1 Fore St, London, EC2Y 9DT
Machinalis Limited is a company registered in England and Wales. Registered number: 10574987.
As reference of prior art, there is https://pypi.python.org/pypi/munch in PyPI
Serhiy Storchaka wrote:
> In 3.7 I have removed an old-deprecated plistlib.Dict. [1] Actually it
> already was deprecated when the plistlib module was added to the regular
> stdlib in Python 2.6.
>
> Raymond noticed that that capability seemed nice to have.
So nice in fact that I'm sure I've reimplemented something similar
several times. :)
> What do you think about reviving this type as general purpose type in
> collections or types? Perhaps it can be convenient for working with
> JSON, plists, configuration files, databases and in other cases that
> need a dict with string keys.
>
> If reintroduce it, there are open questions.
>
> 1. The name of the type.
>
> 2. The location of the type. collections or types? Or other variants?
>
> 3. How it will collaborate with OrderedDict, defaultdict, etc?
>
> 4. Should it be a dict subclass, or a mixin, or a proxy? Or add several
> types?
I also wonder whether PEP 557 dataclasses could provide this except in
the opposite direction, e.g. by optionally adding __getitem__ support.
This is a dict subclass which allows to access items as attributes.
d = plistlib.Dict()
d['a'] = 1
assert d.a == 1
d.b = 2
assert d['b'] == 2
What do you think about reviving this type as general purpose type in collections or types
On Wed, Nov 29, 2017 at 12:52 AM, Serhiy Storchaka <stor...@gmail.com> wrote:
This is a dict subclass which allows to access items as attributes.
d = plistlib.Dict()
d['a'] = 1
assert d.a == 1
d.b = 2
assert d['b'] == 2
What do you think about reviving this type as general purpose type in collections or types
Am I I the only one that thinks this is a "Bad Idea"?
For me, it simply confuses even more the question of "is this code or is this data?" -- which is a difficult enough design question in a dynamic language.
And the couple of libraries I"ve worked with that do this I liked at first, but grew to find problematic.
On 01.12.2017 1:19, Greg Ewing wrote:
> Ivan Pozdeev via Python-ideas wrote:
>> I needed to hold an external function reference in an object instance
>> (if I assigned it to an attribute, it was converted into an instance
>> method).
>
> No, that only happens to functions stored in *class* attributes,
> not instance attributes.
>
> >>> class A:
> ... pass
> ...
> >>> a = A()
> >>>
> >>> def f():
> ... print("I'm just a function")
> ...
> >>> a.x = f
> >>> a.x()
> I'm just a function
>
Well, yes, that was a singleton class, so I kept data in the class
object. Now I can simplify the code by only keeping the instance
reference in the class, thank you. (Without knowing this, that bore no
visible benefits.)
--
Regards,
Ivan