Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
replace the critical in comparisons for testing
  • Loading branch information
tyralla committed Mar 19, 2024
commit 207c56eb3cd7732fbaa82e2f7e10736bf127a608
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3575,7 +3575,7 @@ def visit_comparison_expr(self, e: ComparisonExpr) -> Type:

# Only show dangerous overlap if there are no other errors. See
# testCustomEqCheckStrictEquality for an example.
if not w.has_new_errors() and operator in ("==", "!="):
if not w.has_new_errors() and (operator == "==" or operator == "!="):
right_type = self.accept(right)
if self.dangerous_comparison(left_type, right_type):
# Show the most specific literal types possible
Expand Down
2 changes: 1 addition & 1 deletion mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def find_sources_in_dir(self, path: str) -> list[BuildSource]:
names = sorted(self.fscache.listdir(path), key=keyfunc)
for name in names:
# Skip certain names altogether
if name in ("__pycache__", "site-packages", "node_modules") or name.startswith("."):
if (name == "__pycache__" or name == "site-packages" or name == "node_modules") or name.startswith("."):
continue
subpath = os.path.join(path, name)

Expand Down
4 changes: 2 additions & 2 deletions mypy/reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def infer_condition_value(expr: Expression, options: Options) -> int:
name = expr.name
elif isinstance(expr, OpExpr) and expr.op in ("and", "or"):
left = infer_condition_value(expr.left, options)
if (left in (ALWAYS_TRUE, MYPY_TRUE) and expr.op == "and") or (
left in (ALWAYS_FALSE, MYPY_FALSE) and expr.op == "or"
if ((left == ALWAYS_TRUE or left == MYPY_TRUE) and expr.op == "and") or (
(left == ALWAYS_FALSE or left == MYPY_FALSE) and expr.op == "or"
):
# Either `True and <other>` or `False or <other>`: the result will
# always be the right-hand-side.
Expand Down
8 changes: 4 additions & 4 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5301,13 +5301,13 @@ def visit_op_expr(self, expr: OpExpr) -> None:

if expr.op in ("and", "or"):
inferred = infer_condition_value(expr.left, self.options)
if (inferred in (ALWAYS_FALSE, MYPY_FALSE) and expr.op == "and") or (
inferred in (ALWAYS_TRUE, MYPY_TRUE) and expr.op == "or"
if ((inferred == ALWAYS_FALSE or inferred == MYPY_FALSE) and expr.op == "and") or (
(inferred == ALWAYS_TRUE or inferred == MYPY_TRUE) and expr.op == "or"
):
expr.right_unreachable = True
return
elif (inferred in (ALWAYS_TRUE, MYPY_TRUE) and expr.op == "and") or (
inferred in (ALWAYS_FALSE, MYPY_FALSE) and expr.op == "or"
elif ((inferred == ALWAYS_TRUE or inferred == MYPY_TRUE) and expr.op == "and") or (
(inferred == ALWAYS_FALSE or inferred == MYPY_FALSE) and expr.op == "or"
):
expr.right_always = True

Expand Down