[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Shreyan Avigyan
Reply to Steve D'Aprano - I am talking about constant name binding. Once the name is bind it cannot be changed. The data will remain immutable or mutable. > That seems very odd. That would mean that you can't pass constants to > functions, or put them in lists or dicts, since that would create

[Python-ideas] Currying syntax with multiple parameter lists

2021-05-24 Thread Joren Hammudoglu
> Flat is better than nested. I remember being confused a lot when I was learning how to write my first decorator. Now eight years later, with the last two spent full-time writing Python, I introduced a bug in production because I forgot to return the inner function from within a decorator.

[Python-ideas] Re: Decorators on variables

2021-05-24 Thread Ethan Furman
On 5/24/21 6:36 PM, micro codery wrote: > Variable decorators have been suggested here before, as have new statements > that could also achieve the same level of access to the binding name. However > I propose a much more restricted syntax that would make for less edge cases > where what is

[Python-ideas] Re: Decorators on variables

2021-05-24 Thread Ricky Teachey
I don't have much of substance to say other than this proposal really made me go "oh I like that" several times. There may be downsides/arguments against I'm not considering, but I look forward to following the conversation and hope it gets a serious hearing. On Mon, May 24, 2021, 9:38 PM micro

[Python-ideas] Decorators on variables

2021-05-24 Thread micro codery
Variable decorators have been suggested here before, as have new statements that could also achieve the same level of access to the binding name. However I propose a much more restricted syntax that would make for less edge cases where what is actually passed to the decorator callable may be

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Steven D'Aprano
"Constant variables" is a contradiction in terms. If it is constant, it cannot be a variable, and vice versa. Can we be more precise in the language used please? We have two independent concepts here: * name bindings: names can be bound to a value, or unbound with the `del` statement; *

[Python-ideas] Re: match expressions in python 3.10

2021-05-24 Thread Valentin Berlier
On the other hand I think extending the walrus operator would make the change less intrusive and the syntax more easily discoverable: if match := re.match(r"...", some_string): print(match[1], match[2]) if [_, a, b] := re.match(r"...", some_string): print(a, b) # Assuming match objects

[Python-ideas] Re: match expressions in python 3.10

2021-05-24 Thread Steven D'Aprano
On Mon, May 24, 2021 at 07:55:07PM -, Tyler F wrote: > with the addition of PEP 634 and the new match/case syntax in python > 3.10, it seems fitting to be able to use these new match statements > inside of expressions as well, Python 3.10 isn't even showing up on the Downloads page yet:

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Chris Angelico
On Tue, May 25, 2021 at 8:09 AM Joren wrote: > > We could define "change" in terms of the hash of the object the name points > to, as well as the name itself (the pointer to the object). The hash of a random.Random() object doesn't change when its state does (its derived solely from its id).

[Python-ideas] Re: match expressions in python 3.10

2021-05-24 Thread Tyler F
ehhh in my opinion its more pythonic to use a keyword in this case, especially since that seems to be the main way it is currently done with statements being turned into expressions ___ Python-ideas mailing list -- python-ideas@python.org To

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Stestagg
-1 for all of this unless it’s included as part of a bigger change that has proven performance benefits when constants are used On Mon, 24 May 2021 at 23:10, Joren wrote: > We could define "change" in terms of the hash of the object the name > points to, as well as the name itself (the pointer

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Joren
We could define "change" in terms of the hash of the object the name points to, as well as the name itself (the pointer to the object). ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: symbolic math in Python

2021-05-24 Thread Joren
Aside from the type conversion dunders (e.g. `__bool__`), and the `and`, `or` and `in` operators, this is possible right now: You can create a `Symbol` class that returns another `Symbol` in the compatible operator dunder methods, while internally maintaining a list of (operator, args,

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Chris Angelico
On Tue, May 25, 2021 at 7:30 AM Joren wrote: > > typing.Final actually means something like "cannot be reassigned", whereas > constant variable means "cannot change". Consider e.g. > > class Spam: > def __init__(self): > self.eggs = 0 > > @final # method cannot be overridden

[Python-ideas] Re: match expressions in python 3.10

2021-05-24 Thread Valentin Berlier
There was a discussion about this a couple months ago but instead of adding a new keyword the idea was that the walrus operator could be upgraded from simply being a binding operator to matching patterns supported by the match statement. if ["example", *files] := variable: print(files) If

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Joren
typing.Final actually means something like "cannot be reassigned", whereas constant variable means "cannot change". Consider e.g. class Spam: def __init__(self): self.eggs = 0 @final # method cannot be overridden (which is more related to "reassignment" than to "change")

[Python-ideas] match expressions in python 3.10

2021-05-24 Thread Tyler F
with the addition of PEP 634 and the new match/case syntax in python 3.10, it seems fitting to be able to use these new match statements inside of expressions as well, which is why I think we should have a new `matches` keyword (similar to if/else, is, for, not, etc.) for use in expressions.

[Python-ideas] Re: Add support for private variables, methods and functions in Python

2021-05-24 Thread Marco Sulla
On Sun, 23 May 2021 at 19:50, Chris Angelico wrote: > > On Mon, May 24, 2021 at 3:38 AM Marco Sulla > wrote: > > > > > Do you yearn for actual refactoring tools - which do exist? > > > > > > > > Renaming tools of IDE do not work in 100% of the cases. For example, > > > > if you have _variable in

[Python-ideas] Re: dict.get_deep()

2021-05-24 Thread Marco Sulla
On Sun, 23 May 2021 at 19:41, Todd wrote: > > The pytoolz/cytoolz project already has this: > https://toolz.readthedocs.io/en/latest/api.html#toolz.dicttoolz.get_in It seems a project that is used by many people. I think that JSON is so much used that that function could be added to the builtin

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Shreyan Avigyan
Thomas Grainger: > This is already available with typing.Final and immutable types: > > from typing import Final > > ham: Final = 3 > ham = 4 # Error > > hams: Final[Sequence[str]] = ["ham", "spam"] > hams.append("meat") # Error I'm not sure whether it's a reply to me or someone else. But anyways

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Thomas Grainger
This is already available with typing.Final and immutable types: from typing import Final ham: Final = 3 ham = 4 # Error hams: Final[Sequence[str]] = ["ham", "spam"] hams.append("meat") # Error On Mon, 24 May 2021, 18:40 Abdur-Rahmaan Janhangeer, wrote: > Greetings, > > Just a light-hearted

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Abdur-Rahmaan Janhangeer
Greetings, Just a light-hearted note, if ever the idea is taken seriously, variable: constant = 10 seems more pythonic to me. constant variable = 10 opens the doors for int x = 5 etc Kind Regards, Abdur-Rahmaan Janhangeer about | blog

[Python-ideas] Introduce constant variables in Python

2021-05-24 Thread Shreyan Avigyan
Many times a programmer would want a variable that will be a constant. The programmer could have been careless and suddenly changed a very important variable. Proposed syntax, constant variable = 10 variable = 20 # Error Now constant means making a variable value immutable. It means now we can