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

Decorator type signatures not recognized by pyright #731

Open
charles-dyfis-net opened this issue Dec 28, 2023 · 4 comments
Open

Decorator type signatures not recognized by pyright #731

charles-dyfis-net opened this issue Dec 28, 2023 · 4 comments

Comments

@charles-dyfis-net
Copy link

...and according to pyright upstream, this is a bug in mypy, rather than in pyright.

Type-checking pytest-asyncio itself yields a great many errors, starting with:

pytest-asyncio/pytest_asyncio/plugin.py:57:60 - error: Type variable "_R" has no meaning in this context (reportGeneralTypeIssues)
pytest-asyncio/pytest_asyncio/plugin.py:57:36 - error: TypeVar bound type cannot be generic
pytest-asyncio/pytest_asyncio/plugin.py:60:65 - error: Type variable "_R" has no meaning in this context (reportGeneralTypeIssues)
pytest-asyncio/pytest_asyncio/plugin.py:60:37 - error: TypeVar bound type cannot be generic

...and type-checking a project that uses pytest-asyncio's decorators with reportUntypedFunctionDecorator set in pyright's configuration:

error: Untyped function decorator obscures type of function; ignoring decorator (reportUntypedFunctionDecorator)

I suspect that the option of either passing the function to be used as a fixture as a direct argument to fixture() or returning a function that acts as a proper decorator adds complexity here. If it's not possible to be pyright-friendly with the existing calling convention flexibility, might it make sense to offer a less-flexible, more explicitly-typed alternative?

@seifertm
Copy link
Contributor

seifertm commented Jan 1, 2024

Thanks. Pytest-asyncio is currently type checked with an outdated version of mypy. There's an issue to update the type checker: #596

I assume it would be helpful to also type check with pyright in the CI.

Since pytest-asyncio v0.23 has functional issues that break some users' test suites, the typing issue you describe is not at the top of my priorities list at the moment. I hope you understand!

@seifertm
Copy link
Contributor

seifertm commented Feb 6, 2024

@charles-dyfis-net pytest-asyncio-0.23.5a0 fixed some typing issues and removed the unbound type variable _R in the process. Can you try the pre release and check if it resolves your issue?

@seifertm seifertm added the needsinfo Requires additional information from the issue author label Feb 6, 2024
@charles-dyfis-net
Copy link
Author

charles-dyfis-net commented Feb 6, 2024

We're not running clean, but the specific issue this ticket was filed for is no longer present:

pytest-asyncio/pytest_asyncio/plugin.py
  pytest-asyncio/pytest_asyncio/plugin.py:401:13 - error: Argument of type "Node | None" cannot be assigned to parameter "parent" of type "Node" in function "from_parent"
    Type "Node | None" cannot be assigned to type "Node"
      "None" is incompatible with "Node" (reportGeneralTypeIssues)
  pytest-asyncio/pytest_asyncio/plugin.py:652:30 - error: Cannot access member "__original_collect" for type "Module"
    Member "__original_collect" is unknown (reportGeneralTypeIssues)
pytest-asyncio/tests/test_is_async_test.py
  pytest-asyncio/tests/test_is_async_test.py:77:8 - error: Operator "<" not supported for types "tuple[Literal[7], Literal[4], Literal[0]]" and "tuple[Literal[7], Literal[2]]" (reportGeneralTypeIssues)
  pytest-asyncio/tests/test_is_async_test.py:80:10 - error: Operator "<" not supported for types "tuple[Literal[7], Literal[4], Literal[0]]" and "tuple[Literal[8]]" (reportGeneralTypeIssues)
pytest-asyncio/tests/hypothesis/test_base.py
  pytest-asyncio/tests/hypothesis/test_base.py:8:24 - error: "given" is unknown import symbol (reportGeneralTypeIssues)
  pytest-asyncio/tests/hypothesis/test_base.py:8:31 - error: "strategies" is unknown import symbol (reportGeneralTypeIssues)
6 errors, 0 warnings, 0 informations 

@seifertm seifertm removed the needsinfo Requires additional information from the issue author label Feb 9, 2024
@seifertm
Copy link
Contributor

seifertm commented Feb 9, 2024

Thanks for checking.

Resolving this issue would make for suitable first contribution to pytest-asyncio. I don't necessarily mean you, but anyone who is interested in working on this.

If anyone wants to open a PR, I would expect:

  • A pyright pre-commit hook to be added to .pre-commit-config.yaml. This will run pyright on every commit and prevent this kind of issue in the future
  • the docs and tests folders to be excluded from the pyright type check (see configuration of the mypy pre-commit hook)
  • The two typing errors to be fixed

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