Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quantity class violates collections.abc protocol #2050

Open
jruebsam opened this issue Aug 22, 2024 · 0 comments
Open

Quantity class violates collections.abc protocol #2050

jruebsam opened this issue Aug 22, 2024 · 0 comments

Comments

@jruebsam
Copy link

jruebsam commented Aug 22, 2024

Evaluating the Sized type for a Quantity is not working properly.
Lets say I want to evaluate the length of a Quantity x = 1*u.s, if this is only a single value len(x) will raise an exception.

In this case using something like

from collections.abc import Sized
if isinstance(x, Sized):
    print(len(x))

is a nice way to solve this issue. However this will always evaluate to True even if the Quantity only contains a single Value.
This would require to somehow implement the __len__ method more dynamically or delete it if only a single value is contained.
Im not sure if this is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant