-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed as not planned
Closed as not planned
Copy link
Labels
T: bugSomething isn't workingSomething isn't working
Description
Describe the bug
When an @overload function is inside a class, the parser bugs out only when using the --line-ranges argument. This bug does not happen when the @overload function is outside of a class however.
To Reproduce
Take this code:
from typing import Union, overload
class Test:
@overload
def test(self, a: str, b: str) -> str: ...
@overload
def test(self, a: str, b: int) -> int: ...
def test(self, a: str, b: Union[str, int]):
print(a)
return bRun with args --line-ranges 12-13:
2025-10-30 12:12:18.172 [info] error: cannot format test.py: Cannot parse for target version Python 3.13: 6:17: @overload def test(self, a: str, b: str) -> str: ...
Oh no! 💥 💔 💥
1 file failed to reformat.
Run with args --line-ranges 6-7:
2025-10-30 12:15:51.626 [info] All done! ✨ 🍰 ✨
1 file left unchanged.
Run with no args:
2025-10-30 12:13:14.575 [info] All done! ✨ 🍰 ✨
1 file left unchanged.
Expected behavior
It should have the same output as running without args.
Environment
- Black's version: 25.9.0
- OS and Python version: Windows 10, Python 3.9.2
Additional context
#4669 might be worth mentioning, since it's a similar variant of this bug.
Metadata
Metadata
Assignees
Labels
T: bugSomething isn't workingSomething isn't working