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

Pyre unexpectedly complains about single-parameter Generator[int] annotation. #967

Open
Iain-S opened this issue Feb 19, 2025 · 1 comment

Comments

@Iain-S
Copy link

Iain-S commented Feb 19, 2025

Pyre Bug

Bug description

According to:

Generator[int] == Generator[int, None] == Generator[int, None, None]

so that you should be able to do:

def infinite_stream(start: int) -> Generator[int]:
    while True:
        yield start
        start += 1

However, depending on whether Generator is imported from collections.abc or typing, one of two different errors is given by pyre --strict check:

  1. Incompatible return type [7]: Expected Generator[Variable[_YieldT_co], Variable[_SendT_contra], Variable[_ReturnT_co]] but got Generator[None, typing.Any, typing.Any].
  2. Invalid type parameters [24]: Generic type Generator expects 3 type parameters, received 1.

Reproduction steps

See the failing and passing actions for the PRs in my minimal reproducible example repo: https://github.com/Iain-S/pyre_mre/pulls.

Expected behavior

I would not expect Pyre-check to complain as the definition for Generator in typing.py seems to be:

Generator = _alias(collections.abc.Generator, 3, defaults=(types.NoneType, types.NoneType))

which is explicit about the defaults.

Logs

pyre_rage.log

Additional context

Tested on CPython 3.13.1.

Since ruff simplifies the expression to have a single parameter when the others are None, pre-commit checks with both Pyre and Ruff conflict, requiring an ugly workaround or disabling UP043.

@dluo
Copy link
Contributor

dluo commented Feb 19, 2025

Thank you for the detailed report! Unfortunately, PEP 696(type parameter defaults) isn't currently supported by Pyre right now. This will likely have to wait until we complete some major architectural changes to our system.

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

2 participants