mirror of https://github.com/astral-sh/ruff
[ty] Avoid duplicate diagnostics during multi-inference of standalone expressions (#21056)
## Summary Resolves https://github.com/astral-sh/ty/issues/1428.
This commit is contained in:
parent
adbf05802a
commit
f17ddd62ad
|
|
@ -284,6 +284,8 @@ def _(flag: bool):
|
||||||
|
|
||||||
Diagnostics unrelated to the type-context are only reported once:
|
Diagnostics unrelated to the type-context are only reported once:
|
||||||
|
|
||||||
|
`expression.py`:
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def f[T](x: T) -> list[T]:
|
def f[T](x: T) -> list[T]:
|
||||||
return [x]
|
return [x]
|
||||||
|
|
@ -307,3 +309,18 @@ def _(x: int):
|
||||||
# error: [possibly-unresolved-reference] "Name `z` used when possibly not defined"
|
# error: [possibly-unresolved-reference] "Name `z` used when possibly not defined"
|
||||||
y(f(True), [z])
|
y(f(True), [z])
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`standalone_expression.py`:
|
||||||
|
|
||||||
|
```py
|
||||||
|
def f(_: str): ...
|
||||||
|
def g(_: str): ...
|
||||||
|
def _(a: object, b: object, flag: bool):
|
||||||
|
if flag:
|
||||||
|
x = f
|
||||||
|
else:
|
||||||
|
x = g
|
||||||
|
|
||||||
|
# error: [unsupported-operator] "Operator `>` is not supported for types `object` and `object`"
|
||||||
|
x(f"{'a' if a > b else 'b'}")
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,9 @@ impl<'db, 'ast> InferContext<'db, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn extend(&mut self, other: &TypeCheckDiagnostics) {
|
pub(crate) fn extend(&mut self, other: &TypeCheckDiagnostics) {
|
||||||
self.diagnostics.get_mut().extend(other);
|
if !self.is_in_multi_inference() {
|
||||||
|
self.diagnostics.get_mut().extend(other);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn is_lint_enabled(&self, lint: &'static LintMetadata) -> bool {
|
pub(super) fn is_lint_enabled(&self, lint: &'static LintMetadata) -> bool {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue