Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Terry Reedy
On 7/26/2018 4:12 AM, Miro Hrončok wrote: Hi, now when dicts are sorted, can we change the repr of collections.OrderedDict to look like dict? I mean from:     OrderedDict([('a', '1'), ('b', '2')]) To:     OrderedDict({'a': '1', 'b': '2'}) I assume the current list-of-tuples repr is ther

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Terry Reedy
On 7/26/2018 1:21 PM, Terry Reedy wrote: On python-idea,  Miro Hrončok asked today whether we can change the OrderedDict repr from, for instance, OrderedDict([('a', '1'), ('b', '2')]) # to OrderedDict({'a': '1', 'b': &#

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-27 Thread Terry Reedy
On 7/26/2018 1:23 PM, Terry Reedy wrote: On 7/26/2018 1:21 PM, Terry Reedy wrote: On python-idea,  Miro Hrončok asked today whether we can change the OrderedDict repr from, for instance, OrderedDict([('a', '1'), ('b', '2')]) # to OrderedDict({'a&#

Re: [Python-ideas] Idea: msgfmt.py and pygettext..py should be -m executable modules

2018-07-30 Thread Terry Reedy
On 7/30/2018 9:43 AM, Petr Viktorin wrote: On Mon, Jul 23, 2018 at 2:16 PM, Miro Hrončok wrote: $ python3 -m gettext.msgfmt +1 Note that this means gettext will need to become a package. Once there is a command line interface, arguments can be supplied to the module, as in python -m g

Re: [Python-ideas] With expressions

2018-08-02 Thread Terry Reedy
On 8/2/2018 7:53 AM, Thomas Nyberg via Python-ideas wrote: On 08/02/2018 12:43 PM, Paul Moore wrote: But if someone wanted to raise a doc bug suggesting that we mention this, I'm not going to bother objecting... Paul I opened a bug here: https://bugs.python.org/issue34319 We can see wh

Re: [Python-ideas] Asynchronous friendly iterables

2018-08-20 Thread Terry Reedy
On 8/20/2018 3:19 AM, Simon De Greve wrote: Hello everyone, I'm quite new working with asyncio and thus maybe missing some things about it, but wouldn't it be quite easier to have some iterables to support async for loops "natively", since asyncio is now part of the Stdlib? One purpose of a

Re: [Python-ideas] Off topic: 'strike a balance' - second language English

2018-08-20 Thread Terry Reedy
On 8/20/2018 5:13 PM, Barry Scott wrote: On 20 Aug 2018, at 17:07, Chris Barker via Python-ideas > wrote: > Summary: I look at the phrase 'strike a balance' in different languages, It is interesting that you picked up on "strike a balance" which has

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-24 Thread Terry Reedy
On 8/24/2018 4:12 AM, Wes Turner wrote: There was a thread about deprecating Tk awhile back. That was an intentionally annoying troll post, not a serious proposal. Please don't refer to it as if it were. asyncio event loop support would be great for real world apps. This is unclear. Any

Re: [Python-ideas] Add Unicode-aware str.reverse() function?

2018-09-08 Thread Terry Reedy
On 9/8/2018 7:33 AM, Paddy3118 wrote: I wrote a blog post nearly a decade ago on extending a Rosetta Code task example to handle the correct reversal of strings with combinin

Re: [Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

2018-09-08 Thread Terry Reedy
On 9/8/2018 7:17 AM, Jonathan Fine wrote: I thank Steve D'Aprano for pointing me to this real-life (although perhaps extreme) code example https://github.com/Tinche/aiofiles/blob/master/aiofiles/threadpool/__init__.py#L17-L37 def open(file, mode='r', buffering=-1, encoding=None, errors=None, ne

Re: [Python-ideas] Retire or reword the "Beautiful is better than ugly" Zen clause

2018-09-13 Thread Terry Reedy
On 9/13/2018 7:34 PM, Tim Peters wrote: I already made clear that I'm opposed to changing it.\ To me, this settles the issues. As author, you own the copyright on your work. The CLA allows revision of contributions, but I don't think that contributed poetry should be treated the same as co

Re: [Python-ideas] Moving to another forum system where

2018-09-20 Thread Terry Reedy
On 9/20/2018 3:38 AM, Hans Polak wrote: I don’t think its unreasonable to point out that the title of this thread is "Moving to another forum". If you want to contribute Python Ideas you *have to* subscribe to the mailing list. Or you can point your mail/news reader to news.gmane.org and 'sub

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-10-07 Thread Terry Reedy
On 9/24/2018 3:46 AM, Marko Ristin-Kaufmann wrote: I am responding to your request "Please do point me to what is not obvious to you". I think some of your claims are not only not obvious, but are wrong. I have read some (probably less than half) of the responses and avoid saying what I know

Re: [Python-ideas] Simplicity of C (was why is design-by-contracts not widely)

2018-10-07 Thread Terry Reedy
On 9/30/2018 2:19 AM, Marko Ristin-Kaufmann wrote: The library name will also need to change. When I started developing it, I was not aware of Java icontract library. It will be probably renamed to "pcontract" or any other suggested better name :) 'icontract' immediatly looks to me like 'inte

Re: [Python-ideas] Better error messages for missing optional stdlib packages

2018-10-07 Thread Terry Reedy
On 10/3/2018 4:29 PM, Marcus Harnisch wrote: When trying to import lzma on one of my machines, I was suprised to get a normal import error like for any other module. What was the traceback and message? Did you get an import error for one of the three imports in lzma.py. I don't know why you

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Terry Reedy
On 10/6/2018 5:00 PM, Nathaniel Smith wrote: On Sat, Oct 6, 2018 at 12:22 AM, Ram Rachum wrote: I'd like to use the re module to parse a long text file, 1GB in size. I wish that the re module could parse a stream, so I wouldn't have to load the whole thing into memory. I'd like to iterate over

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Terry Reedy
On 10/7/2018 12:32 AM, Ram Rachum wrote: Does that mean I'll have to write that character-by-character algorithm? I would not be surprised if you could make use of str.index, which scans at C speed. See my answer to Nathaniel. -- Terry Jan Reedy __

Re: [Python-ideas] Why is design-by-contracts not widely adopted?

2018-10-08 Thread Terry Reedy
On 10/8/2018 10:26 AM, Steven D'Aprano wrote: On Sun, Oct 07, 2018 at 04:24:58PM -0400, Terry Reedy wrote: https://www.win.tue.nl/~wstomv/edu/2ip30/references/design-by-contract/index.html defines contracts as "precise (legally unambiguous) specifications" (5.2 Business

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 method

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Terry Reedy
On 10/21/2018 12:06 PM, Andreas Winschu wrote: There was an extensive discussion about this in the past. https://www.artima.com/weblogs/viewpost.jsp?thread=147358 And perhaps 20 other threads, now including this one. In the end Guido felt that his effort seems to him like building a Rube Go

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 arg

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

2018-10-21 Thread Terry Reedy
On 10/21/2018 2:42 PM, MRAB wrote: 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

Re: [Python-ideas] Fix documentation for __instancecheck__

2018-10-27 Thread Terry Reedy
On 10/27/2018 2:53 PM, Joy Diamond wrote: Chris, Yes, the following works: """ (Note that any object `x` is always considered to be an instance of `type(x)`, and this cannot be overridden.) """ Open a doc issue on bugs.python.org with the problem, motivation, and proposed solution and it shou

Re: [Python-ideas] Decide if `type.__subclasses__` is part of future Python or not

2018-10-29 Thread Terry Reedy
On 10/29/2018 2:25 PM, Joy Diamond wrote: Thanks, Storchaka for finding the documentation. Though it is really annoying I could not find it with a google search... Next time, start with our excellent index, which includes a page for words starting with '_'. There is another page for symbols,

Re: [Python-ideas] __len__() for map()

2018-11-27 Thread Terry Reedy
On 11/26/2018 4:29 PM, Kale Kundert wrote: I just ran into the following behavior, and found it surprising: >>> len(map(float, [1,2,3])) TypeError: object of type 'map' has no len() I understand that map() could be given an infinite sequence and therefore might not always have a length. The

Re: [Python-ideas] __len__() for map()

2018-11-28 Thread Terry Reedy
On 11/28/2018 9:27 AM, E. Madison Bray wrote: On Mon, Nov 26, 2018 at 10:35 PM Kale Kundert wrote: I just ran into the following behavior, and found it surprising: len(map(float, [1,2,3])) TypeError: object of type 'map' has no len() I understand that map() could be given an infinite seque

Re: [Python-ideas] __len__() for map()

2018-11-29 Thread Terry Reedy
On 11/28/2018 5:27 PM, Steven D'Aprano wrote: On Wed, Nov 28, 2018 at 02:53:50PM -0500, Terry Reedy wrote: One of the guidelines in the Zen of Python is "Special cases aren't special enough to break the rules." This proposal claims that the Python 3 built-in iterator class

Re: [Python-ideas] __len__() for map()

