Only try to set flag_value if is_flag is true by lpsinger · Pull Request #2829 · pallets/click

@lpsinger

This statement:

    flag_value = not self.default

requires the class to have a working `__bool__` method. However,
there are some classes that explicitly disable this method:

- [`numpy.ndarray`](https://numpy.org/doc/stable/reference/arrays.ndarray.html)
  raises `ValueError: The truth value of an array with more than
  one element is ambiguous. Use a.any() or a.all()`
- [`astropy.units.Quantity`](https://docs.astropy.org/en/stable/api/astropy.units.Quantity.html)
  raises `ValueError: Quantity truthiness is ambiguous, especially
  for logarithmic units and temperatures. Use explicit  comparisons.`

Move this statement so that it is only executed if `is_flag` is
true.

@lpsinger mentioned this pull request

Dec 22, 2024

@AndreasBackx

@github-actions github-actions bot locked as resolved and limited conversation to collaborators

Jan 6, 2025