Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Always allow lambda calls#17430

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ilevkivskyi merged 1 commit intopython:masterfromilevkivskyi:allow-lambda
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Always allow lambda calls
  • Loading branch information
@ilevkivskyi
ilevkivskyi committedJun 23, 2024
commit6e092be1c37b3b919c28a7a4ee12be6ec2f61e40
2 changes: 2 additions & 0 deletionsmypy/checkexpr.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@
ARG_STAR,
ARG_STAR2,
IMPLICITLY_ABSTRACT,
LAMBDA_NAME,
LITERAL_TYPE,
REVEAL_LOCALS,
REVEAL_TYPE,
Expand DownExpand Up@@ -599,6 +600,7 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
and self.chk.in_checked_function()
and isinstance(callee_type, CallableType)
and callee_type.implicit
and callee_type.name != LAMBDA_NAME
):
if fullname is None and member is not None:
assert object_type is not None
Expand Down
4 changes: 3 additions & 1 deletionmypy/nodes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,6 +175,8 @@ def get_nongen_builtins(python_version: tuple[int, int]) -> dict[str, str]:
"typing_extensions.runtime_checkable",
)

LAMBDA_NAME: Final = "<lambda>"


class Node(Context):
"""Common base class for all non-type parse tree nodes."""
Expand DownExpand Up@@ -2262,7 +2264,7 @@ class LambdaExpr(FuncItem, Expression):

@property
def name(self) -> str:
return"<lambda>"
returnLAMBDA_NAME

def expr(self) -> Expression:
"""Return the expression (the body) of the lambda."""
Expand Down
2 changes: 1 addition & 1 deletionmypy/plugins/functools.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,7 +25,7 @@

_ORDERING_METHODS: Final = {"__lt__", "__le__", "__gt__", "__ge__"}

PARTIAL = "functools.partial"
PARTIAL: Final = "functools.partial"


class _MethodInfo(NamedTuple):
Expand Down
16 changes: 16 additions & 0 deletionstest-data/unit/check-functions.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3366,3 +3366,19 @@ class C(B):
) -> None:
...
[builtins fixtures/tuple.pyi]

[case testLambdaAlwaysAllowed]
# flags: --disallow-untyped-calls
from typing import Callable, Optional

def func() -> Optional[str]: ...
var: Optional[str]

factory: Callable[[], Optional[str]]
for factory in (
lambda: var,
func,
):
reveal_type(factory) # N: Revealed type is "def () -> Union[builtins.str, None]"
var = factory()
[builtins fixtures/tuple.pyi]

[8]ページ先頭

©2009-2025 Movatter.jp