Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 749: Add a FAKE_GLOBALS_VALUE format #3991

Merged
merged 4 commits into from
Sep 25, 2024

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Sep 24, 2024

This is a first round of changes as a result of feedback by @larryhastings; I may make some more changes, but need to think about them more first.


📚 Documentation preview 📚: https://pep-previews--3991.org.readthedocs.build/

And some other changes from feedback by Larry.
peps/pep-0749.rst Outdated Show resolved Hide resolved
Co-authored-by: Carl Meyer <[email protected]>
@@ -27,7 +27,9 @@ specification:
* We specify the behavior of wrapper objects that provide annotations, such as :py:func:`classmethod`
and code that uses :py:func:`functools.wraps`.
* There will not be a code flag for marking ``__annotate__`` functions
that can be run in a "fake globals" environment.
that can be run in a "fake globals" environment. Instead, we add a fourth format,
``FAKE_GLOBALS_VALUE``, to allow third-party implementors of annotate functions to
Copy link
Contributor

Choose a reason for hiding this comment

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

It took me a bit to work out that this name was a combination of describing the output format and a difference in the supported inputs.

How would you feel about a more explicit separation of the two aspects, calling this format VALUE_WITH_FAKE_GLOBALS?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that, I'll ask Larry tomorrow to see if he agrees.

Copy link
Contributor

Choose a reason for hiding this comment

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

After reviewing how the fake globals format is used, FORWARDREF_VIA_GLOBALS is likely clearer, since this format injects fake globals to produce a FORWARDREF result that can be postprocessed to give a SOURCE result.

It doesn't emit the VALUE format, so having that in the name would be misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel it makes more sense to think of the format as "VALUE with an asterisk", since that's how __annotate__ functions should handle it internally.

this format injects fake globals to produce a FORWARDREF result that can be postprocessed to give a SOURCE result

That's not really how the implementation works. There isn't a forwardref involved in producing {"x": "int"} out of the annotations for def f(x: int): pass in SOURCE format.

@JelleZijlstra JelleZijlstra merged commit 9c9c5c3 into python:main Sep 25, 2024
6 checks passed
@JelleZijlstra JelleZijlstra deleted the pep749-larry branch September 25, 2024 23:46
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.

4 participants