File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ def isinstance_proper_hook(ctx: FunctionContext) -> Type:
42
42
return ctx .default_return_type
43
43
ctx .api .fail ('Never apply isinstance() to unexpanded types;'
44
44
' use mypy.types.get_proper_type() first' , ctx .context )
45
+ ctx .api .note ('If you pass on the original type' # type: ignore[attr-defined]
46
+ ' after the check, always use its unexpanded version' , ctx .context )
45
47
return ctx .default_return_type
46
48
47
49
Original file line number Diff line number Diff line change @@ -1896,6 +1896,14 @@ def get_proper_type(typ: Type) -> ProperType: ...
1896
1896
1897
1897
1898
1898
def get_proper_type (typ : Optional [Type ]) -> Optional [ProperType ]:
1899
+ """Get the expansion of a type alias type.
1900
+
1901
+ If the type is already a proper type, this is a no-op. Use this function
1902
+ wherever a decision is made on a call like e.g. 'if isinstance(typ, UnionType): ...',
1903
+ because 'typ' in this case may be an alias to union. Note: if after making the decision
1904
+ on the isinstance() call you pass on the original type (and not one of its components)
1905
+ it is recommended to *always* pass on the unexpanded alias.
1906
+ """
1899
1907
if typ is None :
1900
1908
return None
1901
1909
while isinstance (typ , TypeAliasType ):
You can’t perform that action at this time.
0 commit comments