[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-22 Thread Alex Waygood
Alex Waygood added the comment: Thanks for the PRs, Kumar — I appreciate you putting in the time. Sorry for the wasted effort. -- resolution: -> not a bug stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-21 Thread Alex Waygood
Alex Waygood added the comment: I have also been persuaded that my suggested solution is not the way to go. Thanks everybody for the useful discussion. -- ___ Python tracker

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-21 Thread Akuli
Akuli added the comment: I now agree that `# type: ignore` in dict subclasses makes sense the most, and exposing the views doesn't solve practical problems. We talked more with the people who brought this up in typing. Turns out that the correct solution to their problems was to just

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-20 Thread Guido van Rossum
Change by Guido van Rossum : -- nosy: -gvanrossum ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-20 Thread Inada Naoki
Inada Naoki added the comment: > If we literally ignore the attribute, any usage of `.mapping` will be an > error, which basically makes the whole `.mapping` feature useless for > statically typed code. It also wouldn't appear in IDE autocompletions. `.mapping` is not exist between Python

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-20 Thread Akuli
Akuli added the comment: > I also think that keeping a status quo (ignoring the mapping attribute in > typing) is the lesser evil. Can you clarify this? There are several things that typing could do, and I don't know which option you are referring to. I listed most of them below, and I'd

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-19 Thread Jelle Zijlstra
Jelle Zijlstra added the comment: I see the concerns about exposing too many implementation details. But I'm also not sure how much this will really help static typing use cases. Alex's examples just call super().keys(), but if you do that, there's not much point in overriding keys() in the

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-19 Thread Guido van Rossum
Guido van Rossum added the comment: Given all this discussion I defer to Serhiy and Inada-San. On Wed, Jan 19, 2022 at 02:23 Serhiy Storchaka wrote: > > Serhiy Storchaka added the comment: > > I share concerns of Inada-san. I also think that keeping a status quo > (ignoring the mapping

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I share concerns of Inada-san. I also think that keeping a status quo (ignoring the mapping attribute in typing) is the lesser evil. I am not sure that exposing this attribute was a good idea. We do not expose attributes list and index for list iterators.

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-19 Thread Inada Naoki
Inada Naoki added the comment: In other words, a. If `.keys()` in all dict subclasses must return subclass of `dict_keys`: `dict.keys() -> dict_keys`. b. If `.keys().mapping` must be accessible for all dict subclasses: Add `.mapping` to `KeysView`. c. If `.keys().mapping` is optional for

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-19 Thread Inada Naoki
Inada Naoki added the comment: > I agree with Inada that not every internal type should be exposed, but I > would make an exception for the dict views classes due to the fact that dict > subclasses are much more common than subclasses of other mappings, such as > OrderedDict. I don't think

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-19 Thread Alex Waygood
Alex Waygood added the comment: I agree with Inada that not every internal type should be exposed, but I would make an exception for the dict views classes due to the fact that dict subclasses are much more common than subclasses of other mappings, such as OrderedDict. I don't think it's

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-18 Thread Inada Naoki
Inada Naoki added the comment: I am not happy about exposing every internal types. I prefer duck typing. Like OrderedDict, not all dict subtypes uses `dict_keys`, `dict_views`, and `dict_items`. If typeshed annotate dict.keys() returns `dict_keys`, "incompatible override" cano not be

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-18 Thread Jelle Zijlstra
Jelle Zijlstra added the comment: The types of `.keys()`, `.items()`, and `.values()` on `collections.OrderedDict` are distinct from those for dict, and they are also not exposed anywhere. Should we put them in a public, documented place too for consistency? >>> import collections >>> od =

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-17 Thread Guido van Rossum
Guido van Rossum added the comment: Probably. On Mon, Jan 17, 2022 at 02:14 Alex Waygood wrote: > > Alex Waygood added the comment: > > Do these changes warrant an entry in "What's New in 3.11"? > > -- > > ___ > Python tracker >

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-17 Thread Alex Waygood
Alex Waygood added the comment: Do these changes warrant an entry in "What's New in 3.11"? -- ___ Python tracker ___ ___

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-17 Thread Alex Waygood
Alex Waygood added the comment: Thanks, Kumar — I appreciate it! > (Though since this can only work for 3.11+, maybe typeshed could also be > adjusted? For that you’d have to file a bug there.) Yes — it's unfortunate, but I have some ideas for hacky workarounds we can implement in typeshed

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-17 Thread Kumar Aditya
Change by Kumar Aditya : -- pull_requests: +28833 pull_request: https://github.com/python/cpython/pull/30630 ___ Python tracker ___

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-17 Thread Kumar Aditya
Kumar Aditya added the comment: I would like to work on this. -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-17 Thread Kumar Aditya
Change by Kumar Aditya : -- keywords: +patch pull_requests: +28832 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30629 ___ Python tracker ___

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-17 Thread Kumar Aditya
Change by Kumar Aditya : -- nosy: +kumaraditya303 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-16 Thread Guido van Rossum
Guido van Rossum added the comment: Okay, PR welcome. (Though since this can only work for 3.11+, maybe typeshed could also be adjusted? For that you’d have to file a bug there.) -- ___ Python tracker

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-16 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I propose that two changes be made to `dict_keys`, `dict_values` > and `dict_items`: > > * They should be officially exposed in the `types` module. > * `__class_getitem__` should be added to the classes. +1 --

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-16 Thread Alex Waygood
Alex Waygood added the comment: As a fix, I propose that two changes be made to `dict_keys`, `dict_values` and `dict_items`: * They should be officially exposed in the `types` module. * `__class_getitem__` should be added to the classes. These two changes would mean that users would be able

[issue46399] Addition of `mapping` attribute to dict views classes has inadvertently broken type-checkers

2022-01-16 Thread Alex Waygood
New submission from Alex Waygood : Issue40890 added a new `.mapping` attribute to dict_keys, dict_values and dict_items in 3.10. This addition is great for introspection. However, it has inadvertently caused some unexpected problems for type-checkers. Prior to Issue40890, the typeshed stub