[issue40890] Dict views should be introspectable

2021-10-11 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
nosy:  -pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2021-10-11 Thread Joshua Bronson


Change by Joshua Bronson :


--
nosy: +jab
nosy_count: 6.0 -> 7.0
pull_requests: +27187
pull_request: https://github.com/python/cpython/pull/28892

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-14 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-14 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 10c3b2120afa01b2c310ac50e99d8b98c943b0a2 by Pablo Galindo in 
branch 'master':
bpo-40890: Fix compiler warning in dictobject.c (GH-20876)
https://github.com/python/cpython/commit/10c3b2120afa01b2c310ac50e99d8b98c943b0a2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-14 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
nosy: +pablogsal
nosy_count: 5.0 -> 6.0
pull_requests: +20064
pull_request: https://github.com/python/cpython/pull/20876

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-14 Thread Dennis Sweeney


Change by Dennis Sweeney :


--
pull_requests: +20061
stage: resolved -> patch review
pull_request: https://github.com/python/cpython/pull/20873

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-14 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

There is a tiny portability issue.

--
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-12 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-12 Thread Raymond Hettinger


Raymond Hettinger  added the comment:


New changeset 3ee0e48b0376a710c08eec6f30e4181563b192a2 by Dennis Sweeney in 
branch 'master':
bpo-40890: Add `mapping` property to dict views (GH-20749)
https://github.com/python/cpython/commit/3ee0e48b0376a710c08eec6f30e4181563b192a2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-12 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Would it be better to have a dictview.mapping() method rather than an 
attribute, since it constructs a new object of a different type and since 
that's what keys(), values(), and items() are?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-09 Thread Inada Naoki


Inada Naoki  added the comment:

+1.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-09 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> I meant that you can make dict_view.mapping always 
> returning a MappingProxyType.

That would be a reasonable constraint.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I meant that you can make dict_view.mapping always returning a MappingProxyType.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-08 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Here's a workaround that's possible with PR 20749 applied:

>>> d = {"a":1, "b":2} # fill up the dict...
>>> DICT = object()
>>> d[DICT] = d
>>> items = d.items()
>>> del d
>>>
>>> d = items.mapping[DICT].pop(DICT)
>>> d
{'a': 1, 'b': 2}

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-08 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

PR 20749 gives each dict view access to a mappingproxy for the original dict, 
although I don't know if that defeats the original purpose.

It might be hard to sensibly make MappingProxy(d).items() return something 
other than d.items(), since this is already the behavior for user-defined 
classes:

>>> class A:
def __getitem__(self, key):
return "value"
def items(self):
return 17

>>> from types import MappingProxyType
>>> MappingProxyType(A()).items()
17

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-08 Thread Dennis Sweeney


Change by Dennis Sweeney :


--
keywords: +patch
pull_requests: +19954
pull_request: https://github.com/python/cpython/pull/20749

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Do you see any easy way to have some_mapping_proxy.items().mapping return 
some_mapping_proxy rather than unmasking the proxied dict?

--
keywords:  -easy (C), patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

property, partial, bound methods and ChinMap all do something complex with the 
underlying object. Dict-views are quite simple by comparison, is there an 
example where this would be helpful and better than just passing directly the 
mapping object?

--
nosy: +remi.lapeyre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Inada Naoki


Inada Naoki  added the comment:

> Would the best way to address this be adding new KeysProxy, ValuesProxy, and 
> ItemsProxy types?

I feel it is too much.  Until real high need is demonstrated, I don't want to 
introduce such complexity.

--
nosy: +inada.naoki

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I am not sure that it is good idea to expose internal details (do you want to 
expose also internal details of iterators?), but if expose an underlying dict 
of a dict view, I think it should be either a copy or a read-only proxy. It 
should be enough to help with introspection, but will not open the hole in 
integrity.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Would the best way to address this be adding new KeysProxy, ValuesProxy, and 
ItemsProxy types?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Indeed, with PR 20691 applied, the following crashes:

>>> vars(str).items().mapping.clear()
>>> "uh oh"

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Dennis Sweeney


Change by Dennis Sweeney :


--
keywords: +patch
pull_requests: +19906
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/20691

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

I think this will also require typing.MappingProxyType to change a bit, since 
it would make a proxy's underlying dict accessible:

>>> d = dict()
>>> proxy = MappingProxyType(d)
>>> type(proxy.items()) is type(d.items())  # should be False
True
>>> proxy.items().mapping is d  # should be False
???

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Just "mapping" would suffice.   That is variable name used in the ABCs, the 
name defined in the glossary, and the variable name used in ChainMap (in plural 
form).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-07 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

I'd be happy to write a PR.

Method names could be "mapping", "target", "target_mapping", "target_dict", 
"referent_dict", etc. 

I like the choice of "target_mapping":

d = dict()
assert d is d.keys().target_mapping
assert d is d.values().target_mapping
assert d is d.items().target_mapping

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40890] Dict views should be introspectable

2020-06-06 Thread Raymond Hettinger


New submission from Raymond Hettinger :

Dict views wrap an underlying mapping but don't expose that mapping as an 
attribute.

Traditionally, we do expose wrapped objects:  property() exposes fget,  
partial() exposes func, bound methods expose __func__, ChainMap() exposes maps, 
etc.

Exposing this attribute would help with introspection, making it possible to 
write efficient functions that operate on dict views.

--
components: Interpreter Core
keywords: easy (C)
messages: 370841
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Dict views should be introspectable
type: behavior
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com