File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 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:
4242 return ctx .default_return_type
4343 ctx .api .fail ('Never apply isinstance() to unexpanded types;'
4444 ' 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 )
4547 return ctx .default_return_type
4648
4749
Original file line number Diff line number Diff line change @@ -1896,6 +1896,14 @@ def get_proper_type(typ: Type) -> ProperType: ...
18961896
18971897
18981898def 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+ """
18991907 if typ is None :
19001908 return None
19011909 while isinstance (typ , TypeAliasType ):
You can’t perform that action at this time.
0 commit comments