Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

gh-141388: Fully support non-function callables as annotate functions#141449

Closed
dr-carlos wants to merge 33 commits intopython:mainfrom
dr-carlos:non-function-annotate
Closed

gh-141388: Fully support non-function callables as annotate functions#141449
dr-carlos wants to merge 33 commits intopython:mainfrom
dr-carlos:non-function-annotate

Conversation

@dr-carlos
Copy link
Contributor

@dr-carlos dr-carlos commented Nov 12, 2025

  • Any callable can be used as an __annotate__ function in 3.14, but annotationlib will start throwing errors if the format is not implemented.
  • This is an initial implementation to support them as first-class citizens included here, mostly in call_annotate_function()
  • Currently this implementation supports: methods, class/static methods, class instances that are callable, classes and generics themselves, partial, wrapped, singledispatch, and cached functions. 'Builtin' (C) callables can't really be supported because they have no __code__, __globals__, etc., so a ForwardRef or stringification using the current techniques is impossible. Let me know if there are any more callables to implement, some more special-casing will probably be required.
  • Initial tests are present but not thorough. It should work for all parts of annotationlib, but tests are mostly present on call_annotate_function() for now.
  • Opening a PR now to seek feedback on the implementation and decide on whether the extra complexity is worth it. If there is interest, I'll add more thorough tests, etc.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants