pyright sees return type of CSTTransformer.get_metadata() as `CodeRange | type[_UNDEFINED_DEFAULT]`
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 229
- PR merge metrics
- No merged PRs in 30d
Description
I started encountering this when updating https://github.com/python-trio/flake8-trio - but it's been 9 months since last time I ran the type tests so it'd be a pain to figure out when exactly it started happening. If needed I can try to binary search for it though, and/or figure out if it's an update in pyright or libcst that messed it up.
### repro
foo.py:
```python
import libcst
from libcst.metadata import PositionProvider
class Foo(libcst.CSTTransformer):
METADATA_DEPENDENCIES = (PositionProvider,)
def visit_Comment(self, node: libcst.Comment) -> bool:
metadata = self.get_metadata(PositionProvider, node)
reveal_type(metadata)
return False
```
Works in mypy
```
$ mypy foo.py
foo.py:8: note: Revealed type is "libcst._position.CodeRange"
Success: no issues found in 1 source file
```
but pyright gives an additional weird union
```
$ pyright foo.py
/tmp/pyright+libcst/foo.py
/tmp/pyright+libcst/foo.py:8:21 - information: Type of "metadata" is "CodeRange | type[_UNDEFINED_DEFAULT]"
0 errors, 0 warnings, 1 information
```
### versions
* pyright 1.1.350
* mypy 1.8.0
* libcst 1.1.0
* python 3.11.6
* linux
### real-life code
https://github.com/python-trio/flake8-trio/blob/dde4479842315a6a64f2f56d3875931ead9f0af3/flake8_trio/visitors/visitor_utility.py#L183
Contributor guide
Assessment
This issue has not been assessed yet.