Skip to content

Commit a473e52

Browse files
committed
Save an unnecessary instance check
1 parent 39cd5f9 commit a473e52

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

mypy/checkexpr.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,24 +1664,28 @@ def check_callable_call(
16641664
16651665
See the docstring of check_call for more information.
16661666
"""
1667-
# Check implicit calls to deprecated class constructors.
1668-
# Only the non-overload case is handled here. Overloaded constructors are handled
1669-
# separately during overload resolution. `callable_node` is `None` for an overload
1670-
# item so deprecation checks are not duplicated.
1671-
if isinstance(callable_node, RefExpr) and isinstance(callable_node.node, TypeInfo):
1672-
self.chk.check_deprecated(callable_node.node.get_method("__new__"), context)
1673-
self.chk.check_deprecated(callable_node.node.get_method("__init__"), context)
1674-
16751667
# Always unpack **kwargs before checking a call.
16761668
callee = callee.with_unpacked_kwargs().with_normalized_var_args()
16771669
if callable_name is None and callee.name:
16781670
callable_name = callee.name
16791671
ret_type = get_proper_type(callee.ret_type)
16801672
if callee.is_type_obj() and isinstance(ret_type, Instance):
16811673
callable_name = ret_type.type.fullname
1682-
if isinstance(callable_node, RefExpr) and callable_node.fullname in ENUM_BASES:
1683-
# An Enum() call that failed SemanticAnalyzerPass2.check_enum_call().
1684-
return callee.ret_type, callee
1674+
if isinstance(callable_node, RefExpr):
1675+
# Check implicit calls to deprecated class constructors.
1676+
# Only the non-overload case is handled here. Overloaded constructors are handled
1677+
# separately during overload resolution. `callable_node` is `None` for an overload
1678+
# item so deprecation checks are not duplicated.
1679+
callable_info: TypeInfo | None = None
1680+
if isinstance(callable_node.node, TypeInfo):
1681+
callable_info = callable_node.node
1682+
if callable_info is not None:
1683+
self.chk.check_deprecated(callable_node.node.get_method("__new__"), context)
1684+
self.chk.check_deprecated(callable_node.node.get_method("__init__"), context)
1685+
1686+
if callable_node.fullname in ENUM_BASES:
1687+
# An Enum() call that failed SemanticAnalyzerPass2.check_enum_call().
1688+
return callee.ret_type, callee
16851689

16861690
if (
16871691
callee.is_type_obj()

0 commit comments

Comments
 (0)