-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
PEP xxx: Inner Fields Annotations #3326
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
Conversation
@@ -0,0 +1,322 @@ | |||
PEP: 728 | |||
Title: Inner Fields Annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you be a bit more specific with this title? Before reading the PEP I had no idea what "Inner Fields Annotations" meant.
PEP: 728 | ||
Title: Inner Fields Annotations | ||
Author: Nir Schulman <[email protected]> | ||
Sponsor: Jelle Zijlstra <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @JelleZijlstra for confirmation of sponsorship
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but I am not sponsoring this PEP at the moment. I already have four open PEPs (696, 702, 724, 727), that feels like too much. I can think about sponsoring more when a few of the others are done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. In that case I'll wait and in the meantime address the rest of the comments (and in general try to improve the idea).
@AA-Turner Does this mean this PR should be closed for now or should it stay open with an appropriate label?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UltimateLobster I would suggest that you revisit the Discourse thread and see if another core developer interested in typing would sponsor this proposal. I'll close this PR for now so that we're aware that the PEP number isn't reserved, though still happy to discuss any of the comments I made in review.
A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to set expectations, I don't know whether I'd be willing to sponsor the PEP if I had fewer open PEPs; I'd have to think more about whether I think this is a good direction to go into. I'd also prefer to see more evidence of the feasibility of the idea (e.g., buy-in from type checker maintainers, ideally a prototype implementation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap to 80 columns per PEP 1
========== | ||
Consider the following example: | ||
|
||
.. code-block:: py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: py | |
.. code-block:: python |
|
||
The latter problem can be solved using ``typing.overload``: | ||
|
||
.. code-block:: py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: py | |
.. code-block:: python |
the type of ``obj['x']``. These types would have the same meaning for all python objects (Whether working with TypedDicts or | ||
dataclasses). It would also allow referring to fields of objects containing both attributes and items: | ||
|
||
.. code-block:: py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: py | |
.. code-block:: python |
Should __annotations__ be used as the reference table for fields? | ||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should __annotations__ be used as the reference table for fields? | |
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | |
Should __annotations__ be used as the reference table for fields? | |
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | |
Naming | ||
'''''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming | |
'''''' | |
Naming | |
'''''' | |
Copyright | ||
========= | ||
|
||
This document is placed in the public domain or under the CC0-1.0-Universal license, whichever is more permissive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This document is placed in the public domain or under the CC0-1.0-Universal license, whichever is more permissive. | |
This document is placed in the public domain or under the | |
CC0-1.0-Universal license, whichever is more permissive. |
func("something else") | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title: Inner Fields Annotations | ||
Author: Nir Schulman <[email protected]> | ||
Sponsor: Jelle Zijlstra <[email protected]> | ||
Discussions-To: https://discuss.python.org/t/26527 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link should go into Post-History; a new thread should be created for PEP 728 just before this PR is merged
======== | ||
|
||
This PEP specifies a way for annotations to reference the field types of other complex objects. This include the field | ||
names and types objects with static layout such as dataclasses (or dataclass-like objects), TypedDicts and NamedTuples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
names and types objects with static layout such as dataclasses (or dataclass-like objects), TypedDicts and NamedTuples. | |
names and types objects with static layout such as dataclasses (or dataclass-like objects), :py:class:`~typing.TypedDict`s and :py:class:`~typing.NamedTuple`s. |
@UltimateLobster I've added the new PEP checklist to the PR body, please may you go through it and fill in as appropriate? A |
bar: int | ||
baz: str | ||
|
||
bar: TypeAlias = Literal['baz'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use the type parameter syntax since TypeAlias is deprecated(-ish)? They technically don't do the same thing at runtime but I'm guessing both are supposed to work the same within the context of this PEP's new typing constructs.
Closing per discussion (no sponsor) A |
I know you didn't mean for other packages, but I would use this in Starlette (FastAPI dependency) as soon as it becomes available. Use case is described on python/typing#1457. FYI: I'm not trying to reopen this, I'm just randomly commenting. |
Thank you for the reply! |
FWIW, this would allow correct typing of |
Please direct all discussion to the Discourse thread, thanks! |
Appologies for the long time, as discussed in https://discuss.python.org/t/26527, I created a PEP for this suggestion.
I tried to follow the guidelines but this is my first time writing a PEP, so I'm sorry if some things do not quite follow the conventions.
Basic requirements (all PEP Types)
pep-NNNN.rst
), PR title (PEP 123: <Title of PEP>
) andPEP
headerAuthor
orSponsor
, and formally confirmed their approvalAuthor
,Status
(Draft
),Type
andCreated
headers filled out correctlyPEP-Delegate
,Topic
,Requires
andReplaces
headers completed if appropriate.github/CODEOWNERS
for the PEPStandards Track requirements
Python-Version
set to valid (pre-beta) future Python version, if relevantDiscussions-To
andPost-History
📚 Documentation preview 📚: https://pep-previews--3326.org.readthedocs.build/pep-0728/