Skip to content

Conversation

brandonchinn178
Copy link
Contributor

@brandonchinn178 brandonchinn178 commented May 23, 2025

After #89, the stubs libraries are put in PYTHONPATH, but other external deps are still in MYPYPATH. Now, we can just put everything into PYTHONPATH, and remove the logic to skip adding external deps if the stub library is added, since mypy already has the logic to load types-foo over foo.

Also includes refactoring the MYPYPATH logic to be simpler + more readable. There are probably edge cases that are dropped in the refactoring, but I think we can find regressions + add test cases as we go

@brandonchinn178 brandonchinn178 force-pushed the simplify-env branch 4 times, most recently from 30bd553 to d0113b6 Compare May 24, 2025 03:01
@brandonchinn178 brandonchinn178 force-pushed the simplify-env branch 7 times, most recently from 44b9174 to 32e6877 Compare August 6, 2025 20:00
Comment on lines +52 to +70
DEP_TYPE_NORMAL = "normal"
DEP_TYPE_OVERRIDDEN = "overridden" # a dep that has a stub library overriding it
DEP_TYPE_STUB = "stub"

def _get_deps(ctx):
all_deps = []
stub_mapping = {
base_dep.label: stub_dep
for base_dep, stub_dep in zip(ctx.attr._stubs_keys, ctx.attr._stubs_values)
}

for dep in ctx.rule.attr.deps:
if dep.label in stub_mapping:
all_deps.append((dep, DEP_TYPE_OVERRIDDEN))
all_deps.append((stub_mapping[dep.label], DEP_TYPE_STUB))
else:
all_deps.append((dep, DEP_TYPE_NORMAL))

return all_deps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: This should be able to go away. Just put all deps into PYTHONPATH and let mypy look for the stub library over the real library

@brandonchinn178 brandonchinn178 mentioned this pull request Aug 13, 2025
3 tasks
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

Successfully merging this pull request may close these issues.

2 participants