Skip to content

Conversation

brandonchinn178
Copy link
Contributor

@brandonchinn178 brandonchinn178 commented May 23, 2025

Fixes #86

The current implementation has a few limitations:

  • Naive parser for requirements.txt
    • Fails with extras, like types-boto3[all]
  • No obvious way to specify types stubs whose name doesn't match (e.g. grpc-stubs <-> grpcio)
  • No obvious way to specify local stubs

This PR makes the following changes:

  1. Remove py_type_library altogether and put the types libraries in PYTHONPATH instead of MYPYPATH
    • AFAICT the only reason for py_type_library is to remove the -stubs suffix because MYPYPATH requires the name to be exact. But mypy already has logic to ignore the -stubs suffix if it's on PYTHONPATH ("installed in the current Python environment"), so we should just use that
  2. Remove types.requirements() in MODULE.bazel with load_stubs() helper in aspects.bzl
    • load_stubs() takes in the all_requirements output from @pip//:requirements.bzl, which contains the requirements that rules_python already parsed
    • load_stubs() makes it clear that requirements is just an automatic detection, but there's also an overrides mechanism for manually specifying the mapping (i.e. requirements is just a shortcut for manually specifying overrides for everything)

@brandonchinn178 brandonchinn178 force-pushed the simplify-deps branch 2 times, most recently from 66a0d3f to f0c0e60 Compare May 23, 2025 19:08
@brandonchinn178 brandonchinn178 marked this pull request as ready for review May 23, 2025 19:14
@brandonchinn178 brandonchinn178 requested a review from a team as a code owner May 23, 2025 19:14
@brandonchinn178 brandonchinn178 force-pushed the simplify-deps branch 3 times, most recently from a06fcee to 11d590d Compare May 23, 2025 22:27
@brandonchinn178 brandonchinn178 mentioned this pull request May 23, 2025
@brandonchinn178
Copy link
Contributor Author

Not sure why CI is failing:
https://github.com/theoremlp/rules_mypy/actions/runs/15222881838/job/43979289207

Inputs 'owner' and 'repositories' are not set. Creating token for this repository (theoremlp/rules_mypy).
Error: [@octokit/auth-app] appId option is required

@brandonchinn178 brandonchinn178 force-pushed the simplify-deps branch 3 times, most recently from 350fdd0 to 7837651 Compare June 16, 2025 19:27
@brandonchinn178
Copy link
Contributor Author

@apalmer-theorem Thoughts on this PR?

@markelliot
Copy link
Collaborator

Sorry for the delay here, aiming to review in the next week or so.


return stubs

def load_stubs(requirements = [], overrides = {}):

Choose a reason for hiding this comment

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

I think it would be helpful if an override value could be a list of stubs. For some reason aiobotocore has several stub packages:

I believe since rules_mypy doesn't understand extras, one would need to be able to specify something like:

    overrides = {
        requirement("aiobotocore"): [
            requirement("types_aiobotocore_dynamodb"),
            requirement("types_aiobotocore_s3"),
            requirement("types_aiobotocore_sqs"),
        ],
    },

@michael-pplx
Copy link

It seems that type packages don't get included transitively.
Given

- a/
  - BUILD
  - __init__.py
- b/
  - BUILD
  - __init__.py 

where

# a/__init__.py
from types_aiobotocore_dynamodb.type_defs import (
    TableAttributeValueTypeDef,
)

# b/__init__.py
from a import TableAttributeValueTypeDef
reveal_type(TableAttributeValueTypeDef)  # Any

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.

How to add stubs
3 participants