Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calling a function with name '_' #11810

Merged
merged 1 commit into from Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions mypy/checkexpr.py
@@ -1,6 +1,5 @@
"""Expression type checker. This file is conceptually part of TypeChecker."""

from mypy.util import unnamed_function
from mypy.backports import OrderedDict, nullcontext
from contextlib import contextmanager
import itertools
Expand Down Expand Up @@ -347,12 +346,6 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
and callee_type.implicit):
self.msg.untyped_function_call(callee_type, e)

if (isinstance(callee_type, CallableType)
and not callee_type.is_type_obj()
and unnamed_function(callee_type.name)):
self.msg.underscore_function_call(e)
return AnyType(TypeOfAny.from_error)

# Figure out the full name of the callee for plugin lookup.
object_type = None
member = None
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-functions.test
Expand Up @@ -2230,6 +2230,12 @@ reveal_type(h) # N: Revealed type is "builtins.function"
h(7) # E: Cannot call function of unknown type
[builtins fixtures/bool.pyi]

[case testFunctionWithNameUnderscore]
def _(x: int) -> None: pass

_(1)
_('x') # E: Argument 1 to "_" has incompatible type "str"; expected "int"

-- Positional-only arguments
-- -------------------------

Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/check-redefine.test
Expand Up @@ -498,7 +498,8 @@ def _(arg: str):
def _(arg: int) -> int:
return 'a' # E: Incompatible return value type (got "str", expected "int")

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

Expand Down