[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread M.-A. Lemburg
On 13.10.2020 03:51, jmwar...@gmail.com wrote: > Of course, again, looking at the requests code shows just how much > boilerplate these things take up. The base class RequestException has some > code in it but then there are 22 derived exceptions. So many classes defined > just to give a name to

[Python-ideas] I'm no longer a co-author of PEP 637 - keyword args in item access

2020-10-13 Thread Jonathan Fine
Hi The following is copied and pasted from https://github.com/python/peps/pull/1650 Stefano Borini === Commit message: PEP 637 I've asked Jonathan Fine to resign as PEP author, and he's agreed to do so. Details in the pull request Pull request comment: Hi Jonathan Thank you for accepti

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Steven D'Aprano
Hi jmward01, I'm not really sure what you mean by "boilerplate heavy objects". *Boilerplate* generally applies to the amount of source code you have to write. I don't think that a two line class (perhaps a couple of extra lines if you give it a docstring) justifies the name "boilerplate":

[Python-ideas] Add _KB, _MB, _GB to numeric literals

2020-10-13 Thread malincns
PEP 515 added underscore to numeric literals, it brings better readability. PEP 515 -- Underscores in Numeric Literals https://www.python.org/dev/peps/pep-0515/ Is it possible to add _KB, _MB, _GB to numeric literals, for example: 200_KB (200*1024) 150_MB (150*1024*1024)

[Python-ideas] Re: Add the brotli & zstandard compression algorithms as modules

2020-10-13 Thread Ma Lin
I wrote a zstd module for stdlib: https://github.com/animalize/cpython/pull/8/files And a PyPI version based on it: PyPI: https://pypi.org/project/pyzstd/ Doc: https://pyzstd.readthedocs.io/en/latest/ If you decide to include it into stdlib, the work can be done in a short

[Python-ideas] New feature

2020-10-13 Thread ankith abhayan
Hi, I would like to request a new feature that allows you to clear the console screen. Like in c++, the CLS function Thanks ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail

[Python-ideas] Re: New feature

2020-10-13 Thread Serhiy Storchaka
13.10.20 09:07, ankith abhayan пише: > I would like to request a new feature that allows you to clear the > console screen. > Like in c++, the CLS function There is no the CLS function in C++. ___ Python-ideas mailing list -- python-ideas@python.org To u

[Python-ideas] Re: Add _KB, _MB, _GB to numeric literals

2020-10-13 Thread Richard Damon
On 10/13/20 1:06 AM, malin...@163.com wrote: > PEP 515 added underscore to numeric literals, it brings better readability. > > PEP 515 -- Underscores in Numeric Literals > https://www.python.org/dev/peps/pep-0515/ > > Is it possible to add _KB, _MB, _GB to numeric literals, for example: > >

[Python-ideas] Re: Add _KB, _MB, _GB to numeric literals

2020-10-13 Thread Serhiy Storchaka
13.10.20 08:06, malin...@163.com пише: > PEP 515 added underscore to numeric literals, it brings better readability. > > PEP 515 -- Underscores in Numeric Literals > https://www.python.org/dev/peps/pep-0515/ > > Is it possible to add _KB, _MB, _GB to numeric literals, for example: > >

[Python-ideas] Re: New feature

2020-10-13 Thread Stestagg
It's not uncommon for C++ tutorials etc, to refer to using: system("cls"); to clear the screen (in windows console environments only). I assume this is what ankith was talking about. The python equivalent would be: import os os.system('cls') or in the repl: _ = os.system('cls'). Note, ipyth

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread jmward01
Steven, Thanks for the responses. In response to your responses: Steven D'Aprano wrote: > Hi jmward01, > I'm not really sure what you mean by "boilerplate heavy objects". > Boilerplate generally applies to the amount of source code you have to > write. I don't think that a two line class (pe

[Python-ideas] Add _KB, _MB, _GB to numeric literals

2020-10-13 Thread Stephen J. Turnbull
malin...@163.com writes: > PEP 515 added underscore to numeric literals, it brings better > readability. > > PEP 515 -- Underscores in Numeric Literals > https://www.python.org/dev/peps/pep-0515/ > > Is it possible to add _KB, _MB, _GB to numeric literals, for example: With a bit

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Ronald Oussoren via Python-ideas
> On 13 Oct 2020, at 16:08, jmwar...@gmail.com wrote: > > Steven, > Thanks for the responses. In response to your responses: > Steven D'Aprano wrote: >> Hi jmward01, >> I'm not really sure what you mean by "boilerplate heavy objects". >> Boilerplate generally applies to the amount of source

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Chris Angelico
On Wed, Oct 14, 2020 at 1:41 AM Ronald Oussoren via Python-ideas wrote: > > #— (python 3.9) > > import dataclasses > > @dataclasses.dataclass > class MyException (Exception): > a : int > b : str > > > try: > raise MyException(a=1, b="hello") > > except MyException as exc: > print(f

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Eric V. Smith
On 10/13/2020 11:09 AM, Chris Angelico wrote: On Wed, Oct 14, 2020 at 1:41 AM Ronald Oussoren via Python-ideas wrote: #— (python 3.9) import dataclasses @dataclasses.dataclass class MyException (Exception): a : int b : str try: raise MyException(a=1, b="hello") except MyExce

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread David Mertz
On Tue, Oct 13, 2020 at 6:18 AM Steven D'Aprano wrote: > I don't think that a two line class (perhaps a couple of extra > lines if you give it a docstring) justifies the name "boilerplate": > > class MySpecialException(Exception): > pass > I think that in 22 years of using Python, I

[Python-ideas] Re: Add _KB, _MB, _GB to numeric literals

2020-10-13 Thread Steve Barnes
I would also suggest taking a look at human friendly https://pypi.org/project/humanfriendly/ which does a lot this for you on the user input/output front. Steve Barnes From: malin...@163.com Sent: 13 October 2020 13:14 To: python-ideas@python.org

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Wes Turner
Exception.args holds the arguments passed to the exception. You could add type checking with dataclass, or you can just access Exception.args or sys.exc_info().args: ```python class Exception2(Exception): pass try: raise Exception2('error str', dict(a='1', b=2)) except Exception2 as e:

[Python-ideas] Re: Add _KB, _MB, _GB to numeric literals

2020-10-13 Thread MRAB
On 2020-10-13 06:06, malin...@163.com wrote: PEP 515 added underscore to numeric literals, it brings better readability. PEP 515 -- Underscores in Numeric Literals https://www.python.org/dev/peps/pep-0515/ Is it possible to add _KB, _MB, _GB to numeric literals, for example: 20

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Brian Allen Vanderburg II via Python-ideas
An issue I have is how to handle typos, whether implemented as a helper or a __getattr__ method: try:     ...     raise ExceptionMaker.color_error("color out of range", color) except ExceptionMaker.colr_error as e:     ... Each __getattr__ would dynamically create/return a new exception class ba

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Christopher Barker
On Tue, Oct 13, 2020 at 9:55 AM David Mertz wrote: > If you really want a snazzy highly-parameterized exception, write it > yourself as a class factory. I won't particularly like the antipattern, > but it's available now. > > if some_bad_thing: > raise ExceptionMaker("BadStuffErrror", detail

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Wes Turner
Compared to conditionals, programming by Exception is slow. You can use the timeit module (or the IPython %timeit magic function) to run comparative performance benchmarks. https://en.wikipedia.org/wiki/Coding_by_exception : https://en.wikipedia.org/wiki/Exception_handling#Criticism : > Excepti

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread David Mertz
On Tue, Oct 13, 2020 at 1:21 PM Christopher Barker wrote: > On Tue, Oct 13, 2020 at 9:55 AM David Mertz wrote: > >> If you really want a snazzy highly-parameterized exception, write it >> yourself as a class factory. I won't particularly like the antipattern, >> but it's available now. >> >> if

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread jmward01
I am not advocating removing exception objects so inheritance is still there if needed. As for the data class and exceptions being just two lines, again, I think that makes my point about the boilerplate for most exceptions. Most of the time they are being created just to have a constant to comp

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Chris Angelico
On Wed, Oct 14, 2020 at 4:48 AM David Mertz wrote: > Well, technically you could memoize calls to ExceptionMaker and have this > work. > > In [11]: try: > ...: raise ExceptionMaker("BadStuffError") > ...: except ExceptionMaker("BadStuffError"): > ...: print("caught") > ...

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread jmward01
I keep using a syntax of . for a reason. It is piggybacking on an already established exception and in reality just providing a sub-type that could easily be used by the except block to determine acceptance. An easy implementation of this still constructs that just has a property of subtype so

[Python-ideas] Re: New feature

2020-10-13 Thread Mike Miller
On 2020-10-13 06:19, Stestagg wrote: For example, the pypi `console` library provides a method: `console.sc.reset()` that behaves similarly to `CLS` on windows and also appears to be fairly reliable cross-platform. Yes, there is more to it than appears at first glance. There is resetting t

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Wes Turner
I think that Exceptions are not designed for message passing: they're deliberately kept very simple because (1) exceptions are slow; and (2) they create scope and resource considerations (as I directly quoted above). Why do you need subclasses for this? dataobj = dict(a=a, b=b, c=c) try: func

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread David Mertz
On Tue, Oct 13, 2020 at 1:56 PM wrote: > I do agree that it is nice to have some ability to type the call more > rigidly, just like a function call. I could see having functions, > optionally, advertise exception calls as possible alternate returns but > this should be just that, optional just to

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread David Mertz
I've heard of this thing called "multiple inheritance" :-). Does that fit into your naming scheme? On Tue, Oct 13, 2020 at 2:03 PM wrote: > I keep using a syntax of . for a reason. > It is piggybacking on an already established exception and in reality just > providing a sub-type that could eas

[Python-ideas] Re: Add the brotli & zstandard compression algorithms as modules

2020-10-13 Thread David Mertz
On Tue, Oct 13, 2020 at 8:16 AM Ma Lin wrote: > Zstd has some advantages: fast speed, multi-threaded compression, > dictionary for small data, etc. IMO it's suitable as a replacement for > zlib, but at this time: > 1, If it is included into stdlib, it will take advantage of the huge > influen

[Python-ideas] Re: New feature

2020-10-13 Thread Guido van Rossum
Can one of the educators on the list explain why this is such a commonly required feature? I literally never feel the need to clear my screen -- but I've seen this requested quite a few times in various forms, often as a bug report "IDLE does not support CLS". I presume that this is a common thing

[Python-ideas] Re: New feature

2020-10-13 Thread Chris Angelico
On Wed, Oct 14, 2020 at 9:38 AM Guido van Rossum wrote: > > Can one of the educators on the list explain why this is such a commonly > required feature? I literally never feel the need to clear my screen -- but > I've seen this requested quite a few times in various forms, often as a bug > repo

[Python-ideas] Re: New feature

2020-10-13 Thread Christopher Barker
I have never had one of my students as for this. Note that clearing the screen (command window these days) IS common -- at least I do ti a lot :-) -- but with a keystroke, not in code. I suspect Chris A is right -- this would be called for in a command-line / menu driven app that wasn't using ful

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Steven D'Aprano
On Tue, Oct 13, 2020 at 12:47:45PM -0400, David Mertz wrote: > On Tue, Oct 13, 2020 at 6:18 AM Steven D'Aprano wrote: > > > I don't think that a two line class (perhaps a couple of extra > > lines if you give it a docstring) justifies the name "boilerplate": > > > > class MySpecialException(E

[Python-ideas] Re: New feature

2020-10-13 Thread David Mertz
I teach a lot. But it's adults, and ones who have at least a little bit of programming experience (perhaps in a different language, but something). I've never had anyone request a "clear screen" command. Of course, I usually use Jupyter notebooks for teaching, so I'm not sure what that would mea

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread David Mertz
On Tue, Oct 13, 2020 at 7:02 PM Steven D'Aprano wrote: > > I DID in the discussion, immediately think of making an exception a > > dataclass, as someone else replied with. I guess if you want cargo in > your > > exception, that's a pretty good way to do it. > > "Cargo", that's an excellent term,

[Python-ideas] Re: New feature

2020-10-13 Thread Steven D'Aprano
On Tue, Oct 13, 2020 at 03:35:58PM -0700, Guido van Rossum wrote: > Can one of the educators on the list explain why this is such a commonly > required feature? I literally never feel the need to clear my screen -- but > I've seen this requested quite a few times in various forms, often as a bug >

[Python-ideas] Re: New feature

2020-10-13 Thread Michael Smith
I occasionally find it useful to clear the screen when doing demos/presentations. I think the case for it is clear (hah) enough based on its long history and presence in many terminal emulators. But then again, the terminals I use and readline support it already, so I don't need python repl to do

[Python-ideas] Re: New feature

2020-10-13 Thread Steven D'Aprano
Hello Ankith, On Tue, Oct 13, 2020 at 11:37:25AM +0530, ankith abhayan wrote: > Hi, > I would like to request a new feature that allows you to clear the console > screen. > Like in c++, the CLS function Can you be specific? I can think of at least three behaviours: 1. Move all existing console

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Greg Ewing
On 14/10/20 6:55 am, jmwar...@gmail.com wrote: Why waste the lines defining them anywhere other than where they are thrown and where they are handled for most of them? If you expect people to catch these exceptions, they need to be documented somewhere. A class statement does a much better job o

[Python-ideas] Re: New feature

2020-10-13 Thread MRAB
On 2020-10-14 00:46, Steven D'Aprano wrote: On Tue, Oct 13, 2020 at 03:35:58PM -0700, Guido van Rossum wrote: Can one of the educators on the list explain why this is such a commonly required feature? I literally never feel the need to clear my screen -- but I've seen this requested quite a few

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Steven D'Aprano
On Tue, Oct 13, 2020 at 02:08:11PM -, jmwar...@gmail.com wrote: > I am not particularly concerned with performance here. I am more > worried about code clarity, boilerplate that de-incentivizes a feature > and hidden values. Okay. > The current exception mechanism encourages passing, > ef

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Wes Turner
https://docs.python.org/3/faq/design.html#how-fast-are-exceptions : """ A try/except block is extremely efficient if no exceptions are raised. Actually catching an exception is expensive. In versions of Python prior to 2.0 it was common to use this idiom: try: value = mydict[key] except KeyEr

[Python-ideas] Re: Exceptions as function calls to kill boilerplate

2020-10-13 Thread Stephen J. Turnbull
jmwar...@gmail.com writes: > I am not particularly concerned with performance here. I am more > worried about code clarity, boilerplate that de-incentivizes a > feature and hidden values. The current exception mechanism > encourages passing, effectively, un-named lists of parameters or > buil