#6347·pyo3

Assign an alias to a type hint

Author: anuraagaCreated Aug 24, 2026Updated Aug 24, 2026

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.