Skip to content

Conversation

@dr-carlos
Copy link
Contributor

@dr-carlos dr-carlos commented Dec 5, 2025

  • Clarified in the glossary that an annotate function can be any callable (as is already the case).
  • Improved error messages if call_annotate_function() tries to run with fake globals but can't find the annotate function's __code__ attribute.
  • Added defaults if other non-required attributes cannot be found for fake globals, e.g. if the annotate function doesn't provide __defaults__, that's fine, just assume it's None.
    If required, I can remove some (or all) of these defaults, particularly __globals__ which adds an extra parameter to _build_closure(), or __builtins__ which is semantically correct but a little more complicated than the rest (it would be much simpler to just fallback to builtins.__dict__).
  • Added tests for the current support, added support, and error messages associated with non-function callables as annotate functions..
  • Added a section to the annotationlib documentation providing a simple recipe for a 'minimum viable implementation' of a custom callable class as annotate function. Happy to remove if this is unnecessary/too niche - I just thought it was the clearest way of demonstrating how to implement one of these, without just spelling out which dunders they need to implement.

📚 Documentation preview 📚: https://cpython-previews--142327.org.readthedocs.build/

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I am not quite convinced that this should be done. __annotate__ is already complex enough.

In the issue itself there were no real use-cases that can support the idea.

In my opinion, it is fine to have __annotate__ magic function as function only.

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.

2 participants