
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2019-09-16 19:59 bygribbg, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 16222 | merged | serhiy.storchaka,2019-09-17 09:31 | |
| PR 16237 | merged | miss-islington,2019-09-17 18:22 | |
| PR 16238 | merged | serhiy.storchaka,2019-09-17 18:33 | |
| PR 16239 | merged | serhiy.storchaka,2019-09-17 18:42 | |
| PR 16240 | merged | serhiy.storchaka,2019-09-17 18:51 | |
| Messages (9) | |||
|---|---|---|---|
| msg352579 -(view) | Author: Glenn Gribble (gribbg) | Date: 2019-09-16 19:59 | |
At present, it is not possible to use the shorthand notation to define a NamedTuple with typename or fields. I.e., NamedTuple('MyTuple', typename=str, fields=int) does not work. Changing the parameter names to _typename and _fields would allow any non-private, legal identifier to be used in the shorthand notation. >>> import typing>>> typing.NamedTuple('Example', fieldz=int)<class '__main__.Example'>>>> typing.NamedTuple('Example2', fields=int)Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files\Python37\lib\typing.py", line 1411, in __new__ return _make_nmtuple(typename, fields) File "C:\Program Files\Python37\lib\typing.py", line 1326, in _make_nmtuple types = [(n, _type_check(t, msg)) for n, t in types]TypeError: 'type' object is not iterableOf course, it is fairly easy to work around the issue by using fields parameter:>>> typing.NamedTuple('Example3', [('fields', int)])<class '__main__.Example3'>There would be backwards compatibility issues with any code using named arguments for fields or typename. | |||
| msg352620 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-17 08:11 | |
Looks as a good case for positional-only parameters.But first passing these arguments by keyword should be deprecated. | |||
| msg352622 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-17 09:36 | |
PR 16222 adds support for arbitrary keyword argument names in NamedTuple and TypedDict. Passing arguments like "typename", "_typename", "fields" and "_fields" by keyword is still supported, but deprecated. I'm going to backport this to 3.8 and 3.7 (to 3.7 without deprecation warnings), and than convert warnings to error in master (by using positional-only parameters syntax). | |||
| msg352654 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-17 18:22 | |
New changeset2bf31ccab3d17f3f35b42dca97f99576dfe2fc7d by Serhiy Storchaka in branch 'master':bpo-38191: Accept arbitrary keyword names in NamedTuple() and TypedDict(). (GH-16222)https://github.com/python/cpython/commit/2bf31ccab3d17f3f35b42dca97f99576dfe2fc7d | |||
| msg352655 -(view) | Author: miss-islington (miss-islington) | Date: 2019-09-17 18:41 | |
New changeset54ba5f19d4a654768c785468d736ed0bd05947f5 by Miss Islington (bot) in branch '3.8':bpo-38191: Accept arbitrary keyword names in NamedTuple() and TypedDict(). (GH-16222)https://github.com/python/cpython/commit/54ba5f19d4a654768c785468d736ed0bd05947f5 | |||
| msg352656 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-17 18:53 | |
Oh, when backported to 3.7 I have found that TypedDict is new in 3.8. So I think it is better to get rid of deprecations in TypedDict(). | |||
| msg352657 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-17 19:09 | |
New changeset69b3718b183a698202bd67488639bffd64a488bc by Serhiy Storchaka in branch '3.7':[3.7]bpo-38191: Accept arbitrary keyword names in NamedTuple(). (GH-16222) (GH-16239)https://github.com/python/cpython/commit/69b3718b183a698202bd67488639bffd64a488bc | |||
| msg352659 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-17 19:41 | |
New changeset8fc5839a9def34c13b6025c291434ba5fb5d6442 by Serhiy Storchaka in branch 'master':bpo-38191: Turn warnings into errors in NamedTuple() and TypedDict(). (GH-16238)https://github.com/python/cpython/commit/8fc5839a9def34c13b6025c291434ba5fb5d6442 | |||
| msg352697 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-18 06:08 | |
New changeset2adcd79bf90415147691a51a4cb046d5920f6ce7 by Serhiy Storchaka in branch '3.8':bpo-38191: Use positional-only parameters in TypedDict(). (GH-16240)https://github.com/python/cpython/commit/2adcd79bf90415147691a51a4cb046d5920f6ce7 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:20 | admin | set | github: 82372 |
| 2019-09-18 06:08:31 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-09-18 06:08:04 | serhiy.storchaka | set | messages: +msg352697 |
| 2019-09-17 19:41:59 | serhiy.storchaka | set | messages: +msg352659 |
| 2019-09-17 19:09:15 | serhiy.storchaka | set | messages: +msg352657 |
| 2019-09-17 18:53:53 | serhiy.storchaka | set | messages: +msg352656 |
| 2019-09-17 18:51:36 | serhiy.storchaka | set | pull_requests: +pull_request15837 |
| 2019-09-17 18:42:23 | serhiy.storchaka | set | pull_requests: +pull_request15836 |
| 2019-09-17 18:41:58 | miss-islington | set | nosy: +miss-islington messages: +msg352655 |
| 2019-09-17 18:33:28 | serhiy.storchaka | set | pull_requests: +pull_request15835 |
| 2019-09-17 18:22:13 | miss-islington | set | pull_requests: +pull_request15834 |
| 2019-09-17 18:22:04 | serhiy.storchaka | set | messages: +msg352654 |
| 2019-09-17 09:36:22 | serhiy.storchaka | set | messages: +msg352622 |
| 2019-09-17 09:31:48 | serhiy.storchaka | set | keywords: +patch stage: patch review pull_requests: +pull_request15822 |
| 2019-09-17 08:11:18 | serhiy.storchaka | set | assignee:serhiy.storchaka messages: +msg352620 nosy: +serhiy.storchaka,levkivskyi,gvanrossum |
| 2019-09-16 19:59:55 | gribbg | create | |