[Python-ideas] Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steve Jorgensen
I brought this up before, but I had a kind of weak understanding of `enum.Enum` at the time, so my expression of the issue and proposal for a solution were pretty awkward. Basically, with the current implementation of `Enum` and supporting classes, the only way that a member can have access to

[Python-ideas] [Suspected Spam]Re: Renaming json.load()

2019-11-30 Thread Stephen J. Turnbull
Steven D'Aprano writes: > He describes his design of the language here: We're talking about different things. Specifically: > > "Design with learning in mind" literally means "don't forget > > about beginners in Python and in programming", not "sacrifice > > everything else on the altar of

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steven D'Aprano
On Sat, Nov 30, 2019 at 08:24:39AM -, Steve Jorgensen wrote: > Basically, with the current implementation of `Enum` and supporting > classes, the only way that a member can have access to its own name > during or prior to its initialization is if/when its value is > auto-generated, so if yo

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius On Sat, 30 Nov 2019, 09:36 Christopher Barker, wrote: > So we don't have to have this entire discussion the next time this comes > up, I've posted a summary here: > > > https://pythonchb.github.i

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steve Jorgensen
Steven D'Aprano wrote: > On Sat, Nov 30, 2019 at 08:24:39AM -, Steve Jorgensen wrote: > > Basically, with the current implementation of > > Enum and supporting > > classes, the only way that a member can have access to its own name > > during or prior to its initialization is if/when its valu

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steve Jorgensen
> Per the AutoName example at > https://docs.python.org/3/library/enum.html#using-automatic-values, > one can easily use _generate_next_value_ to derive a member's value from its > name, but that is only invoked when the object's value is an instance of > auto(), so if you want to give an enum mem

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steve Jorgensen
Steve Jorgensen wrote: > I brought this up before, but I had a kind of weak understanding of > enum.Enum at the time, so my expression of the issue and proposal for a > solution were pretty awkward. > Basically, with the current implementation of Enum and supporting classes, > the only way that a m

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Brian Skinn
Why, we could even number them, call them Python-Issues Common Threads, abbreviate that as "PICT", and then refer to them as, e.g., "PICT-114"!! :-D :-D :-D :-D ... |-[ ___ Python-ideas mailing list -- [email protected] To unsubscribe send an ema

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Anders Hovmöller
Maybe the right way to think about Enum is as only for the most trivial use cases. At work we almost never use Enum because it's too limited and we instead reach for our own tri.declarative which scales up to very complex use cases. Adding a lot of features to Enum would make it less of an enum

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Brian Skinn
That aside, absolutely +1 for curating such a list. Excellent idea. ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Mes

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Paul Moore
On Sat, 30 Nov 2019 at 10:57, Brian Skinn wrote: > > Why, we could even number them, call them Python-Issues Common Threads, > abbreviate that as "PICT", and then refer to them as, e.g., "PICT-114"!! :-D > :-D :-D :-D ... |-[ I nominate this statement for the position of PICT-001 :-) Paul ___

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Stephen J. Turnbull
Abdur-Rahmaan Janhangeer writes: > Education is one side of it. It's about intuitive API Problem is, just the reactions to examples given in this thread demonstrate that personal intuition varies substantially. To identify the "intuitions" that reach the largest audience, the only halfway objec

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Stephen J. Turnbull
Christopher Barker writes: > Frankly, I get confused when there are discussion on this list (or > python-dev, or) about currently PEPs in the midst of active > discussion! I would take that as a signal to ignore that thread or poster, to be honest. If it's not clear from thread and post conte

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Wes Turner
I'd like to propose potentially adding my comments about strategies for learning APIs and typing through type annotations and introspection tooling with a potential PR to PICT-001. If there's interest, I'll consider preparing a PR? On Saturday, November 30, 2019, Paul Moore wrote: > On Sat, 30 N

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Wes Turner
Though, PICT-001 should probably be reserved as an index for other PICT documents. On Saturday, November 30, 2019, Paul Moore wrote: > On Sat, 30 Nov 2019 at 10:57, Brian Skinn wrote: >> >> Why, we could even number them, call them Python-Issues Common Threads, abbreviate that as "PICT", and the

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Richard Damon
That would be PICT-000 (PEP 0 is the index) On 11/30/19 8:25 AM, Wes Turner wrote: > Though, PICT-001 should probably be reserved as an index for other > PICT documents. > > On Saturday, November 30, 2019, Paul Moore > wrote: > > On Sat, 30 Nov 2019 at 10:57, Brian Ski

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Brian Skinn
Steve, It looks like what you're trying to achieve is an Enum with more than a singleton `.value` exposed on each sub-item. I was able to achieve something that *looks* like your example using an Enum mixin with a custom class: > from enum import Enum class Labeler: @property def la

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Adam Johnson
Peeking at the source for Enum, the __new__ method is explicitly called, thereby deferring the call to __init__ until it, too, is explicitly called, but only after member's _name_ attribute has been assigned. So, adapting your example: class ChoiceEnum(Enum): def __init__(self, value):

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Ricky Teachey
It sounds like many would agree that renaming some things could have many benefits, but the cost seems to be higher than I imagined. What if an easier way could be created to manage renaming that avoided many of these problems? Perhaps aliases of objects could be something worth baking into the l

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Brian Skinn
What happens when aliases collide with proper attributes? Could you have an attribute 'foo', combined with an attribute 'bar' with alias 'foo'? If so, how would that work? What happens when a subclass of Foo adds an attribute that masks an alias defined for an attribute of Foo? Dragons. Compli

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Ricky Teachey
> What happens when aliases collide with proper attributes? Could you have > an attribute 'foo', combined with an attribute 'bar' with alias 'foo'? If > so, how would that work? > Using a ChainMap makes this choice for us. The first level dictionary-- which would contain the attribute with the nam

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Brian Skinn
Ah, right -- relatively straightforward rule. But, one that's going to require a lot of careful thought to track down exactly how a name will resolve across an inheritance tree. Seems like a lot of extra complexity and potential for confusion for a comparatively small benefit. Also, I have to t

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread MRAB
On 2019-11-30 05:28, Andrew Barnert via Python-ideas wrote: On Nov 29, 2019, at 02:42, Steven D'Aprano wrote: Programming uses lots of initialisms, abbreviations and hybrid words, such as: os ram ssd dir json xml len chr EOF I/O rlcompleter pprint sqlite etc, and loads is not particular

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Ricky Teachey
> Also, I have to think this would be appreciably slower than the current > mechanism, having to run through this ChainMap cascade for (almost) *every* > attribute lookup? > If I remember correctly, ChainMap is pretty fast. I doubt it would be appreciably slower, though it would undoubtedly be som

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 05:10, Stephen J. Turnbull wrote: > > Why "new" users? Because experienced users will have their > "intuition" informed by their experience with "traditional" ways of > expression as codified in identifiers and syntax. For example, while > augmented assignment turns out to

[Python-ideas] namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Soni L.
I have a lot of code that looks like this:     def filter(self, it, defs):     for x in it:     for y in _match_helper(self.key, defs, x[0]):     yield (y, x[1])     def filter(self, it):     for el in it:     try:     if self.compiled.search(el[0]

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 08:02, Ricky Teachey wrote: > >  > It sounds like many would agree that renaming some things could have many > benefits, but the cost seems to be higher than I imagined. > > What if an easier way could be created to manage renaming that avoided many > of these problems? >

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 10:25, MRAB wrote: > > On 2019-11-30 05:28, Andrew Barnert via Python-ideas wrote: >>> On Nov 29, 2019, at 02:42, Steven D'Aprano wrote: >>> Programming uses lots of initialisms, abbreviations and hybrid words, such >>> as: >>> os ram ssd dir json xml len chr EOF I/O rlco

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Greg Ewing
On 1/12/19 8:54 am, Andrew Barnert via Python-ideas wrote: but that their intuition for ++ doesn’t make sense for Python while their intuition for += does. Another couple of possible reasons: * There is far less use for ++ in Python. In C, it's extremely common to step through arrays by incre

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 13:19, Soni L. wrote: > > I have a lot of code that looks like this: > > def filter(self, it, defs): > for x in it: > for y in _match_helper(self.key, defs, x[0]): > yield (y, x[1]) Try destructuring it: for key, value in it: An

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steve Jorgensen
Adam Johnson wrote: > Peeking at the source for Enum, the __new__ method is explicitly called, > thereby deferring the call to __init__ until it, too, is explicitly > called, but only after member's _name_ attribute has been assigned. So, > adapting your example: > class ChoiceEnum(Enum): > def

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Steven D'Aprano
On Sat, Nov 30, 2019 at 06:16:49PM -0300, Soni L. wrote: > It'd be quite nice if dict.items() returned a namedtuple so all these > x[0], x[1], el[0], el[1], etc would instead be x.key, x.value, el.key, > el.value, etc. It would be more readable and more maintainable. If you are doing for

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steve Jorgensen
Brian Skinn wrote: > Steve, > It looks like what you're trying to achieve is an Enum with more than a > singleton > .value exposed on each sub-item. > I was able to achieve something that looks like your example using an Enum > mixin with a custom class: > > from enum import Enum > > class Labe

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Steve Jorgensen
Anders Hovmöller wrote: > Maybe the right way to think about Enum is as only for the most trivial use > cases. At > work we almost never use Enum because it's too limited and we instead reach > for our own > tri.declarative which scales up to very complex use cases. > Adding a lot of features to

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Christopher Barker
On Sat, Nov 30, 2019 at 3:02 AM Brian Skinn wrote: > That aside, absolutely +1 for curating such a list. Excellent idea. > Thanks -- I hope you'll be able to contribute. -CHB > ___ > Python-ideas mailing list -- [email protected] > To unsubs

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Steven D'Aprano
On Sat, Nov 30, 2019 at 01:30:55PM -0500, Ricky Teachey wrote: > Consulting two dictionaries instead of one is a very very very > minor penalty. It's more than twice as expensive: not only do you have to do two look ups rather than one, but you have to also look up the second dict as well. And

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Steven D'Aprano
On Sat, Nov 30, 2019 at 06:21:29PM +, MRAB wrote: > I wouldn't like it if the names got too long. I find a certain amount of > abbreviation makes it easier to read in the long run. This. People are beginners for what, maybe 2 or 5% of their career as programmers? The minor benefit they get

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Steven D'Aprano
On Sat, Nov 30, 2019 at 11:54:35AM -0800, Andrew Barnert via Python-ideas wrote: > To an experienced C programmer, both += and ++ are intuitive. But to a > novice who’s never programmed, neither one is intuitive. Can we have a moratorium on the use of the word "intuitive" until people learn to

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Oscar Benjamin
On Sat, 30 Nov 2019 at 22:24, Steven D'Aprano wrote: > > On Sat, Nov 30, 2019 at 06:16:49PM -0300, Soni L. wrote: > > > It'd be quite nice if dict.items() returned a namedtuple so all these > > x[0], x[1], el[0], el[1], etc would instead be x.key, x.value, el.key, > > el.value, etc. It would be mo

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Brian Skinn
Me too. I'm a relative python-ideas newb, though, so I don't really know the back catalog. On Sat, Nov 30, 2019, 18:46 Christopher Barker wrote: > > > On Sat, Nov 30, 2019 at 3:02 AM Brian Skinn wrote: > >> That aside, absolutely +1 for curating such a list. Excellent idea. >> > > Thanks -- I

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Ricky Teachey
> > Consulting two dictionaries instead of one is a very very very > > minor penalty. > > It's more than twice as expensive: not only do you have to do two look > ups rather than one, but you have to also look up the second dict as > well. And there's the overhead of the ChainMap itself. > > >

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 16:15, Steven D'Aprano wrote: > On Sat, Nov 30, 2019 at 11:54:35AM -0800, Andrew Barnert via Python-ideas > wrote: > >> To an experienced C programmer, both += and ++ are intuitive. But to a >> novice who’s never programmed, neither one is intuitive. > > Can we have a mora

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 16:36, Oscar Benjamin wrote: > > On Sat, 30 Nov 2019 at 22:24, Steven D'Aprano wrote: >> >>> On Sat, Nov 30, 2019 at 06:16:49PM -0300, Soni L. wrote: >>> >>> It'd be quite nice if dict.items() returned a namedtuple so all these >>> x[0], x[1], el[0], el[1], etc would inste

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Greg Ewing
On 1/12/19 5:00 am, Ricky Teachey wrote: Perhaps aliases of objects could be something worth baking into the language itself. We would have to be using aliases a *lot* to make something like this worthwhile. I don't think that's something we should be doing or encouraging. Also, for the use ca

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Eric V. Smith
On 11/30/2019 8:51 PM, Andrew Barnert via Python-ideas wrote: On Nov 30, 2019, at 16:36, Oscar Benjamin wrote: On Sat, 30 Nov 2019 at 22:24, Steven D'Aprano wrote: On Sat, Nov 30, 2019 at 06:16:49PM -0300, Soni L. wrote: It'd be quite nice if dict.items() returned a namedtuple so all these

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius On Thu, 28 Nov 2019, 15:24 Abdur-Rahmaan Janhangeer, wrote: > "Designed With Learning in Mind" > I had no idea Guido told that or Python vowed that but thought it was a cool concept to design AP

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Wes Turner
What about keys that contain invalid characters for attribute names? items = {'1': 1, 'two-3': 4,} x = object() x.__dict__.update(items) # dangerous x = AttrDict(**items) x.1 # error x.two-3 # error On Saturday, November 30, 2019, Eric V. Smith wrote: > On 11/30/2019 8:51 PM, Andrew Barnert

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Steven D'Aprano
Apparently hitting "Send" when I intended to hit "Save" to come back and edit the message further is also "intuitive", since it involved no conscious thought. Sorry about that. Aside from cleaning up or removing some of the unfinished paragraphs, one of the major points I intended to make is th

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Steven D'Aprano
On Sat, Nov 30, 2019 at 11:13:54PM -0500, Wes Turner wrote: > Does functools.update_wrapper() *copy* __doc__ and __annotations__ or > *reference* those function/method attributes so that the API docs have the > docstrings and tools with type annotation support have the correct type > annotations?

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Steven D'Aprano
On Sat, Nov 30, 2019 at 07:40:13PM -0500, Brian Skinn wrote: > Me too. I'm a relative python-ideas newb, though, so I don't really know > the back catalog. In your Copious Spare Time(TM), I can highly recommend randomly browsing the archives looking for subjects which seem interesting to you. I'

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Abdur-Rahmaan Janhangeer
I'm lost in that new mail interfacs, i'm lost, really lost. It's the 'HyperTrippy' version. Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius ___ Python-ideas mailing list -- [email protected] To u

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 20:13, Steven D'Aprano wrote: > > On Sat, Nov 30, 2019 at 05:31:01PM -0800, Andrew Barnert wrote: >>> On Nov 30, 2019, at 16:15, Steven D'Aprano wrote: >>> On Sat, Nov 30, 2019 at 11:54:35AM -0800, Andrew Barnert via Python-ideas >>> wrote: >>> To an experienced C pr

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-11-30 Thread Andrew Barnert via Python-ideas
On Nov 30, 2019, at 20:21, Wes Turner wrote: > > What about keys that contain invalid characters for attribute names? What about them? > items = {'1': 1, 'two-3': 4,} > x = object() > x.__dict__.update(items) # dangerous > x = AttrDict(**items) > x.1 # error > x.two-3 # error The message

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Stephen J. Turnbull
Andrew Barnert via Python-ideas writes: > It’s not “things people have learned to expect”, it’s “things > people apprehend without having to think consciously”. Which is > what “intuitive” means. I believe many people make a distinction between unconscious apprehension as perception ("intuitio

[Python-ideas] Re: Renaming json.load()

2019-11-30 Thread Stephen J. Turnbull
Andrew Barnert writes: > I’m not sure this example really argues the case. > > To an experienced C programmer, both += and ++ are intuitive. But > to a novice who’s never programmed, neither one is intuitive. I'm sorry, I expressed my point poorly, which is, first, that IMHO your statement a

[Python-ideas] Re: Access to member name/names via context during Enum instance initialization

2019-11-30 Thread Anders Hovmöller
> On 30 Nov 2019, at 23:30, Steve Jorgensen wrote: > > Anders Hovmöller wrote: >> Maybe the right way to think about Enum is as only for the most trivial use >> cases. At >> work we almost never use Enum because it's too limited and we instead reach >> for our own >> tri.declarative which sc