Skip to content

Commit d315403

Browse files
authored
ParamSpec must not raise errors on valid attr access (#13472)
1 parent 08ddf1c commit d315403

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

mypy/semanal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5107,6 +5107,11 @@ def lookup_qualified(
51075107
if isinstance(typ, AnyType):
51085108
# Allow access through Var with Any type without error.
51095109
return self.implicit_symbol(sym, name, parts[i:], typ)
5110+
# This might be something like valid `P.args` or invalid `P.__bound__` access.
5111+
# Important note that `ParamSpecExpr` is also ignored in other places.
5112+
# See https://github.com/python/mypy/pull/13468
5113+
if isinstance(node, ParamSpecExpr) and part in ("args", "kwargs"):
5114+
return None
51105115
# Lookup through invalid node, such as variable or function
51115116
nextsym = None
51125117
if not nextsym or nextsym.module_hidden:

test-data/unit/check-parameter-specification.test

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,3 +1127,38 @@ def func(callback: Callable[P1, str]) -> Callable[P1, str]:
11271127
return "foo"
11281128
return inner
11291129
[builtins fixtures/paramspec.pyi]
1130+
1131+
[case testParamSpecTestPropAccess]
1132+
from typing import Callable
1133+
from typing_extensions import ParamSpec
1134+
1135+
P1 = ParamSpec("P1")
1136+
1137+
def func1(callback: Callable[P1, str]) -> Callable[P1, str]:
1138+
def inner(
1139+
*args: P1.typo, # E: Use "P1.args" for variadic "*" parameter \
1140+
# E: Name "P1.typo" is not defined
1141+
**kwargs: P1.kwargs,
1142+
) -> str:
1143+
return "foo"
1144+
return inner
1145+
1146+
def func2(callback: Callable[P1, str]) -> Callable[P1, str]:
1147+
def inner(
1148+
*args: P1.args,
1149+
**kwargs: P1.__bound__, # E: Use "P1.kwargs" for variadic "**" parameter \
1150+
# E: Name "P1.__bound__" is not defined
1151+
) -> str:
1152+
return "foo"
1153+
return inner
1154+
1155+
def func3(callback: Callable[P1, str]) -> Callable[P1, str]:
1156+
def inner(
1157+
*args: P1.__bound__, # E: Use "P1.args" for variadic "*" parameter \
1158+
# E: Name "P1.__bound__" is not defined
1159+
**kwargs: P1.invalid, # E: Use "P1.kwargs" for variadic "**" parameter \
1160+
# E: Name "P1.invalid" is not defined
1161+
) -> str:
1162+
return "foo"
1163+
return inner
1164+
[builtins fixtures/paramspec.pyi]

0 commit comments

Comments
 (0)