Skip to content

Commit 1521287

Browse files
JukkaLIvan Levkivskyi
authored and
Ivan Levkivskyi
committed
Allow calling a function with name '_' (#11810)
Fixes #11774. The issue has relevant background information in the discussion. It may be worth it to eventually add back some restrictions, but we'd only focus the restrictions on singledispatch functions. This is a quick fix to work around a regression.
1 parent 933c25b commit 1521287

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

mypy/checkexpr.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Expression type checker. This file is conceptually part of TypeChecker."""
22

3-
from mypy.util import unnamed_function
43
from mypy.backports import OrderedDict, nullcontext
54
from contextlib import contextmanager
65
import itertools
@@ -337,12 +336,6 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
337336
and callee_type.implicit):
338337
self.msg.untyped_function_call(callee_type, e)
339338

340-
if (isinstance(callee_type, CallableType)
341-
and not callee_type.is_type_obj()
342-
and unnamed_function(callee_type.name)):
343-
self.msg.underscore_function_call(e)
344-
return AnyType(TypeOfAny.from_error)
345-
346339
# Figure out the full name of the callee for plugin lookup.
347340
object_type = None
348341
member = None

test-data/unit/check-functions.test

+6
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,12 @@ reveal_type(h) # N: Revealed type is "builtins.function"
22302230
h(7) # E: Cannot call function of unknown type
22312231
[builtins fixtures/bool.pyi]
22322232

2233+
[case testFunctionWithNameUnderscore]
2234+
def _(x: int) -> None: pass
2235+
2236+
_(1)
2237+
_('x') # E: Argument 1 to "_" has incompatible type "str"; expected "int"
2238+
22332239
-- Positional-only arguments
22342240
-- -------------------------
22352241

test-data/unit/check-redefine.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ def _(arg: str):
498498
def _(arg: int) -> int:
499499
return 'a' # E: Incompatible return value type (got "str", expected "int")
500500

501-
[case testCallingUnderscoreFunctionIsNotAllowed]
501+
[case testCallingUnderscoreFunctionIsNotAllowed-skip]
502+
# Skipped because of https://github.com/python/mypy/issues/11774
502503
def _(arg: str) -> None:
503504
pass
504505

0 commit comments

Comments
 (0)