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

Regression when loading types for python 3.9 #8018

Closed
last-partizan opened this issue May 29, 2024 · 2 comments
Closed

Regression when loading types for python 3.9 #8018

last-partizan opened this issue May 29, 2024 · 2 comments
Labels
as designed Not a bug, working as intended bug Something isn't working

Comments

@last-partizan
Copy link
Contributor

Describe the bug
After updating to pyright@1.1.364 i encounter following error, but only for python 3.9.

Code or Screenshots

pip install pytest-cases typing-extensions
from typing_extensions import reveal_type
from pytest_cases import fixture

reveal_type(fixture)


@fixture()
def f1_call(): ...


@fixture
def f2_plain(): ...

Note incorrect types for fixture.

pytest-cases are using decopatch.function_decorator, it has types defined in .pyi file, but they're ignored.

> npx pyright@1.1.364 --pythonversion 3.9 pytest-cases.py

/home/serg/src/pyright-examples/pytest-cases.py
  /home/serg/src/pyright-examples/pytest-cases.py:4:13 - information: Type of "fixture" is "(scope: str = "function", autouse: bool = False, name: str = None, unpack_into: Iterable[str] = None, hook: ((...) -> Unknown) -> ((...) -> Unknown) = None, fixture_func: _Symbol | Unknown = DECORATED, **kwargs: Unknown) -> Generator[None, Any, Unknown]"
  /home/serg/src/pyright-examples/pytest-cases.py:7:2 - error: Object of type "Generator[None, Any, Unknown]" is not callable
    Attribute "__call__" is unknown (reportCallIssue)
  /home/serg/src/pyright-examples/pytest-cases.py:11:2 - error: Argument of type "() -> None" cannot be assigned to parameter "scope" of type "str" in function "fixture"
    "function" is incompatible with "str" (reportArgumentType)
2 errors, 0 warnings, 1 information

Larger version of python is not affected and produce correct result:

> npx pyright@1.1.364 --pythonversion 3.10 pytest-cases.py

/home/serg/src/pyright-examples/pytest-cases.py
  /home/serg/src/pyright-examples/pytest-cases.py:4:13 - information: Type of "fixture" is "_Decorator[(scope: str = "function", autouse: bool = False, name: str = None, unpack_into: Iterable[str] = None, hook: ((...) -> Unknown) -> ((...) -> Unknown) = None, fixture_func: _Symbol | Unknown = DECORATED, **kwargs: Unknown)]"
0 errors, 0 warnings, 1 information
@last-partizan last-partizan added the bug Something isn't working label May 29, 2024
@erictraut
Copy link
Collaborator

This is caused by a bug in the decopatch stubs. They're using a try/except block in the import of ParamSpec. Stub files are not executed, and they're not allowed to use dynamic code like try/except blocks.

try:
    from typing import ParamSpec
except ImportError:
    from typing_extensions import ParamSpec

should be replaced by

from typing_extensions import ParamSpec

An older bug in pyright happened to mask the effects of the bug in the stubs, which explains why this apparently worked for you prior to pyright 1.1.364.

The correct fix here is to address the bug in the stubs. I recommend that you file a bug report with the maintainers of the decopatch stubs.

@erictraut erictraut closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2024
@erictraut erictraut added the as designed Not a bug, working as intended label May 29, 2024
@last-partizan
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants