Error: Function declaration "x" is obscured by a declaration of the same name when it should not.
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
A clear and concise description of the behavior you are seeing and the expected behavior along with steps to reproduce it.
**Code or Screenshots**
```python
from typing import TypeVar
U = TypeVar("U")
if 1 + 1 == 2:
def x(v: U) -> U:
return v
else:
def x(v: U) -> U:
return v
```
I got Function declaration "x" is obscured by a declaration of the same name. But these two functions are identical IMO. This seems to be related to the TypeVar. If I do not use TypeVar, the error goes away.
Contributor guide
Research direction
Start by running the provided Python snippet through Pyright, then compare it with the version that does not use TypeVar. Investigate the duplicate function-declaration diagnostic and confirm the fix by verifying that identical conditional definitions no longer produce the error while genuinely conflicting declarations still do.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100