Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue38191

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:typing.NamedTuple() should prefix parameters with '_'
Type:enhancementStage:resolved
Components:Library (Lib)Versions:Python 3.9, Python 3.8, Python 3.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: gribbg, gvanrossum, levkivskyi, miss-islington, serhiy.storchaka
Priority:normalKeywords:patch

Created on2019-09-16 19:59 bygribbg, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 16222mergedserhiy.storchaka,2019-09-17 09:31
PR 16237mergedmiss-islington,2019-09-17 18:22
PR 16238mergedserhiy.storchaka,2019-09-17 18:33
PR 16239mergedserhiy.storchaka,2019-09-17 18:42
PR 16240mergedserhiy.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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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
DateUserActionArgs
2022-04-11 14:59:20adminsetgithub: 82372
2019-09-18 06:08:31serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-09-18 06:08:04serhiy.storchakasetmessages: +msg352697
2019-09-17 19:41:59serhiy.storchakasetmessages: +msg352659
2019-09-17 19:09:15serhiy.storchakasetmessages: +msg352657
2019-09-17 18:53:53serhiy.storchakasetmessages: +msg352656
2019-09-17 18:51:36serhiy.storchakasetpull_requests: +pull_request15837
2019-09-17 18:42:23serhiy.storchakasetpull_requests: +pull_request15836
2019-09-17 18:41:58miss-islingtonsetnosy: +miss-islington
messages: +msg352655
2019-09-17 18:33:28serhiy.storchakasetpull_requests: +pull_request15835
2019-09-17 18:22:13miss-islingtonsetpull_requests: +pull_request15834
2019-09-17 18:22:04serhiy.storchakasetmessages: +msg352654
2019-09-17 09:36:22serhiy.storchakasetmessages: +msg352622
2019-09-17 09:31:48serhiy.storchakasetkeywords: +patch
stage: patch review
pull_requests: +pull_request15822
2019-09-17 08:11:18serhiy.storchakasetassignee:serhiy.storchaka

messages: +msg352620
nosy: +serhiy.storchaka,levkivskyi,gvanrossum
2019-09-16 19:59:55gribbgcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp