mirror of https://github.com/astral-sh/ruff
Merge 074904f90d into b0bc990cbf
This commit is contained in:
commit
10ae98509a
|
|
@ -805,3 +805,30 @@ class Sub2(Base):
|
|||
# error: [invalid-overload]
|
||||
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;
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue