Skip to content

Distinguish redundant-expr warnings from unreachable warnings #9125

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

Merged
merged 7 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use new --enable-error-codes functionlity
  • Loading branch information
llchan committed Aug 12, 2020
commit a70cca803bcfaafc0366b1ed3f1ac3195d829ae6
6 changes: 3 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2747,7 +2747,7 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
# the analysis from the semanal phase below. We assume that nodes
# marked as unreachable during semantic analysis were done so intentionally.
# So, we shouldn't report an error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you understand what this comment refers to? I wonder if the two nearly-identical comment blocks shouldn’t be refactored (the second could just say “similar as above comment”).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what exactly that comment means. When I split the conditions into two, I erred on the side of "explicit is better than implicit" and made sure the comment was copied to both places, so that a future change doesnt inadvertently lead to a dangling comment reference.

if self.chk.options.warn_redundant_expr:
if codes.REDUNDANT_EXPR in self.chk.options.enabled_error_codes:
if left_map is None:
self.msg.redundant_left_operand(e.op, e.left)

Expand Down Expand Up @@ -3682,7 +3682,7 @@ def check_for_comp(self, e: Union[GeneratorExpr, DictionaryComprehension]) -> No
for var, type in true_map.items():
self.chk.binder.put(var, type)

if self.chk.options.warn_redundant_expr:
if codes.REDUNDANT_EXPR in self.chk.options.enabled_error_codes:
if true_map is None:
self.msg.redundant_condition_in_comprehension(False, condition)
elif false_map is None:
Expand All @@ -3695,7 +3695,7 @@ def visit_conditional_expr(self, e: ConditionalExpr, allow_none_return: bool = F
# Gain type information from isinstance if it is there
# but only for the current expression
if_map, else_map = self.chk.find_isinstance_check(e.cond)
if self.chk.options.warn_redundant_expr:
if codes.REDUNDANT_EXPR in self.chk.options.enabled_error_codes:
if if_map is None:
self.msg.redundant_condition_in_if(False, e.cond)
elif else_map is None:
Expand Down
3 changes: 0 additions & 3 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,6 @@ def add_invertible_flag(flag: str,
help="Warn about statements or expressions inferred to be"
" unreachable",
group=lint_group)
add_invertible_flag('--warn-redundant-expr', default=False, strict_flag=False,
help="Warn about expressions inferred to be redundant",
group=lint_group)

# Note: this group is intentionally added here even though we don't add
# --strict to this group near the end.
Expand Down
5 changes: 0 additions & 5 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class BuildType:
"strict_optional_whitelist",
"warn_no_return",
"warn_return_any",
"warn_redundant_expr",
"warn_unreachable",
"warn_unused_ignores",
} # type: Final
Expand Down Expand Up @@ -175,10 +174,6 @@ def __init__(self) -> None:
# type analysis.
self.warn_unreachable = False

# Report an error for any expressions inferred to be redundant as a result of
# type analysis.
self.warn_redundant_expr = False

# Variable names considered True
self.always_true = [] # type: List[str]

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-redundant-expr.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- expressions classified as redundant.

[case testRedundantExpressions]
# flags: --warn-redundant-expr
# flags: --enable-error-code redundant-expr
def foo() -> bool: ...

lst = [1, 2, 3, 4]
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy