microsoft / pyright

Static Type Checker for Python
Other
13.12k stars 1.4k forks source link

Fixed bug that results in a false positive error when type argument f… #8700

Closed erictraut closed 1 month ago

erictraut commented 1 month ago

…or Literal doesn't follow type expression rules within a value expression context. This addresses 8696.

github-actions[bot] commented 1 month ago

Diff from mypy_primer, showing the effect of this PR on open source code:

artigraph (https://github.com/artigraph/artigraph)
-   /tmp/mypy_primer/projects/artigraph/tests/arti/types/test_python_adapters.py:91:52 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/artigraph/tests/arti/types/test_python_adapters.py:91:57 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/artigraph/tests/arti/types/test_python_adapters.py:103:59 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/artigraph/tests/arti/types/test_python_adapters.py:105:40 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
- 158 errors, 4 warnings, 0 informations 
+ 154 errors, 4 warnings, 0 informations 

pydantic (https://github.com/pydantic/pydantic)
-   /tmp/mypy_primer/projects/pydantic/pydantic/json_schema.py:69:33 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/pydantic/pydantic/json_schema.py:69:61 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
- 267 errors, 47 warnings, 0 informations 
+ 265 errors, 47 warnings, 0 informations 

pandera (https://github.com/pandera-dev/pandera)
-   /tmp/mypy_primer/projects/pandera/tests/core/test_decorators.py:779:28 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/pandera/tests/core/test_decorators.py:779:28 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
- 2444 errors, 25 warnings, 0 informations 
+ 2442 errors, 25 warnings, 0 informations 

steam.py (https://github.com/Gobot1234/steam.py)
-   /tmp/mypy_primer/projects/steam.py/steam/badge.py:189:54 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/steam.py/steam/badge.py:189:54 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/steam.py/steam/badge.py:197:9 - error: Type of "__init__" is partially unknown
-     Type of "__init__" is "(state: ConnectionState, id: int, level: int, app: PartialApp[str | None] | Unknown, owner: UserT@UserBadge, community_item_id: int | str | None) -> None" (reportUnknownMemberType)
- 8468 errors, 93 warnings, 0 informations 
+ 8465 errors, 93 warnings, 0 informations 

discord.py (https://github.com/Rapptz/discord.py)
-   /tmp/mypy_primer/projects/discord.py/discord/utils.py:1168:34 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/utils.py:1168:34 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:63:13 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:63:31 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:64:13 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:64:31 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:65:13 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:65:31 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:66:13 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:66:31 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:67:13 - error: Type arguments for "Literal" must be None, a literal value (int, bool, str, or bytes), or an enum value (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:67:31 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:95:15 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:116:15 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   /tmp/mypy_primer/projects/discord.py/discord/ext/commands/parameters.py:126:34 - warning: Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)
- 118 errors, 92 warnings, 0 informations 
+ 104 errors, 91 warnings, 0 informations 

beartype (https://github.com/beartype/beartype)
+ /tmp/mypy_primer/projects/beartype/beartype/_conf/_confget.py
+   /tmp/mypy_primer/projects/beartype/beartype/_conf/_confget.py:31:28 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+ /tmp/mypy_primer/projects/beartype/beartype/_conf/confcls.py
+   /tmp/mypy_primer/projects/beartype/beartype/_conf/confcls.py:281:19 - error: Variable not allowed in type expression (reportInvalidTypeForm)
- 0 errors, 1 warning, 0 informations 
+ 2 errors, 1 warning, 0 informations