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

Typing issue with Annotated #7238

Closed
AlexanderPodorov opened this issue Feb 9, 2024 · 1 comment
Closed

Typing issue with Annotated #7238

AlexanderPodorov opened this issue Feb 9, 2024 · 1 comment
Labels
as designed Not a bug, working as intended bug Something isn't working

Comments

@AlexanderPodorov
Copy link

Describe the bug
See example code snippet

from dataclasses import dataclass
from typing import Annotated


@dataclass
class Test:
    pass


TestAnnonated = Annotated[Test, ...]


def test(a: type[Test]) -> None:
    return None


# Shows warning in Pylance v2024.2.1 (Pyright 1.1.348)
# No warning in Pylance v2023.12.1 (Pyright 1.1.336)
test(TestAnnonated)

# This works:
test(Test)

VS Code extension or command-line
Pylance v2024.2.1 (Pyright 1.1.348)

@AlexanderPodorov AlexanderPodorov added the bug Something isn't working label Feb 9, 2024
@erictraut
Copy link
Collaborator

Pyright's behavior is correct here. The special form Annotated is not compatible with type when used in a value expression. Annotated is intended to be used to be used in a type expression (an annotation), not in a value expression. Pyright previously didn't generate an error here as it should have. Mypy correct does. I've been working to make pyright more conformant with the official typing spec.

You can also read more about this in this typing forum thread.

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