packaging
packaging copied to clipboard
There is no way to create a SpecifierSet directly from one or more Specifiers
The SpecifierSet
constructor takes a string as input. But if you have a list of Specifier
objects, there's no way to make a SpecifierSet
from them without converting them back to strings and re-parsing.
Could a classmethod be added to build a specifier set from an iterable of Specifier
s? It could be as simple as
@classmethod
def from_specifiers(cls, specs: Iterable[Specifier], prerelease: Optional[bool] = None):
new_value = cls()
new_value._specs = specs
new_value._prereleases = prereleases
return new_value
I'd be happy to create a PR for this if the idea is acceptable.
On reflection, this probably doesn't need a new classmethod - simply allowing construction from an iterator of Specifier
instances should be fine.
I've created https://github.com/pypa/packaging/pull/777 implementing this.
I think this can be closed now that https://github.com/pypa/packaging/pull/777 was merged