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

Do not emit unreachable warnings for lines that returnNotImplemented.#20083

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
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
4 changes: 3 additions & 1 deletionmypy/checker.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3147,6 +3147,8 @@ def is_noop_for_reachability(self, s: Statement) -> bool:
"""
if isinstance(s, AssertStmt) and is_false_literal(s.expr):
return True
elif isinstance(s, ReturnStmt) and is_literal_not_implemented(s.expr):
return True
elif isinstance(s, (RaiseStmt, PassStmt)):
return True
elif isinstance(s, ExpressionStmt):
Expand DownExpand Up@@ -8281,7 +8283,7 @@ def is_literal_none(n: Expression) -> bool:
return isinstance(n, NameExpr) and n.fullname == "builtins.None"


def is_literal_not_implemented(n: Expression) -> bool:
def is_literal_not_implemented(n: Expression | None) -> bool:
return isinstance(n, NameExpr) and n.fullname == "builtins.NotImplemented"


Expand Down
20 changes: 20 additions & 0 deletionstest-data/unit/check-unreachable-code.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1620,6 +1620,26 @@ reveal_type(bar().attr) # N: Revealed type is "Never"
reveal_type(foo().attr) # N: Revealed type is "Never"
1 # E: Statement is unreachable

[case testIgnoreReturningNotImplemented]
# flags: --warn-unreachable

class C:
def __add__(self, o: C) -> C:
if not isinstance(o, C):
return NotImplemented
return C()
def __sub__(self, o: C) -> C:
if isinstance(o, C):
return C()
return NotImplemented
def __mul__(self, o: C) -> C:
if isinstance(o, C):
return C()
else:
return NotImplemented

[builtins fixtures/isinstance.pyi]

[case testUnreachableStatementPrettyHighlighting]
# flags: --warn-unreachable --pretty
def x() -> None:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp