Skip to content

Conversation

@Tpt
Copy link
Contributor

@Tpt Tpt commented Jan 19, 2026

Use it for default values and custom signature hints

First step to support Literal type-hints and user-provided hints written using Rust AST

@Tpt Tpt added the CI-skip-changelog Skip checking changelog entry label Jan 19, 2026
Use it for default values and user-provided hints

First step to support Literal type-hints and user-provided hints written using Rust AST
@Tpt Tpt marked this pull request as ready for review January 19, 2026 13:16
@Tpt
Copy link
Contributor Author

Tpt commented Jan 19, 2026

Code coverage is sparse, I plan to improve it as part of the support for the iteration on custom signature annotations


#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct PythonTypeHint(PyExpr);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This name is not great anymore. I am considering a follow up to remove PythonTypeHint and use directly PyExpr

Copy link
Member

Choose a reason for hiding this comment

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

Looks like choice to use constant strings in tests here changed the outputs (I assume this was intended).

Lit::Int(i) => PyConstant::Int(i.base10_digits().into()),
Lit::Float(f) => PyConstant::Float(f.base10_digits().into()),
Lit::Bool(b) => PyConstant::Bool(b.value()),
_ => return None,
Copy link
Member

Choose a reason for hiding this comment

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

Probably can handle CStr here, maybe the byte constants too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. I have added a TODO. I am not sure how useful both are in practice.


#[pymodule_export]
pub const SIMPLE: &str = "SIMPLE";
pub const SIMPLE: &str = "S\0\x01\t\n\r\"'\\";
Copy link
Member

Choose a reason for hiding this comment

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

Not so simple any more 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed; Renamed

Comment on lines +39 to +40
a: "int", *_args: "str", _b: "int | None" = None, **_kwargs: "bool"
) -> "int": ...
Copy link
Member

Choose a reason for hiding this comment

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

Is it expected that these changed? Seems potentially unfortunate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! My motivation is to have a simple translation behavior between user-provided annotation and what is in the stub. For example that strings gets translated to strings. I think it will be useful if we allow to write things like Literal["foo"] in the future. The good news is that it's allowed to write type annotations as strings and type checkers are supposed to properly parse them (doc).

However, I am fine to revert this change if you prefer so.

@Tpt
Copy link
Contributor Author

Tpt commented Jan 20, 2026

I realized I forgot to migrate argument default values. Here is a fix and introduction of ellipsis in the expressions: ddbbe11

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