This commit is contained in:
Alex Waygood 2025-12-16 16:37:01 -05:00 committed by GitHub
commit 10ae98509a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View File

@ -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 -->

View File

@ -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)
}