Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyright sees return type of CSTTransformer.get_metadata() as CodeRange | type[_UNDEFINED_DEFAULT] #1107

Open
jakkdl opened this issue Feb 15, 2024 · 0 comments
Labels
enhancement New feature or request machinery Internal plumbing for visitor, transformer, matcher APIs

Comments

@jakkdl
Copy link
Contributor

jakkdl commented Feb 15, 2024

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:

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

@zsol zsol added enhancement New feature or request machinery Internal plumbing for visitor, transformer, matcher APIs labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request machinery Internal plumbing for visitor, transformer, matcher APIs
Projects
None yet
Development

No branches or pull requests

2 participants