Now with improved legibility: PEP-0484 specifies that Any, classes, unions of classes, and type variables can be parameters of types, and "Any other special constructs like Tuple or Callable are not allowed as an argument to Type." I found the origin of this text: https://github.com/python/typing/pull/218#discussion-diff-63608361 It looks like the intent of this was to prohibit non-class values, but the improved wording was overly strict. mypy uses Type[Type[]] in its internal representation and error messages already: ``` list_str: List[str] = ["a", "b", "c"] type_list_str: Type[List[str]] = type(list_str) type_type_list_str = type(type_list_str) reveal_type(type_type_list_str) # note: Revealed type is 'Type[Type[builtins.list[builtins.str]]]' ``` and will typecheck such an annotation as expected: ``` list_str: List[str] = ["a", "b", "c"] type_list_str: Type[List[str]] = type(list_str) # error: Incompatible types in assignment (expression has type "Type[Type[List[str]]]", variable has type "Type[Type[List[int]]]") type_type_list_int: Type[Type[List[int]]] = type(type_list_str) ```
participants (1)
-
Buck Evan