Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Nick Timkovich
On Tue, Nov 21, 2017 at 6:45 PM, Steven D'Aprano wrote: > On Tue, Nov 21, 2017 at 04:56:27PM -0600, Nick Timkovich wrote: > > On Tue, Nov 21, 2017 at 4:16 PM, Sven R. Kunze wrote: > > > > > Maybe, that suffices: https://pypi.python.org/pypi/xheap > > > > >

Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Chris Angelico
On Wed, Nov 22, 2017 at 3:55 PM, Greg Ewing wrote: > Chris Angelico wrote: >> >> So the question is more: why, with Python being the way it is, do the >> heap functions operate on a list? I think heapq.heapify is the answer: >> in linear time, it heapifies a list *in

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Stéfane Fermigier
Javascript (ES6) has 'let' and 'const' for mutable and constant variables, respectively. When programming in JS, I find myself aggressively aiming for as little 'let' and as much 'const' as reasonably possible, since reasoning about constants is much easier than about variables. In this context,

Re: [Python-ideas] Ignorable whitespaces in the re.VERBOSE mode

2017-11-21 Thread Serhiy Storchaka
21.11.17 04:20, Stephen J. Turnbull пише: Serhiy Storchaka writes: > I agree. But if there is a special part of the Unicode standard for > Pattern White Spaces which includes non-ASCII characters, perhaps there > is a need in them. I asked for the case if Python developers with very >

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Saeed Baig
al Software - > http://www.abilian.com/ > Chairman, Free Group / Systematic Cluster - > http://www.gt-logiciel-libre.org/ > Co-Chairman, National Council for Free & Open Source Software (CNLL) - > http://cnll.fr/ > Founder & Organiser, PyData Paris - http://pydata.fr/ >

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Bernardo Sulzbach
This could also be useful if one eventually wanted to implement constant optimizations in the interpreter as it would be possible to detect constants when they are declared without any code analysis. This would be "constant" as in Java constants right? Referential constants, so that if an

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 02:38:45AM -0500, Joseph Jevnik wrote: > How is that different from "pi = 3.14"? pi = 3.14 pi = 5 print(pi) # prints 5 let pi = 3.14 pi = 5 # raises an exception -- Steve ___ Python-ideas mailing list

[Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Kirill Balunov
Hello. Currently during star assignement the new list is created. What was the idea to produce new list instead of returning an iterator? It seems to me that returning an iterator more suited to the spirit of Python 3. There are three cases: 1. a,b,c,*d = something_iterable 2. *a,b,c,d =

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Serhiy Storchaka
21.11.17 10:54, Kirill Balunov пише: Of course this version has drawbacks (the first that come to mind): 1. Will *b see change if rhs is some muttable sequence? 2. Will *b one way iterator or somethong like range? But still it seems to me that the "iterator way" has more useful applications.

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Kirill Balunov
> Your implementation iterates seq multiple times. But iterable unpacking > syntax works with an arbitrary iterable, and iterates it only once. > Oh sorry, I know that my implementation iterates seq multiple times, I only provide this to show the idea. It can be much optimized at C level. I just

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 12:27:32PM +0300, Kirill Balunov wrote: > Backward compatibility is an important issue, but at the same time it is > the main brake on progress. "Progress just means bad things happen faster." -- Terry Pratchett, "Witches Abroad" [...] > And how do you look at something

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Clint Hepner
> On Nov 21, 2017, at 5:40 AM, Stéfane Fermigier wrote: > > for i in range(0, 100): >const foo = f(i) >const bar = g(i, foo) >do_something_with(bar) This wouldn’t work, since a for loop doesn’t introduce a new scope for variables, and allowing a constant to be

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Stéfane Fermigier
That's one way to do it with no changes to the language, though syntaxically I find it lacking a bit of elegance (maybe a matter of getting accustomed with it?). Also, I'm not sure "Final" really conveys what it means (at first glance, I thought it was about immutability, not constantness).

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Ivan Levkivskyi
On 21 November 2017 at 12:12, Stéfane Fermigier wrote: > That's one way to do it with no changes to the language, though > syntaxically I find it lacking a bit of elegance (maybe a matter of getting > accustomed with it?). > > Also, I'm not sure "Final" really conveys what it

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 08:34:31PM +1100, Saeed Baig wrote: > > Hi. Just to respond to some peoples’ points… > Bernardo asked 'This would be "constant" as in Java constants right? > Referential > constants, so that if an object were mutable you would still be able to > change its internal

Re: [Python-ideas] Rewriting the "roundrobin" recipe in the itertools documentation

2017-11-21 Thread Serhiy Storchaka
The roundrobin() implementation in recipes has quadratic time for large number of iterables. As well as all other proposed implementations. This is a problem if you use it with hundreds or thousands of iterables. For example: list(roundrobin(*([[1]]*1000))) next(roundrobin(*([[]]*1000

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Serhiy Storchaka
21.11.17 11:27, Kirill Balunov пише: Your implementation iterates seq multiple times. But iterable unpacking syntax works with an arbitrary iterable, and iterates it only once. Oh sorry, I know that my implementation iterates seq multiple times, I only provide this to show the

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Serhiy Storchaka
21.11.17 11:34, Saeed Baig пише: Serhiy asked, in relation to constants, “To do what? What problem do you need to solve?”. No problem in particular, to be honest. I just thought they’d be nice since they’d increase confidence that my variables-intended-to-be-constants wouldn’t get reassigned,

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Stéfane Fermigier
On Tue, Nov 21, 2017 at 11:03 AM, Serhiy Storchaka wrote: > 21.11.17 11:34, Saeed Baig пише: > >> Serhiy asked, in relation to constants, “To do what? What problem do you >> need to solve?”. No problem in particular, to be honest. I just thought >> they’d be nice since

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Ivan Levkivskyi
On 21 November 2017 at 10:47, Paul Moore wrote: > -1. I don't see how this would improve any programs I've written or > seen. Tools like mypy or linters might benefit from a feature to track > constants and ensure they don't get changed > It is actually likely that

Re: [Python-ideas] Looking for input to help with the pip situation

2017-11-21 Thread Paul Moore
[Excuse any attribution errors, the quoting appears to have got badly messed up somehow] On 21 November 2017 at 06:21, Steve Barnes wrote: > > On 21/11/2017 00:32, Chris Barker wrote: >> I >> don't know what would be the best approach for adding copies/links of >>

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Serhiy Storchaka
21.11.17 11:47, Paul Moore пише: -1. I don't see how this would improve any programs I've written or seen. Tools like mypy or linters might benefit from a feature to track constants and ensure they don't get changed, but I don't think it's needed as a language feature. Seriously, has anyone ever

Re: [Python-ideas] Rewriting the "roundrobin" recipe in the itertools documentation

2017-11-21 Thread Serhiy Storchaka
21.11.17 11:44, Serhiy Storchaka пише: The roundrobin() implementation in recipes has quadratic time for large number of iterables. As well as all other proposed implementations. This is a problem if you use it with hundreds or thousands of iterables. For example:    

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 11:40:14AM +0100, Stéfane Fermigier wrote: > for i in range(0, 100): >const foo = f(i) >const bar = g(i, foo) >do_something_with(bar) I wouldn't expect that to work. You are binding some value f(0) to the constant name "foo" on the first loop, then on the

Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Stephen J. Turnbull
bunslow writes: > Perhaps such repetition is a sign that *something* needs to be > done... It's not. Most such repetition is due to new people who have not read the last 20 years of archives. :-) (In case the smiley isn't clear enough, parse that as "all the new people who aren't

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Kirill Balunov
May be the first thing which I should do is to improve my English:) My main point was that in many cases (in my experience) it is a waste of memory to store entire list for star variable (*b) instead of some kind of iterator or deferred evaluation. How do you defer evaluating the second and

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread brent bejot
Are there any 3rd party tools that already implement this? By my understanding, type annotations started as 3rd party tools that became popular and so are now incorporated into the language proper. I could see a 'const' syntax making its way into the language that way, but not directly.

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Victor Stinner
2017-11-21 7:33 GMT+01:00 Saeed Baig : > Hey guys I am thinking of perhaps writing a PEP to introduce user-defined > constants to Python. Something along the lines of Swift’s “let” syntax (e.g. > “let pi = 3.14”). If you want to work on a PEP, you will have to write a

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Koos Zevenhoven
FWIW, here's something for working with memory-efficient sequences (and generators), which should get more features in the future: pip install git+https://github.com/k7hoven/views Some examples of what it does: py> from views import seq py> seq[::range(3), None, ::"abc", "Hi!"] py>

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Chris Barker
On Tue, Nov 21, 2017 at 6:37 AM, Kirill Balunov wrote: > Currently, __repr__ and __str__ representation of bytes is the same. > Perhaps it is worth making them different, this will make it easier to > visually perceive them as a container of integers from 0 to 255, >

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Ivan Levkivskyi
On 21 November 2017 at 14:22, Kirill Balunov wrote: > It is not set in stone, but it looks like most people like Final (although >> the initial proposal was Const, see https://github.com/python/mypy >> /issues/1214) >> > > > Ivan, you mean this thread "Can't index named

[Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Kirill Balunov
Currently, __repr__ and __str__ representation of bytes is the same. Perhaps it is worth making them different, this will make it easier to visually perceive them as a container of integers from 0 to 255, instead of a mixture of printable and non-printable ascii characters. It is proposed: a)

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Serhiy Storchaka
21.11.17 13:53, Kirill Balunov пише: If I can not copy at Python level, I can 'tee' when 'star_pos' is reached. And tee() uses a real RAM for saving items. ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] Allow additional separator character in variables

2017-11-21 Thread Stephan Houben
2017-11-21 12:55 GMT+01:00 Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp>: > Personally, I think that Python probably should ban non-ASCII > non-letter characters in identifiers and whitespace, and maybe add > them later in response to requests from native speakers of the > relevant

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Kirill Balunov
> > It is not set in stone, but it looks like most people like Final (although > the initial proposal was Const, see https://github.com/python/ > mypy/issues/1214) > Ivan, you mean this thread "Can't index named tuple by defined constant" ? With kind

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 05:37:36PM +0300, Kirill Balunov wrote: > Currently, __repr__ and __str__ representation of bytes is the same. > Perhaps it is worth making them different, this will make it easier to > visually perceive them as a container of integers from 0 to 255, > instead of a mixture

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Victor Stinner
Hi, While it may shock you, using bytes for "text" makes sense in some areas. Please read the Motivation of the PEP 461: https://www.python.org/dev/peps/pep-0461/#motivation Victor 2017-11-21 15:37 GMT+01:00 Kirill Balunov : > Currently, __repr__ and __str__

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread אלעזר
בתאריך יום ג׳, 21 בנוב׳ 2017, 19:36, מאת Chris Barker ‏< chris.bar...@noaa.gov>: > ... > And what's the use-case, really? beyond the use case for all sorts of > static typing... > I don't understand the question. The use case was explained before - people want to have better ways to reason

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Stéfane Fermigier
On Tue, Nov 21, 2017 at 6:34 PM, Chris Barker wrote: > > And what's the use-case, really? beyond the use case for all sorts of > static typing... > Javascript is dynamically typed, and has 'const' variable declaration which were added in ES6. Static typing is not the

Re: [Python-ideas] Rewriting the "roundrobin" recipe in the itertools documentation

2017-11-21 Thread Alon Snir
def roundrobin(*iterables): "roundrobin('ABC', 'D', 'EF') --> A D E B F C" nexts = [ iter(it).__next__ for it in iterables ] i = 0 while nexts: i %= len(nexts) try: yield nexts[i]() except StopIteration: del nexts[i] else:

Re: [Python-ideas] Star assignment in iterator way?

2017-11-21 Thread Terry Reedy
On 11/21/2017 3:54 AM, Kirill Balunov wrote: Hello. Currently during star assignement the new list is created. What was the idea to produce new list instead of returning an iterator? It seems to me that returning an iterator more suited to the spirit of Python 3. There are three cases: 1.

Re: [Python-ideas] Allow additional separator character in variables

2017-11-21 Thread Mikhail V
Serhiy Storchaka wrote: > Yes, it causes less confusion that changing meaning of a minus. If those chars are not used at all, then yes :) And I don't recall I was exactly propsing changing meaning of minus > But the name моязмінна doesn't cause any confusion if used in an > appropriate context

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Kirill Balunov
2017-11-21 20:22 GMT+03:00 Chris Barker wrote: > But the way you did your example indicates that: > > bytes((42, 43, 44, 45, 46)) > > would be an even better __repr__, if the goal is to make it clear and easy > that it is a "container of integers from 0 to 255" > > I've

Re: [Python-ideas] Allow additional separator character in variables

2017-11-21 Thread Stephan Houben
Hi all, If anybody is still worried about this, here is a 29-line proof-of-concept code checker which warns if your source file contains identifiers which are different but look the same. https://gist.github.com/stephanh42/61eceadc2890cf1b53ada5e48ef98ad1 Stephan 2017-11-21 19:19 GMT+01:00

Re: [Python-ideas] Allow additional separator character in variables

2017-11-21 Thread Serhiy Storchaka
21.11.17 22:03, Stephan Houben пише: If anybody is still worried about this, here is a 29-line proof-of-concept code checker which warns if your source file contains identifiers which are different but look the same. https://gist.github.com/stephanh42/61eceadc2890cf1b53ada5e48ef98ad1 Ha! I

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Greg Ewing
Steven D'Aprano wrote: for i in range(0, 100): const foo = f(i) const bar = g(i, foo) do_something_with(bar) You are binding some value f(0) to the constant name "foo" on the first loop, then on the second loop you try to rebind a new value to the same name "foo". It could be made to

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Hugh Fisher
> Message: 4 > Date: Tue, 21 Nov 2017 18:05:17 + > From: ? > To: Chris Barker > Cc: Python-Ideas > Subject: Re: [Python-ideas] Should Python have user-defined constants? [munch] > > It was mentioned that there are

Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Nick Timkovich
On Tue, Nov 21, 2017 at 4:16 PM, Sven R. Kunze wrote: > Maybe, that suffices: https://pypi.python.org/pypi/xheap > I still think the heapq.heap* functions are atrocious and they should immediately be packaged with *no additional features* into a stdlib object for reasons along

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Sven R. Kunze
On 21.11.2017 19:05, אלעזר wrote: I don't understand the question. The use case was explained before - people want to have better ways to reason about their programs. Statically. Why dismiss it as a non-usecase? It's helpful for both tools and humans. Then type annotations are for them. But

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 01:35:41PM -0200, Joao S. O. Bueno wrote: > On 21 November 2017 at 13:16, Steven D'Aprano wrote: > > I'd rather leave __str__ and __repr__ alone. Changing them will have > > huge backwards compatibility implications. I'd rather give bytes a > >

Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Sven R. Kunze
Maybe, that suffices: https://pypi.python.org/pypi/xheap On 21.11.2017 03:46, bunslow wrote: Perhaps such repetition is a sign that *something* needs to be done... Thanks for the link though. I'm new enough to the community that it didn't even occur to me to search for prior discussions.

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Nick Timkovich
On Tue, Nov 21, 2017 at 11:22 AM, Chris Barker wrote: > supposedly __repr__ is supposed to give an eval-able version -- which your > proposal is. But the way you did your example indicates that: > > bytes((42, 43, 44, 45, 46)) > > would be an even better __repr__, if the

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Steven D'Aprano
On Wed, Nov 22, 2017 at 11:47:28AM +1100, Chris Angelico wrote: > On Wed, Nov 22, 2017 at 11:27 AM, Steven D'Aprano wrote: > > Types are literally irrelevant to this, except in the sense that in many > > languages, including Python, the distinction between mutable and > >

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Chris Angelico
On Wed, Nov 22, 2017 at 12:51 PM, Steven D'Aprano wrote: > On Wed, Nov 22, 2017 at 11:47:28AM +1100, Chris Angelico wrote: >> On Wed, Nov 22, 2017 at 11:27 AM, Steven D'Aprano >> wrote: > >> > Types are literally irrelevant to this, except in the sense

Re: [Python-ideas] Rewriting the "roundrobin" recipe in the itertools documentation

2017-11-21 Thread Wes Turner
Here's toolz.itertoolz.interleave(): def interleave(seqs): """ Interleave a sequence of sequences >>> list(interleave([[1, 2], [3, 4]])) [1, 3, 2, 4] >>> ''.join(interleave(('ABC', 'XY'))) 'AXBYC' Both the individual sequences and the sequence of sequences may be infinite

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 09:34:33AM -0800, Chris Barker wrote: > On Tue, Nov 21, 2017 at 3:31 AM, Steven D'Aprano > wrote: > > The > > interesting (but is it useful?) concept is constant identifiers which > > cannot be re-bound or re-assigned once they are set the first

Re: [Python-ideas] Make bytes __repr__ and __str__ representation different?

2017-11-21 Thread Chris Angelico
On Wed, Nov 22, 2017 at 9:49 AM, Nick Timkovich wrote: > On Tue, Nov 21, 2017 at 11:22 AM, Chris Barker > wrote: >> >> supposedly __repr__ is supposed to give an eval-able version -- which your >> proposal is. But the way you did your example

Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Chris Angelico
On Wed, Nov 22, 2017 at 11:45 AM, Steven D'Aprano wrote: > On Tue, Nov 21, 2017 at 04:56:27PM -0600, Nick Timkovich wrote: >> On Tue, Nov 21, 2017 at 4:16 PM, Sven R. Kunze wrote: >> >> > Maybe, that suffices: https://pypi.python.org/pypi/xheap >> > >> I

Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Steven D'Aprano
On Tue, Nov 21, 2017 at 04:56:27PM -0600, Nick Timkovich wrote: > On Tue, Nov 21, 2017 at 4:16 PM, Sven R. Kunze wrote: > > > Maybe, that suffices: https://pypi.python.org/pypi/xheap > > > I still think the heapq.heap* functions are atrocious and they should > immediately be

Re: [Python-ideas] Should Python have user-defined constants?

2017-11-21 Thread Chris Angelico
On Wed, Nov 22, 2017 at 11:27 AM, Steven D'Aprano wrote: > On Tue, Nov 21, 2017 at 09:34:33AM -0800, Chris Barker wrote: >> On Tue, Nov 21, 2017 at 3:31 AM, Steven D'Aprano >> wrote: > >> > The >> > interesting (but is it useful?) concept is constant

Re: [Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

2017-11-21 Thread Greg Ewing
Chris Angelico wrote: So the question is more: why, with Python being the way it is, do the heap functions operate on a list? I think heapq.heapify is the answer: in linear time, it heapifies a list *in place*. There's no reason a Heap object couldn't accomodate that case. E.g. the constructor