Skip to content

Commit

Permalink
Revert "Added exemption to the reportUnnecessaryComparison rule for…
Browse files Browse the repository at this point in the history
… simple wildcard patterns in a `case` clause. This addresses #4706. (#9582)"

our exemption logic is better because it still reports the error if the wildcard case is not used to assert that it's unreachable

This reverts commit 9041f88
  • Loading branch information
DetachHead committed Dec 18, 2024
1 parent cd109bd commit b12c1c4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 21 deletions.
10 changes: 0 additions & 10 deletions packages/pyright-internal/src/analyzer/patternMatching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2225,16 +2225,6 @@ export function getPatternSubtypeNarrowingCallback(
}

function reportUnnecessaryPattern(evaluator: TypeEvaluator, pattern: PatternAtomNode, subjectType: Type): void {
// If this is a simple wildcard pattern, exempt it from this diagnostic.
if (
pattern.nodeType === ParseNodeType.PatternAs &&
pattern.d.orPatterns.length === 1 &&
pattern.d.orPatterns[0].nodeType === ParseNodeType.PatternCapture &&
pattern.d.orPatterns[0].d.isWildcard
) {
return;
}

evaluator.addDiagnostic(
DiagnosticRule.reportUnnecessaryComparison,
LocMessage.patternNeverMatches().format({ type: evaluator.printType(subjectType) }),
Expand Down
11 changes: 0 additions & 11 deletions packages/pyright-internal/src/tests/samples/matchUnnecessary1.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,3 @@ def func4(vals: list[str]) -> TA1:
case _:
pass
return x


def func5(subj: int | str):
match subj:
case int() | str():
pass

# This should not generate a diagnostic becuase _ is exempted
# from the reportUnnecessaryComparison check.
case _:
pass

0 comments on commit b12c1c4

Please sign in to comment.