Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Ivan Levkivskyi
On 25 April 2018 at 06:03, INADA Naoki wrote: > On Wed, Apr 25, 2018 at 12:04 PM, Nick Coghlan wrote: > > On 25 April 2018 at 04:56, Ethan Furman wrote: > >> On 04/24/2018 10:32 AM, Antoine Pitrou wrote: > >> > >>> Also beware the import time cost of having a widely-used module like > >>> "warn

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Jeroen Demeyer
On 2018-04-25 09:57, Ivan Levkivskyi wrote: In the latter case rewriting EnumMeta in C ... or Cython. It's a great language and I'm sure that the Python standard library could benefit a lot from it. ___ Python-ideas mailing list Python-ideas@python.

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Jacco van Dorp
> First, though, can you enumerate (pun intended) the problems with > magic strings? You list "no magic strings" as a benefit, as if it's > self-evident; I'm not sure that it is. > > ChrisA One of my main reasons would be the type-checking from tools like Pycharm, which is the one I use. If I don'

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Chris Angelico
On Wed, Apr 25, 2018 at 6:06 PM, Jacco van Dorp wrote: >> First, though, can you enumerate (pun intended) the problems with >> magic strings? You list "no magic strings" as a benefit, as if it's >> self-evident; I'm not sure that it is. >> >> ChrisA > > One of my main reasons would be the type-che

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Jacco van Dorp
2018-04-25 10:30 GMT+02:00 Chris Angelico : > On Wed, Apr 25, 2018 at 6:06 PM, Jacco van Dorp wrote: >>> First, though, can you enumerate (pun intended) the problems with >>> magic strings? You list "no magic strings" as a benefit, as if it's >>> self-evident; I'm not sure that it is. >>> >>> Chri

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Chris Angelico
On Wed, Apr 25, 2018 at 7:12 PM, Jacco van Dorp wrote: > Pycharm doesn't execute your code - it scans it. It wont know what you > store on a function object. How does it currently know what type something is? If you define something using an enum, how is PyCharm going to know what the members of

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Serhiy Storchaka
25.04.18 10:57, Ivan Levkivskyi пише: On 25 April 2018 at 06:03, INADA Naoki > wrote: enum class&member creation cost is much heavier than "import enum" cost. Especially, "import socket, ssl" is much slower than before... Is it slow simply because we are c

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Ivan Levkivskyi
On 25 April 2018 at 11:03, Serhiy Storchaka wrote: > 25.04.18 10:57, Ivan Levkivskyi пише: > >> On 25 April 2018 at 06:03, INADA Naoki > songofaca...@gmail.com>> wrote: >> enum class&member creation cost is much heavier than "import enum" >> cost. >> Especially, "import socket, ssl" is mu

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Steven D'Aprano
On Wed, Apr 25, 2018 at 10:06:56AM +0200, Jacco van Dorp wrote: > Perhaps the string encode/decode would be a better case, tho. Is it > latin 1 or latin-1 ? utf-8 or UTF-8 ? py> 'abc'.encode('latin 1') == 'abc'.encode('LATIN-1') True py> 'abc'.encode('utf8') == 'abc'.encode('UTF 8') == 'abc'.en

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Serhiy Storchaka
25.04.18 13:15, Ivan Levkivskyi пише: Hm, this is what I wanted to know. I think by rewriting EnumMeta in C we can reduce the creation time of an Enum class (almost) down to the creation time of a normal class, which may be a 4-5x speed-up. What do you think? It could be great. But I afraid th

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Guido van Rossum
On Wed, Apr 25, 2018, 01:03 Jeroen Demeyer wrote: > On 2018-04-25 09:57, Ivan Levkivskyi wrote: > > In the latter case rewriting EnumMeta in C > > ... or Cython. It's a great language and I'm sure that the Python > standard library could benefit a lot from it. > No, the stdlib should not depend

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Guido van Rossum
On Wed, Apr 25, 2018, 02:13 Jacco van Dorp wrote: > ... Which is where the auto-completion comes in. ... > Designing the language with auto-complete in mind feels wrong to me. It assumes a very sophisticated IDE and may lead to lazy design compromises. --Guido > ___

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Ethan Furman
On 04/25/2018 03:15 AM, Ivan Levkivskyi wrote: On 25 April 2018 at 11:03, Serhiy Storchaka wrote: Creating a new function is very cheap -- just around 50 ns on my computer. Creating a new class is over two orders costly -- around 7 us for an empty class on my computer. Creating a new Enum c

[Python-ideas] string method count()

2018-04-25 Thread Julia Kim
Hi, There’s an error with the string method count(). x = ‘AAA’ y = ‘AA’ print(x.count(y)) The output is 1, instead of 2. I write programs on SoloLearn mobile app. Warm regards, Julia Kim ___ Python-ideas mailing list Python-ideas@python.org https

Re: [Python-ideas] string method count()

2018-04-25 Thread João Santos
Hi, >From https://docs.python.org/3/library/stdtypes.html#str.count: str.count(*sub*[, *start*[, *end*]]) Return the number of *non-overlapping* occurrences of substring *sub* in the range [*start*, *end*]. Optional arguments *start* and *end* are interpreted as in slice notation. Best regards, J

Re: [Python-ideas] string method count()

2018-04-25 Thread Alexandre Brault
str.count counts non-overlapping instances of the substring. After counting the first 'AA', there is only one A left, so that isn't a second instance of 'AA' On 2018-04-25 02:22 PM, Julia Kim wrote: > Hi, > > There’s an error with the string method count(). > > x = ‘AAA’ > y = ‘AA’ > print(x.coun

Re: [Python-ideas] string method count()

2018-04-25 Thread Steven D'Aprano
On Wed, Apr 25, 2018 at 11:22:24AM -0700, Julia Kim wrote: > Hi, > > There’s an error with the string method count(). > > x = ‘AAA’ > y = ‘AA’ > print(x.count(y)) > > The output is 1, instead of 2. Are you proposing that there ought to be a version of count that looks for *overlapping* substri

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Antoine Pitrou
On Wed, 25 Apr 2018 14:01:43 +0300 Serhiy Storchaka wrote: > 25.04.18 13:15, Ivan Levkivskyi пише: > > Hm, this is what I wanted to know. I think by rewriting EnumMeta in C we > > can reduce the creation time of an Enum class > > (almost) down to the creation time of a normal class, which may be

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Soni L.
On 2018-04-25 12:05 PM, Guido van Rossum wrote: On Wed, Apr 25, 2018, 02:13 Jacco van Dorp > wrote: ... Which is where the auto-completion comes in. ... Designing the language with auto-complete in mind feels wrong to me. It assumes a very sophisticated IDE

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Jacco van Dorp
Even if not just for the autocompletion, it would be more explicit that it's not just a random string like you'd pass to print(), but it has a specific meaning. Something in PEP 20 about explicit and implicit ? Autocompletion might be a good advantage, but 1) the IDE would need to know what to aut