Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

mypy_stubs issuesΒ #146

@brandonchinn178

Description

@brandonchinn178

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions