PyO3 / PyO3/pyo3

Assign an alias to a type hint

Open
#6,347 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

Type hints such as defined by type_hint_identifier are automatically assigned to imports by PyO3, an extremely convenient feature. Unfortunately, there are rare cases where the type identifier can have the same name from multiple packages.

https://github.com/bufbuild/protovalidate-py/blob/871ad5faebc319b7b6c97259c0cb3f49da57f2c6/protovalidate/_protovalidate.pyi#L19
https://github.com/bufbuild/protovalidate-py/blob/871ad5faebc319b7b6c97259c0cb3f49da57f2c6/src/hints.rs#L37

I understand this is relatively niche but it would be great if we could add an alias to type_hint_identifier that is used in type annotations and added with as to the import.

Conflict handling reference:

https://github.com/PyO3/pyo3/blob/8426c514e5004e5d345cca3c6ed21a72f1ba1da6/pyo3-introspection/src/stubs.rs#L402

There is a TODO to consider something like ModFoo. This may provide ProtobufMessage | Message for us which still wouldn't be much better than the number, so if going with a non-controlled approach without an explicit alias, it would be great if all members of a collision get transformed rather than one, in this case ProtobufMessage | GoogleProtobufMessage is reasonably clear.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/hints.rs and compare its type_hint_identifier handling with the conflict logic in pyo3-introspection/src/stubs.rs, including the referenced TODO. Trace how identifiers become imports and annotations. Done means an explicit alias can control both generated annotation names and imports, with a defined behavior for collisions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
developer-experience, devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.