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

Metadata to aid static analysis #2537

Open
4 tasks
rickeylev opened this issue Dec 27, 2024 · 1 comment
Open
4 tasks

Metadata to aid static analysis #2537

rickeylev opened this issue Dec 27, 2024 · 1 comment

Comments

@rickeylev
Copy link
Collaborator

Static analysis tools need additional information to help understand Python targets correctly. The use case of particular note are type checkers.

See discussion #2455_

At a minimum, these tools need the original source files. For type checkers, pyi files are also needed. Similarly, things like proto (or other code gen) would also benefit from a way to provide pyi files.

  • Add PyInfo fields: {direct, transitive} x {original_sources, pyi_files}
  • Add py_library.{pyi_{srcs, deps}
  • Update py_library et al to populate, merge, propagate this information
  • Update pypi generation code to set attributes appropriately.
@aignas
Copy link
Collaborator

aignas commented Dec 27, 2024

Just a note for future selves - sometimes whl metadata has extra dependencies for type checking that are not included by default and we could potentially leverage the same heuristics as used in #2425 - i.e. the types packages have special names that are/can be easy to detect.

One question though is what happens if the user hasn't specified the types deps in the hub repo requirements? I am somewhat concerned that this could brake bazel query if the type stubs are not present.

Thinking about this more, I have a feeling that automatically propagating stubs from the external typing stub packages is probably a separate ticket as its scope is too large. Initially (as part of this ticket) we should only handle the pyi files that are present in the whl_library repos.

github-merge-queue bot pushed a commit that referenced this issue Dec 31, 2024
This adds attributes and fields of use to static analysis.

For type definition files (usually `.pyi` files), the `pyi_srcs` and
`pyi_deps`
fields are added to the rules. They end up in the PyInfo fields
direct_pyi_files
and transitive_pyi_files.

So that static analysis tools can retain access to a target's Python
source files,
even if precompiling is enabled, `direct_original_sources` and
`transitive_original_sources` fields are added to PyInfo.

Work towards #2537,
#296
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

2 participants