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

How to determine if a specifier set is empty? (Possible feature request) #760

Closed
notatallshaw opened this issue Jan 2, 2024 · 2 comments

Comments

@notatallshaw
Copy link
Member

notatallshaw commented Jan 2, 2024

This is a feature request / support question I guess.

I am writing a big resolution optimization for Pip that requires understanding if a specifier set is empty, am I correect in assuming the only way to do that at the moment is: str(SpecifierSet()) == ""?

And then if so, my feature request would be to support a __bool__ that is True when the SpecifierSet is not empty and is False when the SpecifierSet is empty. This would save on the sorted call that __str__ makes. Would you be willing to take a PR on this?

@pradyunsg
Copy link
Member

pradyunsg commented Jan 3, 2024

You can do this with len(s) == 0 and it should be relatively cheap. I'm wary of defining __bool__ since it's possible that folks depend on the value being truthy.

def __len__(self) -> int:

@notatallshaw
Copy link
Member Author

Ah, perfect thanks!

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

No branches or pull requests

2 participants