Skip to content

Commit 768ce5b

Browse files
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 b31b06b commit 768ce5b

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
@@ -347,12 +346,6 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
347346
and callee_type.implicit):
348347
self.msg.untyped_function_call(callee_type, e)
349348

350-
if (isinstance(callee_type, CallableType)
351-
and not callee_type.is_type_obj()
352-
and unnamed_function(callee_type.name)):
353-
self.msg.underscore_function_call(e)
354-
return AnyType(TypeOfAny.from_error)
355-
356349
# Figure out the full name of the callee for plugin lookup.
357350
object_type = None
358351
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)