Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Ned Batchelder
On 1/31/17 2:13 AM, Roberto Martínez wrote: > Hi, > > I find this type of code quite often: > > class MyOverridedClass(MyBaseClass): > def mymethod(self, foo, **kwargs): > # Do something > return super().mymethod(**kwargs) > > What about creating a decorator to call super()

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

2016-10-27 Thread Ned Batchelder
On 10/27/16 10:12 AM, Mikhail V wrote: > On 27 October 2016 at 06:24, Chris Angelico wrote: > >> Unicode is here to stay. > Congratulations. And chillax. I don't blog anywhere, have no time for that. It's not clear at all where this thread is going, but it's clear to me that it

Re: [Python-ideas] please try to keep things civil

2016-10-21 Thread Ned Batchelder
On 10/21/16 3:13 PM, Mark Lawrence via Python-ideas wrote: > On 17/10/2016 19:29, Brett Cannon wrote: >> >> >> On Sun, 16 Oct 2016 at 09:39 Mark Lawrence via Python-ideas >> > > wrote: >> >> On 16/10/2016 16:41, Mariatta Wijaya wrote:

Re: [Python-ideas] Proposal for default character representation

2016-10-13 Thread Ned Batchelder
On 10/13/16 2:42 AM, Mikhail V wrote: > On 13 October 2016 at 08:02, Greg Ewing wrote: >> Mikhail V wrote: >>> Consider unicode table as an array with glyphs. >> >> You mean like this one? >> >> http://unicode-table.com/en/ >> >> Unless I've miscounted, that one has

Re: [Python-ideas] How to respond to trolling

2017-01-10 Thread Ned Batchelder
On 1/10/17 10:43 AM, Ivan Levkivskyi wrote: > On 10 January 2017 at 16:29, Guido van Rossum > wrote: > > I think a much more effective response would have been a > resounding silence. > > > I agree. > I don't like to use the term "trolling"

Re: [Python-ideas] Python Reviewed

2017-01-09 Thread Ned Batchelder
On 1/9/17 8:31 AM, Chris Angelico wrote: > On Mon, Jan 9, 2017 at 10:25 PM, Simon Lovell wrote: >> Python Reviewed >> >> Having used a lot of languages a little bit and not finding satisfactory >> answers to these in some cases often asked questions, I thought I'd join >>

Re: [Python-ideas] incremental hashing in __hash__

2016-12-28 Thread Ned Batchelder
On 12/28/16 12:27 PM, j...@math.brown.edu wrote: > On Wed, Dec 28, 2016 at 11:48 AM, Ned Batchelder > <n...@nedbatchelder.com <mailto:n...@nedbatchelder.com>> wrote: > > You can write a simple function to use hash iteratively to hash > the entire stream in con

Re: [Python-ideas] Argparse argument deprecation

2017-08-09 Thread Ned Batchelder
On 8/9/17 3:56 AM, Tarek Ziadé wrote: > Hey, > > I don't think there's any helper to deprecate an argument in argparse > > Let's say you have a --foo option in your CLI and want to deprecate it > in the next release before you completely remove it later. > > My first though on how to do this by

Re: [Python-ideas] Argparse argument deprecation

2017-08-09 Thread Ned Batchelder
you would not have automatically generated a "usage" message > or a "--help" command. > > Following your definition, those are not parsing. But there are here, > because we all end up coding them anyway. > > Le 09/08/2017 à 11:50, Ned Batchelder a écrit : >

Re: [Python-ideas] "any" and "all" support multiple arguments

2017-08-01 Thread Ned Batchelder
I find it frustrating that they always return booleans. It would be more useful if any() returned the first true value it finds. This seems like a backward-compatible-enough change to me... :) --Ned. On 8/1/17 9:32 AM, Markus Meskanen wrote: > I'd be more interested in supporting the "key"

Re: [Python-ideas] Make map() better

2017-09-15 Thread Ned Batchelder
On 9/15/17 2:03 PM, Jason H wrote: It's just not liked by the greybeards, which I can appreciate. "here's some new punk kid, get off my lawn!" type of mentality. Dunning-Kruger, etc. I'm not sure if you meant this tongue-in-cheek or not.  The main problem with your proposal is that it would

Re: [Python-ideas] A PEP to define basical metric which allows to guarantee minimal code quality

2017-09-20 Thread Ned Batchelder
On 9/20/17 8:37 PM, Chris Barker - NOAA Federal wrote: You can define metrics. But as to what they mean? Well that is the question. One big problem with metrics is that we tend to measure what we know how to measure -- generally really not the most useful metric... As for some kind of PEP or

Re: [Python-ideas] Changes to the existing optimization levels

2017-09-29 Thread Ned Batchelder
On 9/28/17 2:48 PM, Diana Clarke wrote: Hi folks: I was recently looking for an entry-level cpython task to work on in my spare time and plucked this off of someone's TODO list. "Make optimizations more fine-grained than just -O and -OO" There are currently three supported optimization

Re: [Python-ideas] Please consider adding context manager versions of setUp/tearDown to unittest.TestCase

2017-08-21 Thread Ned Batchelder
On 8/20/17 9:32 PM, Neil Girdhar wrote: > This question describes an example of the > problem: > https://stackoverflow.com/questions/8416208/in-python-is-there-a-good-idiom-for-using-context-managers-in-setup-teardown. > You want to invoke a context manager in your setup/tearing-down, but > the

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Ned Batchelder
On 11/27/17 9:12 PM, Ivan Pozdeev via Python-ideas wrote: The `assert' statment was created the same as in previous languages like C/C++: a check to only do in debug mode, when you can't yet trust your code to manage and pass around internal data correctly. Examples are array bounds and object

Re: [Python-ideas] A proliferation of (un-)Pythonically programmatic pragmas

2017-11-13 Thread Ned Batchelder
On 11/13/17 2:10 PM, Barry Warsaw wrote: I love many of the ancillary tools that help improve the quality of my Python code, including flake8, coverage, and mypy. Each of these usually produces some great diagnostics, but none of them are perfect, so they also produce false positives that have

Re: [Python-ideas] Support floating-point values in collections.Counter

2017-12-20 Thread Ned Batchelder
On 12/20/17 5:05 AM, Paul Moore wrote: On 20 December 2017 at 03:09, Joel Croteau wrote: Well here is some code I wrote recently to build a histogram over a weighted graph, before becoming aware that Counter existed (score is a float here): from collections import

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Ned Batchelder
On 4/16/18 1:42 PM, Chris Angelico wrote: 3) "expr -> name" ==> The information went data way. So either you take a parallel from elsewhere in Python syntax, or you take a hopefully-intuitive dataflow mnemonic symbol. Take your pick. My problem with the "->" option is that function

Re: [Python-ideas] Transpiling contracts

2018-10-02 Thread Ned Batchelder
I'm getting confused: is this still about an idea for Python, or development of a third-party library? --Ned. On 10/2/18 1:14 AM, Marko Ristin-Kaufmann wrote: Hi James, I had another take at it. I wrote it down in the github issue

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

2018-10-06 Thread Ned Batchelder
On 10/6/18 7:25 AM, Ram Rachum wrote: "This is a regular expression problem, rather than a Python problem." Do you have evidence for this assertion, except that other regex implementations have this limitation? Is there a regex specification somewhere that specifies that streams aren't

Re: [Python-ideas] Enabling / disabling optional type hinting

2019-03-23 Thread Ned Batchelder
On 3/23/19 1:37 PM, Gregory P. Smith wrote: Sure, someone is going to typo and omit the = from a := assignment in 3.8 but the walrus is unlikely to be used outside of an conditional or loop test context so this seems like a made up problem. Walruses aren't allowed as a top-level expression

Re: [Python-ideas] Consistency in naming [was Re: ...ALL CAPS] (off-list)

2019-02-03 Thread Ned Batchelder
3, 2019, at 11:20 AM, Ned Batchelder <mailto:n...@nedbatchelder.com>> wrote: James, you say below, "This kind of readability issue, datetime.now, is an example of what’s contributing to Python’s decline." Do you have any evidence of Python's decline?  Lots of metrics (albeit s

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

2019-05-22 Thread Ned Batchelder
On 5/22/19 8:56 AM, Yanghao Hua wrote: And this is something I have in mind for a Python DSL for HDL: def combinational_or_sequential_logic(in: Signal, out: Signal): local_signal = Signal() local_signal <- in << 10 # read as: local_signal <- (in << 10) out <- local_signal + 5

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

2019-05-22 Thread Ned Batchelder
On 5/22/19 8:29 AM, Yanghao Hua wrote: Yes, it does make sense. Forgive my lack of Scala knowledge, but is it possible for 'b' in your example to be the one that handles the addition? Specific case: class Seven: def __add__(self, other): return other + 7 def __radd__(self, other):

Re: [Python-ideas] Idea: Allow multiple levels of tracers

2019-04-25 Thread Ned Batchelder
ning trace function, but they should be able to decide when to call the sub-trace functions. Hmm... Maybe :) On 25 Apr 2019, at 19:16, Ned Batchelder <mailto:n...@nedbatchelder.com>> wrote: Perhaps I misunderstand what's implied by "simple(!) monkeypatch of sys.settrace", bu

Re: [Python-ideas] Idea: Allow multiple levels of tracers

2019-04-25 Thread Ned Batchelder
Perhaps I misunderstand what's implied by "simple(!) monkeypatch of sys.settrace", but the trickiest part of Ram's proposal is that the body of one trace function would still trigger the remaining trace functions.  That to me sounds like it's going to require changes to ceval.c --Ned. On

Re: [Python-ideas] Syntax to conditionally define a field in a dict

2019-04-26 Thread Ned Batchelder
On 4/26/19 11:03 AM, Joshua Marshall wrote: Hello all, I have a use case where I need to send a `dict` to a module as an argument.  Inside of this, it has a multi-level structure, but each field I need to set may only be set to a single value.  Fields must be valid, non-empty strings.  It

[Python-ideas] Re: something like sscanf for Python

2019-06-28 Thread Ned Batchelder
On 6/27/19 1:58 PM, James Lu wrote: On Jun 26, 2019, at 7:13 PM, Chris Angelico wrote: The main advantage of sscanf over a regular expression is that it performs a single left-to-right pass over the format string and the target string simultaneously, with no backtracking. (This is also its

[Python-ideas] Re: Tuple Comprehension

2019-11-18 Thread Ned Batchelder
On 11/17/19 9:39 PM, Daniel Zeng wrote: Syntax for tuple comprehension, something like: (i, for i in range(10)) This shouldn't result in ambiguity, since generators need to be in parentheses anyway: (i, for i in range(10)) vs (1, (i for i in range(10))) The existing comprehensions support

[Python-ideas] Re: Add "elif" to "for_stmt" and "while_stmt"

2019-12-14 Thread Ned Batchelder
On 12/14/19 4:37 PM, komissar.off.and...@gmail.com wrote: Hello! I think it will be useful in Python syntax if we can use "elif" in "for" and "while" statements besides "else" Example for i in range(j): ... elif i > 5: ... else: ... What you think about this change? Can you

[Python-ideas] Re: Where should we put the python-ideas HOWTO?

2019-12-01 Thread Ned Batchelder
On 12/1/19 10:45 AM, C. Titus Brown wrote: Hi folks, sorry, took me more than a few months, but I wrote a draft of a python-ideas HOWTO here, https://hackmd.io/@-6xkuCDkTrSFptQEimAdcg/B1noEGh2H Thanks so much for writing this. I think Python-Ideas is a perfect example of something that

[Python-ideas] Re: PyPI should include PEP 440-compliant version strings for including in install_requires

2020-02-10 Thread Ned Batchelder
On 2/10/20 2:26 AM, Chris Angelico wrote: On Mon, Feb 10, 2020 at 6:09 PM Matthew Einhorn wrote: On Sun, Feb 9, 2020, 11:03 AM Paul Moore wrote: On Sun, 9 Feb 2020 at 14:39, Soni L. wrote: Figuring out versioning is hard. PyPI should encourage semver by including PEP 440 version strings

[Python-ideas] Re: Improving Traceback for Certain Errors by Expanding Source Displayed

2020-02-10 Thread Ned Batchelder
On 2/10/20 1:25 PM, Chris Angelico wrote: On Tue, Feb 11, 2020 at 5:19 AM Andrew Barnert via Python-ideas wrote: Meanwhile, for the implementation side, I don’t think there’s an issue with how traceback passes data around, but with what’s available in the first place. Look at what gets

[Python-ideas] Re: f(doc)string resource imports

2020-01-14 Thread Ned Batchelder
On 1/14/20 12:44 PM, Soni L. wrote: We have importlib resources. We should put it to use. Imagine if you could separate your docs from your code and yet include them in your package. ``` f"""{from mymodule.docs include main.rst}""" def foo():   f"""{from mymodule.docs include foo.rst}"""  

[Python-ideas] Re: addition of "nameof" operator

2020-01-22 Thread Ned Batchelder
On 1/22/20 8:05 AM, Anders Hovmöller wrote: On 22 Jan 2020, at 13:23, Rhodri James wrote: On 22/01/2020 12:03, Anders Hovmöller wrote: He was pretty clear in saying he wanted the same thing as in C#. That no one in this thread seems to have looked that up is really not his fault in my

[Python-ideas] Re: addition of "nameof" operator

2020-01-21 Thread Ned Batchelder
On 1/21/20 1:42 PM, Johan Vergeer wrote: def __repr__(self): return f"{nameof(Person)}({nameof(self.name)}: {self.name}, {nameof(self.age)}: {self.age})" I'm trying to understand what you are looking for.  Why isn't the above line just:    return f"Person(name: {self.name},

[Python-ideas] Re: addition of "nameof" operator

2020-01-21 Thread Ned Batchelder
On 1/21/20 3:11 PM, Ned Batchelder wrote: On 1/21/20 1:42 PM, Johan Vergeer wrote: def __repr__(self): return f"{nameof(Person)}({nameof(self.name)}: {self.name}, {nameof(self.age)}: {self.age})" I'm trying to understand what you are looking for.  Why isn't the

[Python-ideas] Re: The "When" Keyword

2019-12-29 Thread Ned Batchelder
New keywords breaking code is why any proposal for a new keyword has to have a really strong justification. There has to be a large benefit to balance the implied cost of breaking code. Your proposal (if I understand it correctly) is that "when" would execute exactly like "if".  That is not a

[Python-ideas] Re: Alternative to `enumerate` and `range(len(sequence))`: indexes() and entries()

2019-12-27 Thread Ned Batchelder
On 12/27/19 10:16 AM, Marco Sulla via Python-ideas wrote: Steven D'Aprano wrote: On Fri, Dec 27, 2019 at 02:22:48AM -, Marco Sulla via Python-ideas wrote: It's very common to see: for i, x in enumerate(sequence): [...] Yes, that is very common, except that "sequence" can be any

[Python-ideas] Re: list.append(x) could return x

2020-04-20 Thread Ned Batchelder
On 4/20/20 11:25 AM, J. Pic wrote: Hi all, Currently, list.append(x) mutates the list and returns None. It would be a little syntactic sugar to return x, for example:     something = mylist.append(Something()) What do you think ? Now you can do this (but it could be unpopular):    

[Python-ideas] Re: Improve handling of Unicode quotes and hyphens

2020-05-10 Thread Ned Batchelder
On 5/10/20 3:09 AM, Steve Barnes wrote: Change the error message “SyntaxError: invalid character in identifier” to include which character and it’s Unicode value so that it becomes  “SyntaxError: invalid character 0x201c “  in identifier” – this is almost certainly the easiest change and fits

[Python-ideas] Re: Developer messages on install (pip, poetry, etc.)

2020-03-23 Thread Ned Batchelder
On 3/23/20 1:01 AM, Ronie Martinez wrote: Good day! I have been developing in Node for a few months now for non-Python projects (legacy project) and I found a NPM feature which could be helpful to developers of Python libraries. When you install a NPM package, some show a message from the

[Python-ideas] Re: Python JIT Compilation Thoughts

2020-05-25 Thread Ned Batchelder
On 5/25/20 6:02 AM, redrad...@gmail.com wrote: Hi all, I do not know maybe it was already discussed ... It's been extensively discussed and attempted. but the toolchain like LLVM is very mature and it can provide the simpler JIT compilation to machine code functionality and it will improve

[Python-ideas] Re: Move semantics

2020-11-27 Thread Ned Batchelder
On 11/26/20 11:45 PM, Guido van Rossum wrote: On Thu, Nov 26, 2020 at 7:45 PM MRAB > wrote: > It's not discarded, it's still referenced by d in the outer scope. > No, it's not any more, and that's the point. It was _moved_ into the function,

[Python-ideas] Re: Move semantics

2020-11-27 Thread Ned Batchelder
On 11/27/20 6:54 AM, Serhiy Storchaka wrote: 27.11.20 13:25, Ned Batchelder пише: On 11/26/20 11:45 PM, Guido van Rossum wrote: Yes, I see that now.  As Chris points out elsewhere in the thread, this proposal would have the type annotations change the actual behavior of the code

[Python-ideas] Re: Move semantics

2020-11-26 Thread Ned Batchelder
On 11/26/20 9:02 PM, MRAB wrote: On 2020-11-27 01:12, Ned Batchelder wrote: On 11/26/20 6:44 AM, 3mi...@gmail.com wrote: Add something like Move type hint to typing module. It will tell the analyzer that the input parameter of the function is moved and can not be used after. For example

[Python-ideas] Re: Move semantics

2020-11-26 Thread Ned Batchelder
On 11/26/20 6:44 AM, 3mi...@gmail.com wrote: Add something like Move type hint to typing module. It will tell the analyzer that the input parameter of the function is moved and can not be used after. For example: ``` def f(d: Move[dict]) -> dict: d['a'] = 2 return d d = {1: 2} f(d)

[Python-ideas] Re: Move semantics

2020-11-27 Thread Ned Batchelder
On 11/27/20 8:32 AM, Antoine Pitrou wrote: On Fri, 27 Nov 2020 07:32:17 -0500 2qdxy4rzwzuui...@potatochowder.com wrote: I come from old(er) school (1980s, 1990s) embedded systems, and who "owns" a particular mutable data structure and how/where it gets mutated always came up long before we

[Python-ideas] Re: allow initial comma

2021-03-12 Thread Ned Batchelder
I think the only reason anyone ever used leading commas to begin with was because of languages that didn't allow a final trailing comma.  In those worlds, to keep the editing smooth, people moved the commas to the beginning of the line, breaking with every comma-tradition. I don't see a

[Python-ideas] Re: allow initial comma

2021-03-16 Thread Ned Batchelder
On 3/16/21 8:22 AM, Roland Puntaier via Python-ideas wrote: I'd like to write def my_long_function_name(     , my_long_option_2 = "some default expression 1".split()     , my_long_option_1 = "some default expression 1".split()     ):     pass Why not write this instead?: def

[Python-ideas] Re: [Python-Dev] Re: Inadequate error reporting during function call setup stage

2021-02-23 Thread Ned Batchelder
On 2/23/21 12:55 PM, Paul Sokolovsky wrote: Hello, On Tue, 23 Feb 2021 11:52:57 -0500 Ned Batchelder wrote: On 2/23/21 12:56 AM, Paul Sokolovsky wrote: Hello, On Mon, 22 Feb 2021 17:32:23 -0500 Ned Batchelder wrote: On 2/22/21 3:06 PM, Paul Sokolovsky wrote: No, I'm proposing

[Python-ideas] Re: [Python-Dev] Re: Inadequate error reporting during function call setup stage

2021-02-23 Thread Ned Batchelder
On 2/23/21 12:56 AM, Paul Sokolovsky wrote: Hello, On Mon, 22 Feb 2021 17:32:23 -0500 Ned Batchelder wrote: On 2/22/21 3:06 PM, Paul Sokolovsky wrote: No, I'm proposing to stop faking lack of the last stack frame due to CPython's implementation details. See the original message for more

[Python-ideas] Re: Alternate lambda syntax

2021-02-16 Thread Ned Batchelder
"lambda" is unnecessarily obscure. Beginner: "why is it called lambda?" Teacher: "Don't worry about it, just use it to define a function" I'm not taking a side on whether to change Python, but let's please not lose sight of just how opaque the word "lambda" is. People who know the background

[Python-ideas] Re: [Python-Dev] Re: Inadequate error reporting during function call setup stage

2021-02-22 Thread Ned Batchelder
On 2/22/21 3:06 PM, Paul Sokolovsky wrote: No, I'm proposing to stop faking lack of the last stack frame due to CPython's implementation details. See the original message for more info. I'm trying to understand what last stack frame (or lack of a last stack frame, or the faking of a lack of

[Python-ideas] Re: Beginners accidentally shadow module names due to different expectation of the resolution order for module imports

2021-11-03 Thread Ned Batchelder
On 11/2/21 6:03 AM, Florian Wetschoreck wrote: Hello everyone: The scenario/observation: Beginners sometimes create scripts with the name of a package e.g. pandas.py or seaborn.py in order to test something. There's a previous discussion about preventing importing a file into itself. It's

[Python-ideas] Re: Proposal for get_or function in Python dictionaries

2023-07-17 Thread Ned Batchelder
On 7/17/23 1:10 PM, Dom Grigonis wrote: This whole thing started from dict’s `get` extension: def get_substitute(self, key, default=None, subs=()): return keyin self ? (self[key] := valin subs? subs[val] : val) : default I dare you to do a 1-liner with current if-else. Why are we