
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-03-16 20:10 byrhettinger, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 12396 | merged | rhettinger,2019-03-18 08:28 | |
| PR 19370 | merged | serhiy.storchaka,2020-04-04 20:56 | |
| Messages (7) | |||
|---|---|---|---|
| msg338095 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2019-03-16 20:10 | |
Suggestions:* Deprecate _field_types in favor of __annotations__.* Convert __annotations__ from OrderedDict to a regular dict.This will make the API cleaner. The first one will also remove a difference between NamedTuple and namedtuple(). The second is consistent with the decision to convert _asdict() to a regular dictionary since OrderedDict is no longer necessary or desirable. The second will also make the signature of __annotations__ match that from other classes. | |||
| msg338130 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2019-03-17 14:26 | |
Good idea! This should be easy to fix/update, this was initially discussed inhttps://github.com/python/typing/issues/339. | |||
| msg338136 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2019-03-17 19:09 | |
Okay, I'll put together a PR and assign it to you :-) | |||
| msg338243 -(view) | Author: Josh Rosenberg (josh.r)*![]() | Date: 2019-03-18 15:30 | |
Would it make sense to convert _field_types to a property, so the method(s) that implement the property can do:warnings.warn("_field_types is deprecated; use __annotations__ instead", DeprecationWarning)to indicate the deprecation programmatically, not just in the documentation? The property could be backed by __annotations__ directly; they're already aliases of one another, so the only difference in behavior would be if someone was actually reassigning _field_types after class definition time (which I'm hoping is an invalid use case...). Would save some headaches for folks who run with warnings enabled, but don't read the What's New notices in detail. | |||
| msg338253 -(view) | Author: Josh Rosenberg (josh.r)*![]() | Date: 2019-03-18 16:33 | |
Blech. Just remembered _field_types is a *class* attribute, not an instance attribute, so it (just) can't be a plain property on NamedTuple itself.And because NamedTuple is super-weird (AFAICT, class X(typing.NamedTuple): pass defines a class where the class is not a subclass of typing.NamedTuple, nor are its instances instances of NamedTuple, it's just wrapping an invocation of collections.namedtuple, which directly subclasses tuple with no metaclass involvement), and making a "class property" of the type we'd need requires a metaclass (which for tuple subclasses isn't an option), serious hackery or both (https://stackoverflow.com/q/5189699/364696 ), it's probably not worth the effort to provide this warning. The only way to do it, AFAICT, would be to give the root tuple class a metaclass to provide the _field_types property, and that's a non-starter given it would, among other things, probably slow every single use of tuples just to provide the warning for this one niche case.Boo. | |||
| msg338259 -(view) | Author: miss-islington (miss-islington) | Date: 2019-03-18 16:54 | |
New changesetf7b57df0c09c3a04ab27ba06eb2feb989bbb16cb by Miss Islington (bot) (Raymond Hettinger) in branch 'master':bpo-36320: Switch typing.NamedTuple from OrderedDict to regular dict (GH-12396)https://github.com/python/cpython/commit/f7b57df0c09c3a04ab27ba06eb2feb989bbb16cb | |||
| msg365792 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2020-04-04 21:43 | |
New changeset0d1d7c8bae3f9fe9e937d2931dcbbd3555d1a9f1 by Serhiy Storchaka in branch '3.8':bpo-36320: Use the deprecated-removed directive for _field_types (GH-19370)https://github.com/python/cpython/commit/0d1d7c8bae3f9fe9e937d2931dcbbd3555d1a9f1 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:12 | admin | set | github: 80501 |
| 2020-04-04 21:43:10 | serhiy.storchaka | set | messages: +msg365792 |
| 2020-04-04 20:56:21 | serhiy.storchaka | set | nosy: +serhiy.storchaka pull_requests: +pull_request18732 |
| 2019-03-18 16:56:15 | rhettinger | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-03-18 16:54:24 | miss-islington | set | nosy: +miss-islington messages: +msg338259 |
| 2019-03-18 16:33:06 | josh.r | set | messages: +msg338253 |
| 2019-03-18 15:31:00 | josh.r | set | nosy: +josh.r messages: +msg338243 |
| 2019-03-18 08:28:03 | rhettinger | set | keywords: +patch stage: patch review pull_requests: +pull_request12351 |
| 2019-03-17 19:09:42 | rhettinger | set | messages: +msg338136 |
| 2019-03-17 14:26:07 | levkivskyi | set | messages: +msg338130 |
| 2019-03-16 20:10:14 | rhettinger | set | type: behavior |
| 2019-03-16 20:10:01 | rhettinger | create | |