2018-11-29 Thread Terry Reedy
On 11/29/2018 6:13 AM, E. Madison Bray wrote: On Wed, Nov 28, 2018 at 8:54 PM Terry Reedy wrote: The CPython map() implementation already carries this data on it as "func" and "iters" members in its struct. It's trivial to expose those to Python as ".funcs"

Re: [Python-ideas] __len__() for map()

2018-11-29 Thread Terry Reedy
On 11/29/2018 8:16 AM, E. Madison Bray wrote: Okay, let's keep it simple: m = map(str, [1, 2, 3]) len_of_m = None if len(m.iters) == 1 and isinstance(m.iters[0], Sized): len_of_m = len(m.iters[0]) As I have noted before, the existing sized collection __length_hint__ methods (properly) r

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-11 Thread Terry Reedy
On 12/1/2018 8:07 PM, Greg Ewing wrote: Steven D'Aprano wrote: After defining a separate iterable mapview sequence class For backwards compatibilty reasons, we can't just make map() work like this, because that's a change in behaviour. Actually, I think it's possible to get the best of both

Re: [Python-ideas] __len__() for map()

2018-12-11 Thread Terry Reedy
On 12/1/2018 2:08 PM, Steven D'Aprano wrote: This proof of concept wrapper class could have been written any time since Python 1.5 or earlier: class lazymap: def __init__(self, function, sequence): One could now add at the top of the file from collections.abc import Sequence and h

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-11 Thread Terry Reedy
On 12/11/2018 6:48 AM, E. Madison Bray wrote: The idea would be to now enhance the existing built-ins to restore at least some previously lost assumptions, at least in the relevant cases. To give an analogy, Python 3.0 replaced range() with (effectively) xrange(). This broken a lot of assumpt

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-11 Thread Terry Reedy
On 12/11/2018 12:01 PM, Chris Barker - NOAA Federal via Python-ideas wrote: Perhaps I got confused by the early part of this discussion. My point was that there is no “map-like” object at the Python level. (That is no Map abc). Py2’s map produced a sequence. Py3’s map produced an iterable. So

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-11 Thread Terry Reedy
On 12/11/2018 6:50 PM, Greg Ewing wrote: I'm not necessarily saying this *should* be done, just pointing out that it's a possible strategy for migrating map() from an iterator to a view, if we want to do that. Python has list and list_iterator, tuple and tuple_iterator, set and set_iterator,

Re: [Python-ideas] tkinter: time for round buttons?

2019-01-16 Thread Terry Reedy
On 1/16/2019 11:11 AM, Abdur-Rahmaan Janhangeer wrote: without starting a should we ban tkinter discussion, Then don't bring up such an idea. i'd like to propose that we add rounded corners buttons. This is out-of-scope for python-ideas. 'Tkinter' abbreviates 'Tk interface'. It provides

Re: [Python-ideas] tkinter: time for round buttons?

2019-01-16 Thread Terry Reedy
On 1/16/2019 7:26 PM, Abdur-Rahmaan Janhangeer wrote: let us say i'm a novice user, for me py's gui is such. if on Mac it gives rounded corners but on others no, it's pretty unpredictable. and if it does have roundedness but you can't control it then it's no good It is using native widgits of

Re: [Python-ideas] Add list.join() please

2019-01-29 Thread Terry Reedy
On 1/28/2019 8:40 PM, Jamesie Pic wrote: > 0. os.path.join takes *args Since at least 1 path is required, the signature is join(path, *paths). I presume that this is the Python version of the Unix version of the system call that it wraps.. The hidden argument is os.sep. It is equivalent to

Re: [Python-ideas] Add list.join() please

2019-01-29 Thread Terry Reedy
On 1/29/2019 7:12 PM, MRAB wrote: On 2019-01-29 23:30, Terry Reedy wrote: On 1/28/2019 8:40 PM, Jamesie Pic wrote:   > 0. os.path.join takes *args Since at least 1 path is required, the signature is join(path, *paths). I presume that this is the Python version of the Unix version of

Re: [Python-ideas] AMEND PEP-8 TO DISCOURAGE ALL CAPS

2019-01-30 Thread Terry Reedy
On 1/30/2019 6:41 PM, Abe Dillon wrote: I think continued discussion is pretty useless. 1. Most everything relevant has been said, likely more than once, and 2. The required core-developer support does not exist. PEP 8 was written by Guido with input from other core developers. As Chris

Re: [Python-ideas] Add list.join() please

2019-01-31 Thread Terry Reedy
On 1/31/2019 12:51 PM, Chris Barker via Python-ideas wrote: I do a lot of numerical programming, and used to use MATLAB and now numpy a lot. So I am very used to "vectorization" -- i.e. having operations that work on a whole collection of items at once. Example: a_numpy_array * 5 multiplies

Re: [Python-ideas] Option of running shell/console commands inside the REPL

2019-02-01 Thread Terry Reedy
On 2/1/2019 1:50 PM, James Lu wrote: It’s difficult to learn anything with a body (such as a loop or a class or a function) with the built in REPL because you can’t edit lines you’ve already written. I presume you mean that it is 'difficult to learn about compound statements and multiline si

Re: [Python-ideas] Option of running shell/console commands inside the REPL

2019-02-01 Thread Terry Reedy
On 2/1/2019 9:24 AM, Ken Hilton wrote: Hi, As a workaround/alternative, you can just do     >>> import os     >>> os.system('dir') For repeated use within and between sessions, put 'from os import system as oss' in a startup file. Then one only needs "oss('dir')". Note that 'dir' only w

Re: [Python-ideas] How do ideas on this mailing list turn into features?

2019-02-01 Thread Terry Reedy
On 2/1/2019 1:10 PM, James Lu wrote: How do ideas on this mailing list turn into features? What is the typical roadmap? Can this process be documented somewhere? Ultimately, one or more people write Pull Request, usually containing new tests, that passes all tests. Then a Core Developer with

Re: [Python-ideas] Option of running shell/console commands inside the REPL

2019-02-01 Thread Terry Reedy
On 2/1/2019 3:31 PM, Oleg Broytman wrote: Python REPL is missing the following batteries: That is why, on Windows, I nearly always use IDLE. * Persistent history; IDLE's Shell history persists across restarts (which are not available is the standard shell). I cannot remember wanting hist

Re: [Python-ideas] Option of running shell/console commands inside the REPL

2019-02-02 Thread Terry Reedy
On 2/2/2019 8:13 AM, Oleg Broytman wrote: On Fri, Feb 01, 2019 at 08:40:22PM -0500, Terry Reedy wrote: On 2/1/2019 3:31 PM, Oleg Broytman wrote: Python REPL is missing the following batteries: That is why, on Windows, I nearly always use IDLE. I believe this was Chris, not me

Re: [Python-ideas] Clearer communication

2019-02-03 Thread Terry Reedy
On 2/3/2019 12:44 PM, James Lu wrote: On Feb 2, 2019, at 7:17 PM, Steven D'Aprano wrote: It has become unfashionable to link to this, because it is allegedly too elitest and unfriendly and not welcoming enough, but I still think it is extremely valuable: http://www.catb.org/esr/faqs/smart-q

Re: [Python-ideas] What factors led Guido to quit?

2019-02-03 Thread Terry Reedy
On 2/2/2019 11:04 AM, James Lu wrote: What factors led Guido to quit? Guido resigned as 'Enhancement Czar'. He wrote what he want to say publicly as to why in his message to the committers list. Speculating beyond that strikes me as rude. He did not resign as President of the PSF nor as act

Re: [Python-ideas] Clearer communication

2019-02-03 Thread Terry Reedy
On 2/2/2019 10:59 AM, James Lu wrote: I think we need to ... have some way of knowing that Python committees are python committers. It’s really difficult to know how well your proposal is doing without having this. That has occurred to me also. If two or three core developers respond negati

Re: [Python-ideas] PEP 8 update on line length

2019-02-18 Thread Terry Reedy
On 2/18/2019 11:37 PM, Simon wrote: Hello, I'd like to propose an update to PEP8. Indeed, the 80 characters per line guideline is, I feel, outdated. Strictly speaking, PEP8 applies only to CPython stdlib code. Please read the introduction. Adapt it as you will for your code. I understand

Re: [Python-ideas] unittest: 0 tests pass means failure of the testsuite

2019-03-06 Thread Terry Reedy
On 3/6/2019 3:12 PM, Matěj Cepl wrote: Hi, I am a lead maintainer of Python packages in OpenSUSE and I can see the pattern of many packagers adding blindly python setup.py test to %check section of our SPEC file. I am not familiar with setup.py, so I don't know how this affects the pre

Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs

2019-03-07 Thread Terry Reedy
On 3/7/2019 8:56 AM, Steven D'Aprano wrote: On Thu, Mar 07, 2019 at 08:10:20AM -0500, James Lu wrote: Rationale: When I use a search engine to google a Python question, I frequently get a link to a page of the Python 2.7 documentation that shows before the Python 3 documentation link. This is

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-15 Thread Terry Reedy
rticular change happened. https://mail.python.org/pipermail/python-ideas/2009-April/003897.html You proposed that in April 2009, but there was nothing added to the bug tracker for 18 months until it was finally added by Terry Reedy in Actually, I opened the tracker issue with a succinct message, after

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Terry Reedy
I agree with Guido's general comments on operators. Modern arithmetic and algebra really took off with the introduction of operators. On the other hand, I have seen condensed blocks of 'higher math', dense with operators, that I could hardly read, and that reminded me of API or Perl. On 3/15

Re: [Python-ideas] Why operators are useful

2019-03-16 Thread Terry Reedy
On 3/16/2019 8:01 AM, Gustavo Carneiro wrote: On Sat, 16 Mar 2019 at 10:33, Steven D'Aprano > wrote: The question this PEP is trying to answer is not "can we support every use-case imaginable for a merge operator?" but "can we support the most typical u

Re: [Python-ideas] dict.merge(d1, d2, ...) (Counter proposal for PEP 584)

2019-03-21 Thread Terry Reedy
On 3/21/2019 12:11 PM, Guido van Rossum wrote: On Thu, Mar 21, 2019 at 7:45 AM Antoine Pitrou One should also be able to write `d = dict.merge(d1, d2, ...)` If dict merging is important enough to get a new spelling, then I think this proposal is the best: explicit, unambiguous, imm

Re: [Python-ideas] dict.merge(d1, d2, ...) (Counter proposal for PEP 584)

2019-03-22 Thread Terry Reedy
On 3/22/2019 12:53 AM, Steven D'Aprano wrote: On Thu, Mar 21, 2019 at 09:36:20PM -0400, Terry Reedy wrote: I counted what I believe to be 10 instances of copy-update in the top level of /lib. Do either of you consider this to be enough that any addition would be worthwhile. I think y

Re: [Python-ideas] Why not ['a','b','c'].join(',') ?

2019-03-23 Thread Terry Reedy
On 3/23/2019 7:35 PM, Juancarlo Añez wrote: I know it has been discussed endlessly, So please read any of the endless discussions either on this list or python-list. I myself have answered multiple times. -- Terry Jan Reedy ___ Python-ideas mail

Re: [Python-ideas] New explicit methods to trim strings

2019-03-25 Thread Terry Reedy
On 3/25/2019 6:22 AM, Jonathan Fine wrote: Instead of naming these operations, we could use '+' and '-', with semantics:     # Set the values of the variables.     >>> a = 'hello '     >>> b = 'world'     >>> c = 'hello world'     # Some values between the variables.     >>> a + b == c

Re: [Python-ideas] New explicit methods to trim strings

2019-03-25 Thread Terry Reedy
On 3/25/2019 10:55 AM, David Mertz wrote: All of this would be well served by a 3rd party library on PyPI. Strings already have plenty of methods (probably too many).  Having `stringtools` would be nice to import a bunch of simple functions from. I agree. -- Terry Jan Reedy ___

Re: [Python-ideas] Built-in parsing library

2019-04-01 Thread Terry Reedy
On 4/1/2019 1:14 AM, Guido van Rossum wrote: We do have a parser generator in the standard library: https://github.com/python/cpython/tree/master/Lib/lib2to3/pgen2 It is effectively undocumented and by inference discouraged from use. The entry for lib2to3 in the 2to3 doc: https://docs.python.

Re: [Python-ideas] Sorted lists

2019-04-07 Thread Terry Reedy
On 4/7/2019 10:32 PM, Steven D'Aprano wrote: There are quite a few important algorithms which require lists to be sorted. For example, the bisect module, and for statistics median and other quantiles. Sorting a list is potentially expensive: while Timsort is very efficient, it is still ultimatel

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Terry Reedy
On 4/8/2019 5:40 AM, Steven D'Aprano wrote: On Mon, Apr 08, 2019 at 07:44:41AM +0100, Alex Chamberlain wrote: I think a better abstraction for a sorted list is a new class, which implements the Sequence protocol (and hence can be used in a lot of existing list contexts), but only exposed mutati

Re: [Python-ideas] Sorted lists

2019-04-08 Thread Terry Reedy
On 4/8/2019 4:48 PM, Barry Scott wrote: On 8 Apr 2019, at 19:37, Terry Reedy wrote: On 4/8/2019 5:40 AM, Steven D'Aprano wrote: On Mon, Apr 08, 2019 at 07:44:41AM +0100, Alex Chamberlain wrote: I think a better abstraction for a sorted list is a new class, which implements the Seq

Re: [Python-ideas] Logical tracebacks

2019-04-15 Thread Terry Reedy
On 4/15/2019 4:07 PM, Antoine Pitrou wrote: Hello, I apologize because I'm only going to throw a very vague idea and I don't currently have time or motivation to explore it myself. But I think it may prove interesting for other people and perhaps spur some concrete actionable proposal. With t

Re: [Python-ideas] Catching the return value of a generator at the end of a for loop

2019-04-16 Thread Terry Reedy
On 4/16/2019 4:54 PM, Stefano Borini wrote: given the following code def g(): yield 2 yield 3 return 6 for x in g(): print(x) The output is obviously 2 3 As far as I know, there is currently no way to capture the StopIteration value when the generator is used in a for loop

Re: [Python-ideas] What are the strong use cases for str.rindex()?

2019-04-23 Thread Terry Reedy
On 4/23/2019 2:44 AM, 林自均 wrote: Hi all, I found that there are str.index() and str.rindex(), but there is only list.index() and no list.rindex(). str.index and list.index are related but not the same. The consistency argument is better applied to find-rfind, index-rindex, partition-rparti

Re: [Python-ideas] contains_any_in and contains_all_in

2019-04-23 Thread Terry Reedy
On 4/23/2019 4:39 PM, João Matos wrote: Hello, If we want to check if a string contains any/all of several other strings we have to use several or/and conditions or any/all. For any: |if ('string1' in master_string or 'string2' in master_string     or 'string3' in master_string): or ifan

Re: [Python-ideas] contains_any_in and contains_all_in

2019-04-24 Thread Terry Reedy
On 4/24/2019 12:50 PM, João Matos wrote: The objective of the proposal is to increase readability. Relational expressions are powerful and flexible and yes, people find them hard to read until they really learn the sublanguage. The solution is to isolate application-specific regexes in funct

Re: [Python-ideas] What are the strong use cases for str.rindex()?

2019-04-25 Thread Terry Reedy
On 4/25/2019 7:12 PM, Greg Ewing wrote: Steven D'Aprano wrote: I too often forget that reverse() returns an iterator, I presume you mean reversed(). list.reverse() is a list That seems like a mistake. Shouldn't it return a view? RL = reversed(somelist) is already partly view-like. The nt

Re: [Python-ideas] Break multiple loop levels

2019-05-11 Thread Terry Reedy
On 5/11/2019 1:20 PM, haael wrote: Python allows for breaking out from a loop through 'break' and 'continue' keywords. It would be nice if it was possible to break many loop levels using one command. I propose two constructions for that: break break break break break break ... continue bre

Re: [Python-ideas] Passing positional arguments as keyword arguments (to provide function arguments out of order)

2019-05-16 Thread Terry Reedy
On 5/16/2019 8:23 AM, Anders Hovmöller wrote: On 16 May 2019, at 08:50, Serhiy Storchaka wrote: Writing the code that parses args is errorprone and inefficient. There are also other rationales of PEP 570. I've read it. It is unconvincing to me. That's fine. Coredevs don't always agree 10

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-18 Thread Terry Reedy
On 5/18/2019 8:13 PM, Yonatan Zunger wrote: Hi everyone, I'd like to bounce this proposal off everyone and see if it's worth formulating as a PEP. I haven't found any prior discussion of it, but as we all know, searches can easily miss things, so if this is old hat please LMK. *Summary: *Th

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Terry Reedy
On 5/18/2019 10:44 PM, Yonatan Zunger wrote: Terry, let me make sure I'm understanding your responses. (1) Only certain things should be CM's, and those things should be explicitly denoted as such. Thinking about the first one, the purpose of the context manager protocol is to allow cleanup

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Terry Reedy
On 5/18/2019 10:01 PM, Chris Angelico wrote: 2) Redefine the 'with' block or create a new syntactic form such that the variable actually creates a subscope. That way, at the end of the block, the name would revert to its former meaning. x = 1 with local 2 as x: print(x) # 2 print(x) # 1

Re: [Python-ideas] Proposal: Allowing any variable to be used in a 'with... as...' expression

2019-05-19 Thread Terry Reedy
On 5/19/2019 3:00 PM, Chris Angelico wrote: On Mon, May 20, 2019 at 4:46 AM Terry Reedy wrote: On 5/18/2019 10:01 PM, Chris Angelico wrote: 2) Redefine the 'with' block or create a new syntactic form such that the variable actually creates a subscope. That way, at the end of the

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-24 Thread Terry Reedy
On 5/24/2019 8:50 AM, Yanghao Hua wrote: for instance, I explained already but here again: you will need to have "this_signal <<= (that_signal << 4) + something, and next line you should be able to write this_signal <<= 4 bit, where all arithmetic operation still have to be kept. Otherwise it m

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-25 Thread Terry Reedy
On 5/24/2019 4:25 PM, Yanghao Hua wrote: On Fri, May 24, 2019 at 5:45 PM Terry Reedy wrote: What I understand is that you are doing discrete-time hardware simulation and that you need a operator that will schedule future assigments to int-like objects. Have you considered using '@'

Re: [Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

2019-05-25 Thread Terry Reedy
On 5/25/2019 3:09 PM, Yanghao Hua wrote: @= has all the same issues like <<= or >>=, No, it does not in that you are basically sacrificing a well known number operation because @= is not a number operation at all. I admit this (@=) is a much rarer case, It is a different case. but wh

Re: [Python-ideas] `if-unless` expressions in Python

2019-06-03 Thread Terry Reedy
On 6/3/2019 8:57 PM, James Lu wrote: `if-unless` expressions in Python     if condition1 expr unless condition2 is an expression that roughly reduces to     expr if condition1 and not condition2 else EMPTY An expression MUST evaluate to a value. EMPTY is spelled None in Python. No need

Re: [Python-ideas] Assign-in-place operator

2019-06-04 Thread Terry Reedy
On 6/4/2019 6:47 AM, Jeroen Demeyer wrote: I'd like to get rid of all the signal and HDL stuff (whatever that means) in this thread, so I think what the original poster really wants is an "assign in place" operator. Basically, something like += or *= but without the arithmetic. I believe that

Re: [Python-ideas] Let’s make escaping in f-literals impossible

2016-08-30 Thread Terry Reedy
On 8/29/2016 5:33 PM, Eric V. Smith wrote: On 8/29/2016 5:26 PM, Ethan Furman wrote: On 08/29/2016 02:16 PM, Eric V. Smith wrote: I've been looking at this, and I agree it's the best thing to do, for now (and possibly forever). I'm just not convinced I can get it done before alpha 1. Isn't

Re: [Python-ideas] PEP 530: Asynchronous Comprehensions

2016-09-06 Thread Terry Reedy
On 9/6/2016 2:54 PM, Sven R. Kunze wrote: PS: Nick, I noted that while replying, my mail client made me responding to you and the list as cc. For Thunderbird, this is normal behavior. I suspect you would find the same if your tried 'replay all' to multiple messages. > Is there something wr

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-17 Thread Terry Reedy
On 9/17/2016 6:51 AM, João Matos wrote: Hello, I would like to suggest adding a clear command (not function) to Python. It's simple purpose would be to clear the REPL screen, leaving the >>> prompt at the top left of the screen. This is something very basic but also very useful for newbies lear

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Terry Reedy
On 9/19/2016 4:31 AM, Paul Moore wrote: shutil.get_terminal_size() is available on all platforms. On windows, it works with Command Prompt and PowerShell but fails in IDLE, as it must. In the absence of knowledge, it guesses the default of 80 x 24 (as documented). AFAIK, there is no way wh

Re: [Python-ideas] Make partial a built-in

2016-09-20 Thread Terry Reedy
On 9/20/2016 11:51 AM, Guido van Rossum wrote: We seem to have fundamentally different ideas of what sort of code is most readable. The alternative to partial is usually a lambda, Partial and lambda are different in that partial captures variable values immediately, whereas lambda does not, u

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-20 Thread Terry Reedy
On 9/20/2016 9:31 AM, Steven D'Aprano wrote: On Mon, Sep 19, 2016 at 06:18:38AM -0400, Terry Reedy wrote: On 9/19/2016 4:31 AM, Paul Moore wrote: shutil.get_terminal_size() is available on all platforms. On windows, it works with Command Prompt and PowerShell but fails in IDLE, as it

Re: [Python-ideas] Delay evaluation of annotations

2016-09-22 Thread Terry Reedy
On 9/22/2016 10:54 PM, Chris Angelico wrote: On Fri, Sep 23, 2016 at 12:35 PM, Steven D'Aprano wrote: The straight-forward and simple way of writing a recursive spam() function surprises beginners, but they might go years or their entire career without running into a situation where they are ca

Re: [Python-ideas] PEP8 dictionary indenting addition

2016-10-11 Thread Terry Reedy
On 10/11/2016 12:08 PM, Ryan Gonzalez wrote: On Oct 11, 2016 10:40 AM, "Erik Bray" mailto:[email protected]>> wrote: On Sun, Oct 9, 2016 at 2:25 AM, Steven D'Aprano mailto:[email protected]>> wrote: > On Sat, Oct 08, 2016 at 09:26:13PM +0200, Jelte Fennema wrote: >> I have an idea to im

Re: [Python-ideas] INSANE FLOAT PERFORMANCE!!!

2016-10-11 Thread Terry Reedy
On 10/11/2016 2:30 PM, Paul Moore wrote: On 11 October 2016 at 17:49, Nick Coghlan wrote: On 12 October 2016 at 02:16, Elliot Gorokhovsky wrote: So I thought, wow, this will give some nice numbers! But I underestimated the power of this optimization. You have no idea. It's crazy. This is just

Re: [Python-ideas] Add a method to get the subset of a dictionnary.

2016-10-12 Thread Terry Reedy
On 10/12/2016 12:06 PM, Enguerrand Pelletier wrote: Hi all, It always bothered me to write something like this when i want to strip keys from a dictionnary in Python: a = {"foo": 1, "bar": 2, "baz": 3, "foobar": 42} interesting_keys = ["foo", "bar", "baz"] If the keys are hashable, this shoul

Re: [Python-ideas] Add a method to get the subset of a dictionnary.

2016-10-12 Thread Terry Reedy
On 10/12/2016 5:52 PM, Terry Reedy wrote: On 10/12/2016 12:06 PM, Enguerrand Pelletier wrote: b = {k, v for k,v in a.items() if k in interesting_keys} Test code before posting. The above is a set comprehension creating a set of tupes. I should have followed my own advice. The above is a

Re: [Python-ideas] INSANE FLOAT PERFORMANCE!!!

2016-10-12 Thread Terry Reedy
On 10/12/2016 5:57 PM, Elliot Gorokhovsky wrote: On Wed, Oct 12, 2016 at 3:51 PM Nathaniel Smith mailto:[email protected]>> wrote: But this isn't relevant to Python's str, because Python's str never uses UTF-8. Really? I thought in python 3, strings are all unicode... They are ... so

Re: [Python-ideas] PEP8 dictionary indenting addition

2016-10-12 Thread Terry Reedy
On 10/12/2016 1:40 PM, Stephen J. Turnbull wrote: Steven D'Aprano writes: > I learned the hard way that if I don't put the breaking space at > the beginning of the next fragment, I probably wouldn't put it at > the end of the previous fragment either. The converse applies in my case, so that

Re: [Python-ideas] Deterministic iterator cleanup

2016-10-19 Thread Terry Reedy
On 10/19/2016 12:38 AM, Nathaniel Smith wrote: I'd like to propose that Python's iterator protocol be enhanced to add a first-class notion of completion / cleanup. With respect the the standard iterator protocol, a very solid -1 from me. (I leave commenting specifically on __aiterclose__ to

Re: [Python-ideas] Smart/Curly Quote Marks and cPython

2016-10-22 Thread Terry Reedy
On 10/22/2016 3:16 AM, Steven D'Aprano wrote: I would be happy to see improved error messages for smart quotes: py> s = ‘abcd’ File "", line 1 s = ‘abcd’ ^ SyntaxError: invalid character in identifier The above *is* the improved (and regressed) 3.6 version ;-) In 3.5.2 (o

Re: [Python-ideas] Smart/Curly Quote Marks and cPython

2016-10-22 Thread Terry Reedy
On 10/22/2016 12:32 PM, Nick Coghlan wrote: On 22 October 2016 at 17:36, Ryan Birmingham wrote: Per the comments in this thread, I believe that a better error message for this case would be a reasonable way to fix the use case around this issue. It can be difficult to notice that your quotes ar

Re: [Python-ideas] A better interactive prompt

2016-10-28 Thread Terry Reedy
On 10/25/2016 5:13 PM, Paul Moore wrote: The natural unit of interaction at the command line is the single line. To the extent that (for example) fixing a mistake in a multi-line construct at the command line is a real pain. Try IDLE. The unit of interaction is the statement. One writes, edi

Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-28 Thread Terry Reedy
On 10/26/2016 6:17 PM, Chris Barker wrote: I"ve lost track of what (If anything) is actually being proposed here... so I"m going to try a quick summary: 1) an easy way to spell "remove all the characters other than these" In other words, 'only keep these'. We already have easy ways to create

Re: [Python-ideas] Generator-based context managers can't skip __exit__

2016-11-06 Thread Terry Reedy
On 11/6/2016 2:18 AM, Ram Rachum wrote: Well, you think it's weird that I want a `finally` clause to not be called in some circumstances. Do you think it's equally weird to want an `__exit__` method that is not called in some circumstances? Without a deeper understanding of why you want to do

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Terry Reedy
On 11/28/2016 11:38 AM, Guido van Rossum wrote: Overall I think this is a good idea. I have one hit: It seems that there are two possible strategies for searching the .missing.py file: 1. (Currently in the PEP) search it at the same time as the .py file when walking along sys.path. - Pro: pre

  1   2   3   >