Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Guido van Rossum
On Sun, Oct 21, 2018 at 6:08 PM Nathaniel Smith wrote: I'm not sure if this is an issue the way Queue is used in practice, but in general you have to be careful with this kind of circular flow because if your queue communicates backpressure (which it should) then circular flows can deadlock.

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Cameron Simpson
On 21Oct2018 21:19, Vladimir Filipović wrote: On Sun, Oct 21, 2018 at 8:45 PM MRAB wrote: FTR, this has been discussed before: [Python-ideas] `__iter__` for queues? https://mail.python.org/pipermail/python-ideas/2010-January/006711.html Thank you! Hmm, yes. My post there is this one:

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Cameron Simpson
On 21Oct2018 18:06, Nathaniel Smith wrote: On Sun, Oct 21, 2018, 16:48 MRAB wrote: On 2018-10-21 22:30, Antoine Pitrou wrote: > Ah. This is the one statement that makes me favorable to this > idea. > When there is a single consumer, it's easy enough to send a sentinel. > But when there are

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Steven D'Aprano
On Mon, Oct 22, 2018 at 10:25:19AM +1100, Chris Angelico wrote: > On Mon, Oct 22, 2018 at 10:16 AM Terry Reedy wrote: > > Except for relatively trivial expressions, this is a bad thing. All > > functions created from lambda expressions get the same pseudo-name > > ''. This can make tracebacks

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 11:40 AM Steven D'Aprano wrote: > > On Mon, Oct 22, 2018 at 10:25:19AM +1100, Chris Angelico wrote: > > On Mon, Oct 22, 2018 at 10:16 AM Terry Reedy wrote: > > > > Except for relatively trivial expressions, this is a bad thing. All > > > functions created from lambda

Re: [Python-ideas] Python Enhancement Proposal for List methods

2018-10-21 Thread David Mertz
I have changed my opinion to -1 on list.replace(). While max=n is a useful argument, a plain function could work equally well on every sequence and not be specific to lists. On Sun, Oct 21, 2018, 10:18 AM David Mertz The list comprehensions are not very hard, and are more general. EXCEPT > with

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Nathaniel Smith
On Sun, Oct 21, 2018, 16:48 MRAB wrote: > On 2018-10-21 22:30, Antoine Pitrou wrote: > > On Sun, 21 Oct 2018 19:58:05 +0200 > > Vladimir Filipović > > wrote: > >> > >> To anticipate a couple more possible questions: > >> > >> - What would this proposal do about multiple producers/consumers > >>

Re: [Python-ideas] TypeHinting: From variable name to type

2018-10-21 Thread David Mertz
On Fri, Oct 19, 2018 at 3:18 AM Thomas Güttler wrote: > Now my idea: Per module and/or per file type hinting from variable name. > Maybe a magic docstring in the __init__.py file: > variable-name-mapping: > { > request: django.http.HttpRequest, > } > In general, I like this idea; but

[Python-ideas] Python Enhancement Proposal for List methods

2018-10-21 Thread Siva Sukumar Reddy
Hey everyone, I am really new to Python contribution community want to propose below methods for List object. Forgive me if this is not the format to send an email. 1. *list.replace( item_to_be_replaced, new_item )*: which replaces all the occurrences of an element in the list instead of writing

[Python-ideas] IPLike objects

2018-10-21 Thread Damla Altun
Hi, Python's ipaddress module is really good for working with network / IP related thing. I would like to use ipaddress.IPv4/v6Address in creating network interfaces. Like a socket but i can't, the internal things and some standard libraries doesn't support them (even socket). >>>

Re: [Python-ideas] IPLike objects

2018-10-21 Thread Andrew Svetlov
Should we support bytes? Why? For path name, the bytes are sometimes the only way to encode the file name, Posix operates with bytes internally. But IP addresses are always ASCII strings. I doubt if we shall support bytes for it, complicating the implementation. Support for `int` in `get_addr()`

Re: [Python-ideas] Python Enhancement Proposal for List methods

2018-10-21 Thread David Mertz
The list comprehensions are not very hard, and are more general. EXCEPT with the limited number of occurrences. We have this for str.replace(..., max=n), and it is useful fairly often. I'm +0.5 on .replace() with that capability. But -1 on .removeall() that adds nothing to an easy listcomp. On

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread MRAB
On 2018-10-21 18:58, Vladimir Filipović wrote: Hi! I originally submitted this as a pull request. Raymond Hettinger suggested it should be given a shakeout in python-ideas first. https://github.com/python/cpython/pull/10018 https://bugs.python.org/issue35034 [snip] FTR, this has been

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Tobias Kohn
it might just be a detail, but Python does not even have single-statement lambdas.  The body of a lambda is an expression yielding a value, not a statement. Function languages (from which the idea of the Lambda in Python probably came from) do not have statements at all.  Something like

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Nathaniel Smith
Hi Vladimir, It's great to see people revisiting these old stdlib tools. Closure tracking is definitely a big point of awkwardness for Queues. In Trio we started with a straight copy of threading.Queue, and this turned out to be a major friction point for users. We just deprecated our version of

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Vladimir Filipović
On Sun, Oct 21, 2018 at 8:45 PM MRAB wrote: > FTR, this has been discussed before: > > [Python-ideas] `__iter__` for queues? > https://mail.python.org/pipermail/python-ideas/2010-January/006711.html Thank you! For the sake of clarity, I want to outline a few differences between that discussion

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Marko Ristin-Kaufmann
Hi, What about writing longer map in pyspark? When I worked with Spark and Scala, it was easy to script a longer chain of transformations in Scala. Does anybody know how that works in Python without multiline lambdas? Cheers Marko Le dim. 21 oct. 2018 à 18:40, Ron Reiter a écrit : >

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Ron Reiter
Just write all your transformations at the top of the file and then write the mapreduce chain at the end. If you need to use closures that depend on each other then it may be a bit more ugly but still feasible to implement. - Ron [image: Facebook] [image:

Re: [Python-ideas] Python Enhancement Proposal for List methods

2018-10-21 Thread Serhiy Storchaka
21.10.18 16:00, Siva Sukumar Reddy пише: I am really new to Python contribution community want to propose below methods for List object. Forgive me if this is not the format to send an email. 1. *list.replace( item_to_be_replaced, new_item )*: which replaces all the occurrences of an element

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Anders Hovmöller
> A powerful general purpose language should not limit itself to one statement > in a closure. Nitpick on language: It doesn't. Lambdas are not the only way to do a closure. It's important to be precise when discussing these things. > Lets add mutli-statement lambdas to python either with

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Andreas Winschu
A def function has to be named. Wheres a lambda expression can be passed anonymously to any other function as an argument. *map(lambda x: x**2, array)* vs *def powers2(x)* * x**2* *map(powers2, array)* Coming up with a name here is not needed, as the operation is expressive enough. Am

[Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Andreas Winschu
There was an extensive discussion about this in the past. https://www.artima.com/weblogs/viewpost.jsp?thread=147358 In the end Guido felt that his effort seems to him like building a Rube Goldberg machine. By looking at the amount of people still stumbling on this issue we definitely feel, that

Re: [Python-ideas] TypeHinting: From variable name to type

2018-10-21 Thread Kyle Lahnakoski
On 2018-10-21 10:44, David Mertz wrote: > On Fri, Oct 19, 2018 at 3:18 AM Thomas Güttler > mailto:guettl...@thomas-guettler.de>> > wrote: > > Now my idea: Per module and/or per file type hinting from variable > name. > Maybe a magic docstring in the __init__.py file: >

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Ron Reiter
Multi-line lambdas may be nice for functional languages, but Python is very imperative in nature and prefers clean syntax over conciseness, which means it will make it REALLY hard to fit with Python. I personally find multi-line lambdas an unreadable abomination. As for some more concrete reasons

[Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Vladimir Filipović
Hi! I originally submitted this as a pull request. Raymond Hettinger suggested it should be given a shakeout in python-ideas first. https://github.com/python/cpython/pull/10018 https://bugs.python.org/issue35034 -- Briefly: Add a close() method to Queue, which should simplify many common

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 3:07 AM Andreas Winschu wrote: > Guido had a hard opinion on this, but i hope the python community does not. A > powerful general purpose language should not limit itself to one statement in > a closure. > Lets add mutli-statement lambdas to python either with just curly

Re: [Python-ideas] Python Enhancement Proposal for List methods

2018-10-21 Thread Terry Reedy
On 10/21/2018 9:00 AM, Siva Sukumar Reddy wrote: I am really new to Python contribution community want to propose below methods for List object. For most classes, there is an infinite number of possible functions that could be made into methods. The Python philosophy is to include as

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread Antoine Pitrou
On Sun, 21 Oct 2018 19:58:05 +0200 Vladimir Filipović wrote: > > To anticipate a couple more possible questions: > > - What would this proposal do about multiple producers/consumers > needing to jointly decide _when_ to close the queue? > > Explicitly nothing. > > The queue's state is either

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Steven D'Aprano
On Sun, Oct 21, 2018 at 11:04:02PM +0200, Vladimir Filipović wrote: > Sometimes I need that callable to be something very simple, but it > technically can't be a lambda because it has a statement in it. > Defining it as a function forces me to give it not only a name, but a > place too. Defining

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Steven D'Aprano
On Sun, Oct 21, 2018 at 06:28:40PM +0200, Andreas Winschu wrote: > A def function has to be named. That's a feature, not a lack. As a general rule of thumb, if the body of a function is complex enough to require multiple statements, it is probably complex enough to require documentation,

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 10:16 AM Terry Reedy wrote: > > On 10/21/2018 12:28 PM, Andreas Winschu wrote > > > A def function has to be named. > > In general, this is a good thing. It often improves tracebacks. > Perhaps more importantly, name facilitate testing and mocking. > > > Wheres a lambda

Re: [Python-ideas] Python Enhancement Proposal for List methods

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 7:58 AM Terry Reedy wrote: > > An indefinite number of in-place removes is a generally a bad idea > unless done carefully. > alist.remove is inherently O(n). > alist.removeall implemented naively would be O(n*n)/ > alist = [x for x in alist if x == old] or > alist = list(x

Re: [Python-ideas] Add closing and iteration to threading.Queue

2018-10-21 Thread MRAB
On 2018-10-21 22:30, Antoine Pitrou wrote: On Sun, 21 Oct 2018 19:58:05 +0200 Vladimir Filipović wrote: To anticipate a couple more possible questions: - What would this proposal do about multiple producers/consumers needing to jointly decide _when_ to close the queue? Explicitly nothing.

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Terry Reedy
On 10/21/2018 12:28 PM, Andreas Winschu wrote A def function has to be named. In general, this is a good thing. It often improves tracebacks. Perhaps more importantly, name facilitate testing and mocking. Wheres a lambda expression can be passed anonymously to any other function as an

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Vladimir Filipović
On Mon, Oct 22, 2018 at 12:52 AM Steven D'Aprano wrote: > > def inc_counter(): > > counter += 1 > > I don't think that's a real working example. > ... > You need to declare counter and sum as global variables. Good catch! None of the examples were real, in the sense of being copied directly

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 8:05 AM Vladimir Filipović wrote: > From one popular library: > > ws = websocket.WebSocketApp( > url, > on_open = (lambda ws: ws.send('subscribe'); conn_counter += 1), > on_message = (lambda ws, msg: print(msg); msg_counter += 1)) > > Because they include

Re: [Python-ideas] TypeHinting: From variable name to type

2018-10-21 Thread Steven D'Aprano
On Sat, Oct 20, 2018 at 07:53:18PM +0200, Thomas Güttler Lists wrote: > > Am 19.10.18 um 12:15 schrieb Steven D'Aprano: > >>One solution is the do typehinting everywhere the veriable gets used. > > > >You shouldn't need to. Your IDE or type-checker should be able to do > >type-inference and