Comment 2 for bug 1706413

Revision history for this message
Nish Aravamudan (nacc) wrote : Re: [Bug 1706413] Re: lint: result gathering pattern smells

Thanks for this suggestion, I'd not seen that pattern before, and I like
the idea of two internal objects with truthiness and print-ability.

On Jul 25, 2017 11:12, "Robie Basak" <email address hidden> wrote:

> I think that if we treat each checking function as returning a sequence
> of booleans, telling us whether each check was successful or not, then
> yielding works. You can interpret the results of any check function
> using all(), any() or examining the individual booleans. A check
> function can use "yield from" to incorporate other check functions, and
> each check function can adjust its control flow according to previous
> checks (for example if a check isn't possible because a previous check
> failed).
>
> I prefer this because I think that using "ret" on every line is
> particularly error-prone. It's repetitive code, which I think is the
> code smell here.
>
> I admit that perhaps it's not great for the returned booleans not to be
> aligned with anything. We could further enhance the results by making
> them class instances that define __bool__ instead, but also carry more
> information about what failed. This would work quite nicely to separate
> stdout from the running of the checks for better testability. yield and
> all() would still work. We'd do something like:
>
> yield LintError("X is not Y")
>
> or:
>
> yield LintSuccess("A is correct")
>
> LintSuccess.__bool__() would always return True, and
> LintError.__bool__() would always return False.
>
> --
> You received this bug notification because you are a member of Ubuntu
> Server Dev import team, which is subscribed to usd-importer.
> https://bugs.launchpad.net/bugs/1706413
>
> Title:
> lint: result gathering pattern smells
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/usd-importer/+bug/1706413/+subscriptions
>