Skip to content

Conversation

@Tpt
Copy link
Contributor

@Tpt Tpt commented Nov 24, 2025

Allows to build static type hint or manipulate the ones from PyO3 traits

Makes type hint manipulation code much nicer

Allows to build static type hint or manipulate the ones from PyO3 traits

Makes type hint manipulation code much nicer
@Tpt Tpt added the CI-skip-changelog Skip checking changelog entry label Nov 24, 2025
@Tpt
Copy link
Contributor Author

Tpt commented Nov 24, 2025

Aside: I am not sure the PythonTypeHint struct name is great because it covers more usages than type hints like decorators. A big renaming to something like PythonExpression affecting also the TypeHint type in pyo3::inspect and po3_introspection might make sense.

@Tpt Tpt marked this pull request as ready for review November 24, 2025 15:04
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks! Indeed makes code much easier to read.

Aside: I am not sure the PythonTypeHint struct name is great because it covers more usages than type hints like decorators. A big renaming to something like PythonExpression affecting also the TypeHint type in pyo3::inspect and po3_introspection might make sense.

I am tempted by this, I was thinking similarly. Only drawback is that there are some enum variants such as "union" which seem more specifically type hint related. (In a full "expression" I think the union would be some kind of ast of | operators?)

@Tpt
Copy link
Contributor Author

Tpt commented Nov 28, 2025

Only drawback is that there are some enum variants such as "union" which seem more specifically type hint related. (In a full "expression" I think the union would be some kind of ast of | operators?)

Indeed. If we do such change we would imho change the variant to be more focus on Python syntax (and maybe align with the python ast module). My feeling is that we care here more about the Python syntax and not the really the semantic (the main use case of the AST being to rewrite imports) so having a unified syntax-focused representation might make sense.

If you agree, I can do an MR draft going into this direction to see how it feels (having this MR merged before would help because it means less places to update).

@davidhewitt davidhewitt added this pull request to the merge queue Nov 28, 2025
@davidhewitt
Copy link
Member

Sounds good to me 👍

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 28, 2025
@davidhewitt davidhewitt added this pull request to the merge queue Nov 28, 2025
Merged via the queue into PyO3:main with commit 26ce948 Nov 29, 2025
41 of 43 checks passed
@Tpt Tpt deleted the tpt/type-hint-macro branch December 1, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants