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

types: pass through filter list type #430

Merged
merged 1 commit into from
May 28, 2021

Conversation

henryiii
Copy link
Contributor

@henryiii henryiii commented May 19, 2021

This passes through the type of an iterable in filter. filter never broadens or changes the types of the input list.

Example:

x: typing.List[Version]
reveal_type(SpecifierSet("*").filter(x))

Before:

Revealed type is 'typing.Iterable[Union[packaging.version.Version, packaging.version.LegacyVersion, builtins.str]]'

After:

Revealed type is 'typing.Iterable[packaging.version.Version*]'

This passes through the type of a list in filter.

Example:

    x: typing.List[Version]
    reveal_type(SpecifierSet("*").filter(x))

Before:

    Revealed type is 'typing.Iterable[Union[packaging.version.Version, packaging.version.LegacyVersion, builtins.str]]'

After:

    Revealed type is 'typing.Iterable[packaging.version.Version*]'

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii
Copy link
Contributor Author

This is the current workaround:

unsorted_versions = cast(Iterable[Version], spec.filter(versions))

which is really ugly, since versions is known to be an iterable of Version's only.

@brettcannon brettcannon merged commit 7350746 into pypa:main May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants