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

mypy_stubs issues #146

Open
brandonchinn178 opened this issue Feb 20, 2025 · 0 comments
Open

mypy_stubs issues #146

brandonchinn178 opened this issue Feb 20, 2025 · 0 comments

Comments

@brandonchinn178
Copy link

I'm encountering a few issues with mypy_stubs:

  1. Stubs included transitively aren't being included:

    mypy_stubs(name = "kafka_stub", srcs = ["kafka.pyi"])
    
    py_library(name = "dep", srcs = ["dep.py"], deps = [":kafka_stub"])
    
    py_binary(name = "main", srcs = ["main.py"], deps = [":dep"])

    With this setup, building main fails because dep.py is included in the mypy invocation, but kafka.pyi isn't transitively included in stub_files, which means kafka.pyi isn't making it into mypypath

  2. A tree of stub files isn't included in the mypy path correctly. Currently, the integration only adds the mypy_stubs' files' immediate directory into MYPYPATH, but that won't resolve nested structures like a/__init__.py and a/b/__init__.py

    • I also suspect that having a/__init__.py and b/__init__.py would also error currently

Current workaround

I'm currently adding a patch file doing the equivalent of the following:

# transitively include stubs
for deps in transitive_srcs_depsets:
    for f in deps.to_list():
        if f.extension == "pyi":
            stub_files.append(f)

# only add stub root
mypypath_parts += [src_f.dirname for src_f in stub_files if src_f.basename == "__stubs_root__.pyi"]

and then adding __stubs_root__.pyi to every mypy_stubs target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant