diff --git a/mypy/typeanal.py b/mypy/typeanal.py index db5625619262..20210bb43875 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -1929,14 +1929,15 @@ def anal_type( self.allow_unpack = old_allow_unpack if ( not allow_param_spec - and isinstance(analyzed, ParamSpecType) - and analyzed.flavor == ParamSpecFlavor.BARE + and isinstance(analyzed, (ParamSpecType, Parameters)) + and (isinstance(analyzed, Parameters) or analyzed.flavor == ParamSpecFlavor.BARE) ): - if analyzed.prefix.arg_types: + is_concatenate = isinstance(analyzed, Parameters) or analyzed.prefix.arg_types + if is_concatenate: self.fail("Invalid location for Concatenate", t, code=codes.VALID_TYPE) self.note("You can use Concatenate as the first argument to Callable", t) - analyzed = AnyType(TypeOfAny.from_error) else: + assert isinstance(analyzed, ParamSpecType) self.fail( INVALID_PARAM_SPEC_LOCATION.format(format_type(analyzed, self.options)), t, @@ -1947,7 +1948,7 @@ def anal_type( t, code=codes.VALID_TYPE, ) - analyzed = AnyType(TypeOfAny.from_error) + analyzed = AnyType(TypeOfAny.from_error) return analyzed def anal_var_def(self, var_def: TypeVarLikeType) -> TypeVarLikeType: diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 970ba45d0e8e..194795ebe9dc 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -1147,6 +1147,7 @@ from typing import Callable P = ParamSpec("P") def x(f: Callable[Concatenate[int, Concatenate[int, P]], None]) -> None: ... # E: Nested Concatenates are invalid +def y(f: Callable[Concatenate[Concatenate[...], ...], None]) -> None: ... # E: Invalid location for Concatenate # N: You can use Concatenate as the first argument to Callable [builtins fixtures/paramspec.pyi] [case testPropagatedAnyConstraintsAreOK] diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index bfbd2e631f5d..7c5c109ffea2 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -1831,10 +1831,3 @@ class tuple_aa_subclass(Tuple[A, A]): ... inst_tuple_aa_subclass: tuple_aa_subclass = tuple_aa_subclass((A(), A()))[:] # E: Incompatible types in assignment (expression has type "tuple[A, A]", variable has type "tuple_aa_subclass") [builtins fixtures/tuple.pyi] - -[case testTuplePassedParameters] -from typing_extensions import Concatenate - -def c(t: tuple[Concatenate[int, ...]]) -> None: # E: Cannot use "[int, VarArg(Any), KwArg(Any)]" for tuple, only for ParamSpec - reveal_type(t) # N: Revealed type is "tuple[Any]" -[builtins fixtures/tuple.pyi]