[Python-ideas] Re: Extract variable name from itself

2023-09-16 Thread Bruce Leban
If the goal is to create a syntax that allows tools to recognize names in strings, there is a simple solution which requires tool changes only, for example: raise Exception('The field ' + ((('size'))) + ' must be a positive integer in ' + ((('Sample.widget' Python already treats triple parent

[Python-ideas] Re: Warn when iterating over an already exhausted generator

2023-06-13 Thread Bruce Leban
I think the discussion is sort of missing a very common use case, when a user calls func(iterator) and the function is expecting an iterable but not an iterator. The author of the called code might be thinking that the input is a list but that doen't mean the caller thinks that. Even worse is a cas

[Python-ideas] Re: Allowing `str.format` to format one or more parameters instead of all parameters

2023-04-28 Thread Bruce Leban
On Tue, Apr 25, 2023 at 6:16 PM Joao S. O. Bueno wrote: > > Worst case scenario, one goes from one non-running program to a running > program producing partially incorrect output. Any legacy code that was not > working in the first place, is obviously, clearly, not critical for anyone, > otherwis

[Python-ideas] Re: join() could add separators at start or end

2023-03-08 Thread Bruce Leban
On Wed, Mar 8, 2023 at 4:34 PM Rob Cliffe via Python-ideas < python-ideas@python.org> wrote: > It seems to me that it would be useful to be able to make the str.join() > function put separators, not only between the items of its operand, but > also optionally at the beginning or end. > E.g. '|'.jo

[Python-ideas] Re: Ampersand operator for strings

2023-03-07 Thread Bruce Leban
On Sun, Mar 5, 2023 at 7:39 PM Rob Cliffe via Python-ideas < python-ideas@python.org> wrote: > Tl;dr: Join strings together with exactly one space between non-blank > This idea is inappropriate for inclusion in the language. There are too many subtle details in how this should work as noted by ot

[Python-ideas] Re: Idea: Tagged strings in python

2022-12-17 Thread Bruce Leban
On Sat, Dec 17, 2022 at 10:10 AM wrote: > > I replied to this in a separate post, but html() is likely a function name > that is used in millions of existing code bases. Applying this rule to all > of them will lead to too many errors to be acceptable to editors I think. > And if this has to be e

[Python-ideas] Re: Idea: Tagged strings in python

2022-12-17 Thread Bruce Leban
On Sat, Dec 17, 2022 at 9:43 AM wrote: > > Your reply could easily be read as "this is a bad idea, and you shouldn't > have bothered writing it down". I hope that was not your intention, and > instead it comes from handling self-indulgent people expecting things from > you all day. I know, I get

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Bruce Leban
On Sun, Dec 4, 2022 at 11:08 AM Chris Angelico wrote: > > > You're not the first to try to use globals() for this, but it means > that the context manager works ONLY at top-level. > I agree with most criticism of this proposal, although I'll note that the one place where I'd like something like

[Python-ideas] Re: Add InvalidStateError to the standard exception hierarchy

2022-09-01 Thread Bruce Leban
On Thu, Sep 1, 2022 at 2:57 PM Jean Abou Samra wrote: > > How would > a "state error" differ from this more precisely? What value would this new > exception type add? Both ValueError and this proposed StateError are very > generic. > Some examples: * a stream-like object that has been closed a

[Python-ideas] Re: Add InvalidStateError to the standard exception hierarchy

2022-09-01 Thread Bruce Leban
Java calls this IllegalStateException so I would suggest IllegalStateError. Looking at other exceptions that Java has, it would also be nice to have UnsupportedOperationError (I have used NotImplementedError for this but that suggests it might someday be implemented). On the other hand, as you no

[Python-ideas] Re: Regex timeouts

2022-02-14 Thread Bruce Leban
On Mon, Feb 14, 2022 at 9:55 AM J.B. Langston wrote: > ... more generally I think it would be good to have a timeout option that > could be configurable when compiling the regex so that if the regex didn't > complete within the specified timeframe, it would abort and throw an > exception. > > ...

[Python-ideas] Re: Please consider mentioning property without setter when an attribute can't be set

2022-02-13 Thread Bruce Leban
I think the more useful message would be something along the lines of AttributeError: can't set attribute 'f' on object of type 'D' This will help you track down the error. Steven D'Aprano listed three reasons why it might fail which sounds right but frequently the underlying reason is so

[Python-ideas] Re: Mapping unpacking assignment

2022-02-06 Thread Bruce Leban
On Thu, Feb 3, 2022 at 11:53 AM Yurii Karabas <1998uri...@gmail.com> wrote: > > Proposed syntax: > > m = {"a": 1, "b": 2, "c": 3, "d": 4} > > {a, b} = m # a: 1, b: 2 > {a, b, **rest} = m # a: 1, b: 2, rest: {c: 3, d: 4} > > as equivalent to this from PEP 634: > match m: > case {"a": a, "b":

[Python-ideas] Re: Unit variables upon their first appearance

2022-02-05 Thread Bruce Leban
On Sat, Feb 5, 2022, 12:19 PM Mirmojtaba Gharibi wrote: > > With my proposal, using := to init (similar to how in math parlance, the > := is used for defining something for the first time) > > Dic = {} # format fruit:count > For fruit in fruits: >Dic[fruit]:= 0 >Dic[fruit]+=1 > To my ey

[Python-ideas] Re: Syntax for late-bound arguments

2021-10-23 Thread Bruce Leban
On Sat, Oct 23, 2021 at 7:55 PM Steven D'Aprano wrote: > > And is it really a problem if we delay the late-binding to the point > where the value is actually needed? ... [in that csse] I would stick to manual late- > binding using None, and only evaluate it as needed. > > Maybe this i

[Python-ideas] Re: Syntax for late-bound arguments

2021-10-23 Thread Bruce Leban
--- Bruce On Sat, Oct 23, 2021 at 7:55 PM Chris Angelico wrote: > On Sun, Oct 24, 2021 at 1:48 PM Bruce Leban wrote: > > > > > > On Sat, Oct 23, 2021 at 6:23 PM Jelle Zijlstra > wrote: > >> > >> In the PEP's example: > >> &

[Python-ideas] Re: Syntax for late-bound arguments

2021-10-23 Thread Bruce Leban
On Sat, Oct 23, 2021 at 7:00 PM Steven D'Aprano wrote: > I challenge that assertion. I've never knowingly seen a function where > the late binding is "buried deeper in the function", certainly not deep > enough that it is not obvious. It is a very strong convention that such > late binding operat

[Python-ideas] Re: Syntax for late-bound arguments

2021-10-23 Thread Bruce Leban
On Sat, Oct 23, 2021 at 6:23 PM Jelle Zijlstra wrote: > In the PEP's example: > > def bisect_right(a, x, lo=0, hi=>len(a), *, key=None): > > This reads to me like we're putting "hi" into "len(a)", when it's in fact > the reverse. > I think in most cases what's on the right side will be something

[Python-ideas] Re: Syntax for late-bound arguments

2021-10-23 Thread Bruce Leban
On Sat, Oct 23, 2021 at 12:56 PM Guido van Rossum wrote: > I like that you're trying to fix this wart! I think that using a different > syntax may be the only way out. My own bikeshed color to try would be `=>`, > assuming we'll introduce `(x) => x+1` as the new lambda syntax, but I can > see pro

[Python-ideas] Re: Looking for a PEP sponsor

2021-07-14 Thread Bruce Leban
On Wed, Jul 14, 2021 at 8:50 AM Nick Humrich wrote: > > In accordance to PEP 0, I am looking for a Python-core-developer to > sponsor my new PEP. It is essentially a revisit of PEP 501. https:// > github.com/nhumrich/peps/blob/master/pep-.rst > > By immediatel

[Python-ideas] Re: An alternate idea for escaping in string interpolation

2021-06-27 Thread Bruce Leban
Thanks for the comments, Paul and Paul. On Sun, Jun 27, 2021 at 1:14 AM Paul Moore wrote: > On Sun, 27 Jun 2021 at 08:11, Paul Bryan wrote: > > > > It looks like you're suggesting hard-coding specific language escape > conventions into f-strings? > > That's how I understood the proposal too. Ha

[Python-ideas] An alternate idea for escaping in string interpolation

2021-06-26 Thread Bruce Leban
This is a response in part to Thomas Güttler's "Pre PEP: Python Literals" but I am starting a separate thread because I think it deserves separate discussion, and it's not a direct response to that proposal. Here's the problem: we want to allow escaping in strings to prevent injection in HTML, SQL

[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Bruce Leban
On Sun, May 9, 2021 at 1:22 PM MRAB wrote: > > On the third hand(!), 'as' is used in the 'import' and 'with' > statements, where it binds to only one preceding item. > Thanks. Yes, that was what I was thinking that it's weird for "as" to have different precedence in different statements, and I s

[Python-ideas] Re: Add a mechanism so that multiple exceptions can be caught using `except E1, E2, E3:`

2021-05-09 Thread Bruce Leban
On Sun, May 9, 2021 at 9:48 AM Thomas Grainger wrote: > now that python2.7 is EOL, it might be worth resurrecting this syntax as > discussed in https://www.python.org/dev/peps/pep-3100/#id13 > > eg, python 3.11 could support > ``` > try: > ... > except (E1, E2, E3) as e: > ... > ``` > > a

[Python-ideas] Re: String comprehension

2021-05-03 Thread Bruce Leban
On Fri, Apr 30, 2021 at 9:06 AM David Álvarez Lombardi < alvarezd...@gmail.com> wrote: > I propose a syntax for constructing/filtering strings analogous to the one > available for all other builtin iterables. It could look something like > this. > > >>> dirty = "f8sjGe7" > >>> clean = c"char for c

[Python-ideas] Re: Reverse polish notation

2021-04-02 Thread Bruce Leban
I know I'm late to the party but I think what would really help is if we were able to use any Unicode parenthesis characters instead of just (). Consider how much more readable this is: b*(⧼x*2⧽^❪⦅3-a⦆-⟮7*c⟯)❫) --- Bruce ___ Python-ideas mailing list --

[Python-ideas] Re: Move semantics

2020-11-26 Thread Bruce Leban
On Thu, Nov 26, 2020 at 5:43 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: > ``` > You say "moved and cannot be used" which is either incomp

[Python-ideas] Re: A new suggestion for Python

2020-09-30 Thread Bruce Leban
If I can, I want to back up the conversation a bit. Instead of starting with a solution, what's the problem? I believe the issue that this is trying to solve is that some functions that operate on an object return a new object, and we would like to use them to modify an object. Setting aside the f

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-08-26 Thread Bruce Leban
A bunch of the conversation here is how to handle both positional and keyword arguments with a single signature. Let me suggest an alternative. At compile time, we know if the call is made with keyword arguments or not. a[1] positional only a[b=1] keyword only a[1, b=1]both a[**k

[Python-ideas] Re: Pickle security improvements

2020-07-11 Thread Bruce Leban
The security problem arises from the fact that pickle will call arbitrary functions and that it will unpickle arbitrary classes, not just the ones that you might intend it to. It seems to me that the way to make pickle safe is to limit what it can call. Unpickle can take a list of classes and it w

[Python-ideas] Re: Add builtin function for min(max())

2020-07-06 Thread Bruce Leban
On Mon, Jul 6, 2020 at 4:27 AM Richard Damon wrote: > > > Supported, yes. Recommended, no. IEEE-754 specifies that the *minimum > > *operation propagates NaNs while the /alternate /*minimumNumber > > *operation drops NaNs. > > It should be noted, this is a change in the Standard that is just 1 ye

[Python-ideas] Re: Add builtin function for min(max())

2020-07-05 Thread Bruce Leban
On Sun, Jul 5, 2020 at 8:57 AM Steven D'Aprano wrote: > > In the absense of any clear winner, my position is that NAN poisoning > should be opt-in. We should pick the option which inconveniences people > who want the other the least . > > Let's say the stdlib uses Option 1. The function doesn't n

[Python-ideas] Re: Incremental step on road to improving situation around iterable strings

2020-02-24 Thread Bruce Leban
--- Bruce On Mon, Feb 24, 2020 at 1:19 PM Alex Hall wrote: > I think maybe you forgot to reply to the list as well? > > I did mean to reply to the list, so adding it back in. > How many scripts do you have where your own code directly iterated over a > string? How hard do you think it would

[Python-ideas] Re: Incremental step on road to improving situation around iterable strings

2020-02-22 Thread Bruce Leban
On Sat, Feb 22, 2020, 5:29 PM Steve Jorgensen wrote: > ... Currently, it is necessary to specifically test whether a node is an > instance of `str` and stop drilling down in that case. One could say that's > a minor issue, but it's a minor issue that affects a lot of development > efforts and has

[Python-ideas] Re: SQL string prefix idea

2020-02-21 Thread Bruce Leban
On Fri, Feb 21, 2020 at 5:53 AM wrote: > The idea is to add a new string prefix 's' for SQL string. This string > doesn't do anything in Python, unlike b"" or f"" strings, but interactive > Python shells like IPython or Jupyter can parse the following characters as > SQL syntax instead of Python

[Python-ideas] Re: statement-scoped context managers (was: Re: Pickle to/from filename or path)

2020-02-08 Thread Bruce Leban
On Sat, Feb 8, 2020 at 1:22 PM Chris Angelico wrote: > On Sun, Feb 9, 2020 at 8:04 AM Random832 wrote: > > > > On Fri, Feb 7, 2020, at 13:03, Todd wrote: > > > What if you could write pickle.dump(myobj, with open('myfile.p', 'wb'))? > > > > Or other similar examples such as (with open('myfile'))

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

2020-02-03 Thread Bruce Leban
On Mon, Feb 3, 2020 at 3:58 AM Richard Damon wrote: > > IF Python had a proper refactoring tool (see my other message where I > question the ability to do that) then the nameof operator would clearly > help keep logging/debug strings in line with the program definitions. > > A statement like prin

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

2020-02-02 Thread Bruce Leban
People keep mentioning refactoring. It's a red herring. No refactoring tool needs a nameof operator added to the language in order to do its job. And certainly an operator that requires running the program in order to use it is not going to be helpful. Refactoring tools analyze the program; they d

[Python-ideas] Re: Python slicing

2019-12-12 Thread Bruce Leban
On Thu, Dec 12, 2019, 7:28 AM Siddharth Prajosh wrote: > Something like - *s=list(range(100)); s.slice(10, 20).* > You mean like say s[slice(10,20)] ? Done. > > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email t

[Python-ideas] Fwd: for ... except, with ... except

2019-07-29 Thread Bruce Leban
And another message that was rejected (I sent from an unregistered email address) On Sat, Jul 27, 2019 at 1:49 AM Serhiy Storchaka wrote: > 26.07.19 21:52, Bruce Leban пише: > > > To put this in a simpler way: the proposal is to add an except clause that > applies ONLY to the d

[Python-ideas] Fwd: for ... except, with ... except

2019-07-29 Thread Bruce Leban
I sent this message earlier but it was rejected by the mailer. On Fri, Jul 26, 2019 at 11:27 AM Serhiy Storchaka wrote: > > So you will be able to add errors handling like in: > > with connect() as stream: > for data in stream: > try: > write(data) >

Re: [Python-ideas] Syntax for allowing extra keys when unpacking a dict as keyword arguments

2019-04-12 Thread Bruce Leban
On Fri, Apr 12, 2019, 8:12 AM Viktor Roytman > >>> func(**{'a': 1, 'b': 2}) > Traceback (most recent call last): > File "", line 1, in > TypeError: func() got an unexpected keyword argument 'b' > Perhaps func(***kws)? I think this is a real problem given the frequent conventio

Re: [Python-ideas] add fluent operator to everything

2019-02-20 Thread Bruce Leban
On Wed, Feb 20, 2019 at 11:03 AM Rhodri James wrote: > On 20/02/2019 18:24, Bruce Leban wrote: > > a = [1,2,3] > > (_:=a,_.append(4),_.sort()) > > I'm not sure what problem you are solving here, but if that's the > solution I&#x

Re: [Python-ideas] add fluent operator to everything

2019-02-20 Thread Bruce Leban
On Wed, Feb 20, 2019 at 10:34 AM Jonathan Fine wrote: > There's a problem with introducing ,_ as a new operator. > I should have put "new" in scare quotes to be more clear as it's not really new. As you've observed this is already implemented. For it to work as in my example you also need to use

Re: [Python-ideas] add fluent operator to everything

2019-02-20 Thread Bruce Leban
Here's a syntax that solves this using the new operators _:= and ,_ a = [1,2,3] (_:=a,_.append(4),_.sort()) Personally, I find this a bit harder to read on one line and would break it up like this: (_:=a ,_ .append(4) ,_ ..sort() ) --- Bruce _

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

2019-01-30 Thread Bruce Leban
Text in color or against black backgrounds is harder to read than black on white. See for example: https://trevellyan.biz/graphic-design-discussion-how-color-and-contrast-affect-readability-2/ Text where different words in the same sentence are in different colors is even harder to read. And I th

Re: [Python-ideas] Backtick expression: similar to a shorter lambda syntax

2019-01-23 Thread Bruce Leban
On Wed, Jan 23, 2019 at 1:07 PM James Lu wrote: > Backtick expressions (now) use the same scoping and same binding rules as > other functions. > What do you mean by "now"?? There are no backtick expressions in Python anymore and they were never functions. > The only difference is that > class

Re: [Python-ideas] Backtick expression: similar to a shorter lambda syntax

2019-01-23 Thread Bruce Leban
On Sun, Jan 20, 2019 at 6:43 PM James Lu wrote: > Backtick expressions work exactly like lambdas, except that they are bound > to the instance they are created in every time that class is used to create > one. To illustrate, ... First, if there is a useful procedure I am strongly against using

Re: [Python-ideas] Proposal for an inplace else (?=) operator

2018-09-22 Thread Bruce Leban
On Saturday, September 22, 2018, Lee Braiden wrote: > > Proposal: > > The addition of a ?= operator could provide an elegant solution: > > > def teleport(from, to, hitchiker=None, food_accessory=None, > comfort_accessory=None): > > hitchhiker ?= Fly() > > food_

Re: [Python-ideas] Keyword only argument on function call

2018-09-08 Thread Bruce Leban
The proposal is to eliminate the redundancy of writing name=name repeatedly. But IMHO it doesn't do that consistently. That is it allows both forms mixed together, e.g., f(*, a, b, c=x, d, e) I believe this is confusing in part because the * need not be near the arguments it affects. Consider op

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-13 Thread Bruce Leban
On Sun, Aug 12, 2018 at 8:31 PM, Abe Dillon wrote: > > [Steven D'Aprano] > >> ...if we aren't even willing to move out of our own comfort zone to >> the extent of learning accurate jargon terms from our own profession? > > > Very few of us are computer scientists by profession. That's not even >

Re: [Python-ideas] a sorting protocol dunder method?

2017-12-03 Thread Bruce Leban
On Sun, Dec 3, 2017 at 3:06 PM, Chris Barker wrote: > > However, if you are writing a custom class ... > > But what if there was a sort key magic method: > > __key__ or __sort_key__ (or whatever) > > that would be called by the sorting functions > > It seems this would provide a easy way to ma

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

2017-11-19 Thread Bruce Leban
On Sun, Nov 19, 2017 at 4:18 PM, Mikhail V wrote: > Bruce Leban wrote: > > > It is not a misfortune or even true that Python uses hyphen for minus. > > The name of the character used in Python is HYPHEN-MINUS. > > This is pure demagogy, name it HYPHEN-MINUS-TINYDASH

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

2017-11-18 Thread Bruce Leban
On Sat, Nov 18, 2017 at 8:44 PM, Mikhail V wrote: > > > That seems to be another showcase of misfotune that Python > uses hyphen for minus operator. I know it is not language designer's > fault, because basic ASCII simply did not not include minus character. > But do you realise that the **current

Re: [Python-ideas] Remote package/module imports through HTTP/S

2017-08-23 Thread Bruce Leban
On Wed, Aug 23, 2017 at 11:11 AM, Chris Angelico wrote: > > > If you read his README, it's pretty explicit about URLs; the risk is > that "https://github.com/someuser/somelib"; can be intercepted, not > that "someuser" is malicious. If you're worried about the latter, > don't use httpimport. I

Re: [Python-ideas] Remote package/module imports through HTTP/S

2017-08-23 Thread Bruce Leban
On Wed, Aug 23, 2017 at 10:37 AM, John Torakis wrote: > > Github can be trusted 100% percent for example. This isn't even remotely close to true. While I'd agree with the statement that the SSL cert on github is reasonably trustworthy, the *content* on github is NOT trustworthy and that's where

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Bruce Leban
I'm not in favor of this idea for the reason mentioned by many of the other posters. BUT ... this does bring up something missing from json readers: *the ability to read one json object from the input rather than reading the entire input* and attempting to interpret it as one object. For my use cas

Re: [Python-ideas] Fwd: Null coalescing operator

2016-09-10 Thread Bruce Leban
On Sat, Sep 10, 2016 at 6:02 PM, David Mertz wrote: > What I was getting at with "essentially" was that it would *do the same > thing* that an AttributeError does. That is, if `x.foo` can't be evaluated > (i.e. x doesn't have an attribute 'foo'), then access is informally "an > error." The hypo

Re: [Python-ideas] real numbers with SI scale factors

2016-08-28 Thread Bruce Leban
On Sun, Aug 28, 2016 at 6:44 PM, Ken Kundert wrote: > When working with a general purpose programming language, the above numbers > become: > > 780kpc -> 7.8e+05 > 108MPa -> 1.08e+08 > 600TW -> 6e+14 > 3.2Gb -> 3.2e+09 > 53pm -> 5.3e-11 > $8G-> 8e+09 > These are n

Re: [Python-ideas] A proposal to rename the term "duck typing"

2016-08-28 Thread Bruce Leban
On Sunday, August 28, 2016, ROGER GRAYDON CHRISTMAN wrote: > > We have a term in our lexicon "duck typing" that traces its origins, in > part to a quote along the lines of > "If it walks like a duck, and talks like a duck, ..." > > ... > > In that case, it would be far more appropriate for use to