Skip to content

Commit 0a9e750

Browse files
committed
added boolean condition warnings: overlap, redundancy, == True
three ty lints on truthiness tests: - `overlapping-condition` — the branch a condition selects is reached by more than one kind of member, so it cannot tell them apart. only the selected branch is analysed (`if a` truthy, `if not a` falsy), and members of one class (or two where one derives the other) count as one kind - `redundant-condition` — the tested value's own type fixes the outcome. restricted to a value read: ty folding a comparison or call is the statically-known-branch machinery doing its job - `redundant-boolean-comparison` — `a == True` where `a` is a `bool` `ConditionTruthiness` adds a fourth state to `Truthiness`: artificial, for a constant the checker's model of the build produced rather than the program's types — `TYPE_CHECKING`, `sys.version_info`, `sys.platform`, `os.name`. a redundant-condition report on one of those would be wrong two options tune the overlap check: `analysis.overlapping-condition-exempt-types` drops members of the named classes, and `analysis.overlapping-condition-assume-truthy-instances` takes a class with no `__bool__`/`__len__` at face value
1 parent e357026 commit 0a9e750

41 files changed

Lines changed: 2233 additions & 165 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/ruff_db/src/diagnostic/mod.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,27 @@ pub enum DiagnosticId {
10091009
/// A glob pattern doesn't follow the expected syntax.
10101010
InvalidGlob,
10111011

1012+
/// A class name in the configuration isn't spelled like one.
1013+
///
1014+
/// ## Why is this bad?
1015+
/// An option that takes class names matches them literally, so a malformed entry silently
1016+
/// matches nothing. Whether a well-formed name resolves to a class that exists is not checked
1017+
/// — only that it *could* be one.
1018+
///
1019+
/// ## Example
1020+
/// ```toml
1021+
/// [analysis]
1022+
/// overlapping-condition-exempt-types = ["list[int]"]
1023+
/// ```
1024+
///
1025+
/// Use instead:
1026+
///
1027+
/// ```toml
1028+
/// [analysis]
1029+
/// overlapping-condition-exempt-types = ["list"]
1030+
/// ```
1031+
InvalidClassName,
1032+
10121033
/// An `include` glob without any patterns.
10131034
///
10141035
/// ## Why is this bad?
@@ -1137,6 +1158,7 @@ impl DiagnosticId {
11371158
DiagnosticId::RevealedType => "revealed-type",
11381159
DiagnosticId::UnknownRule => "unknown-rule",
11391160
DiagnosticId::InvalidGlob => "invalid-glob",
1161+
DiagnosticId::InvalidClassName => "invalid-class-name",
11401162
DiagnosticId::EmptyInclude => "empty-include",
11411163
DiagnosticId::UnnecessaryOverridesSection => "unnecessary-overrides-section",
11421164
DiagnosticId::UselessOverridesSection => "useless-overrides-section",

‎crates/ty/docs/configuration.md‎

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)