Skip to content

Conversation

@jfeser
Copy link
Contributor

@jfeser jfeser commented Dec 19, 2025

A first attempt to address #450. Handles the basic case, but forward references have some caveats. typing.get_type_hints doesn't actually seem to use the lexical scope of the definition to resolve the hints. Instead, it looks for the module containing the definition. This means that forward references don't work when (for example) an operation is defined inside a function.

@jfeser
Copy link
Contributor Author

jfeser commented Dec 19, 2025

Separately, I think making __signature__ derive from __default__ makes the Operation interface somewhat simpler.

@jfeser jfeser requested a review from eb8680 December 19, 2025 17:43
@eb8680
Copy link
Contributor

eb8680 commented Dec 19, 2025

IIUC we're going to end up reimplementing a lot of the new Python 3.14 standard library module annotationlib this way. In particular annotationlib includes new and improved versions of inspect.get_annotations() and typing.ForwardRef and a new typing function typing.evaluate_forward_ref, all of which are also backported to 3.12/13 within typing_extensions.

From the annotationlib documentation it seems to be the case that using evaluate_forward_ref on the output of get_annotations will evaluate hints containing ForwardRefs in the correct scopes, and that this is now recommended as the primary method for evaluating and introspecting annotations with forward references.

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

Successfully merging this pull request may close these issues.

3 participants