mirror of https://github.com/astral-sh/ruff
[ty] Fix panic on invalid syntax where we would incorrectly consider overloads in another file as belonging to a function in the file being checked
This commit is contained in:
parent
f57917becd
commit
074904f90d
|
|
@ -747,3 +747,30 @@ class Sub2(Base):
|
||||||
# error: [invalid-overload]
|
# error: [invalid-overload]
|
||||||
def method(self, x: str) -> str: ...
|
def method(self, x: str) -> str: ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Invalid syntax regression case
|
||||||
|
|
||||||
|
We used to panic on this snippet (see <https://github.com/astral-sh/ty/issues/1867>), because
|
||||||
|
"iterating over the overloads" for `g` would incorrectly list the overloads for `f`:
|
||||||
|
|
||||||
|
<!-- blacken-docs:off -->
|
||||||
|
|
||||||
|
`module.pyi`:
|
||||||
|
|
||||||
|
```pyi
|
||||||
|
from typing import overload
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def f() -> int: ... # error: [invalid-overload]
|
||||||
|
```
|
||||||
|
|
||||||
|
`main.py`:
|
||||||
|
|
||||||
|
```py
|
||||||
|
import module
|
||||||
|
g = module.f
|
||||||
|
@staticmethod
|
||||||
|
def g # error: [invalid-syntax]
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- blacken-docs:on -->
|
||||||
|
|
|
||||||
|
|
@ -386,6 +386,15 @@ impl<'db> OverloadLiteral<'db> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These can both happen in edge cases involving not-yet-complete function definitions
|
||||||
|
// (invalid syntax).
|
||||||
|
if previous_overload.name(db) != self.name(db) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
if previous_overload.body_scope(db).file(db) != self.file(db) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
Some(previous_literal)
|
Some(previous_literal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue