Reply to Alexis Masson:
There's no way we can end up in an undefined state. Python just detects if _ is
there, it doesn't use it's value. If it is there it's a wildcard pattern.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe
Reply to Chris:
My Browser showed "No results" and a windows error sound could be heard. I
couldn't find the PEP. If I did I would have studied a lot. I didn't have any
idea this idea was proposed before and also had a PEP (unfortunately rejected)
___
Hmmm. Didn't show up as a search result. Yet I feel like it's really to good to
have that feature. (Again, it's the PEP dictator's decision.) :-(
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
l execute and then exceptexpr will execute if expr raised
Exception (This may not be the best syntax I could come up with. This is just
an example. The syntax can be discussed later and will probably end up being
different from this.).
Thanking you,
With Regards,
Shreya
Reply to Chris:
Yes you're right, I meant if-else expression.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message
Python has support for conditional statement, list comprehensions, dict
comprehensions, etc. So we can write these in mere one or two lines. But for
try-except it's not possible to write it one or two lines. Many a times, we
have one stmt that we want to check and if it raises error then do
Now it seems Python doesn’t need constant. There are many ways we can achieve
constants. Though constants may increase performance. Yet again it can also be
the opposite.
From: Paul Sokolovsky
Sent: Saturday, May 29, 2021 12:44:09 AM
To: Shreyan Avigyan
Cc
I was thinking about introducing new opcodes for implementing static
variables. Not sure though. All of the ideas actually do the same thing.
The difference is approach.
On Fri, May 28, 2021 at 6:57 PM Chris Angelico wrote:
> On Fri, May 28, 2021 at 10:11 PM Steven D'Aprano
> wrote:
> >
> > On
Reply to Chris:
Also it's rarely the case where it can become thread unsafe suddenly. 1 /
10*something chances. Because I've repeatedly run a thread-unsafe code and have
not encountered thread unsafe state yet. GIL executes the code to a very good
extent. And is it hypothetically even possible
Chris wrote:
> This is thread-safe:
>
> from threading import Lock
>
> lock = Lock()
> counter = 0
> def get_next():
>with lock:
>global counter
>counter += 1
>my_counter = counter
This is a great workaround. I can try to improve this. But first of all should
we
Reply to Chris:
The only problem is that with that approach that we can't understand if that's
the last yield statement. To achieve that we need to keep going until we
encounter a StopIteration. And the value of x would 3. Because we're not
iterating over a particular generator. We're creating
> A context switch can happen between any two of those instructions.
> That means one thread could load the global, then another thread could
> load the same value, resulting in both of them writing back the same
> incremented value. Or, between opcodes 6 and 8 (between the lines of
> Python
My proposal is somewhat the sum of all of your ideas. Well I propose there
should a STORE_STATIC_FAST opcode that stores a static variable. Static
variable will be declared only once and will be initialized to None (statement
syntax will be similar to that of global). It will be initialized in
I'll try to implement the idea roughly and I'll try to observe how much
performance improvements (or the opposite) will occur.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
For the implementation I had the same idea as Steven. And I don't think static
variables should stored in __dict__ or __defaults__. Instead to increase
efficiency (more importantly not to decrease current efficiency) it should be
stored as a dict in __static__ or some other dunder member.
Reply to Chris:
I'm proposing a way to do this officially in Python. For example I know another
hack,
def count(cur={"cur":0}):
cur["cur"] += 1
return cur
>> Static should behave much like Python's for loop variables.
> I have no idea what this means.
That's a bad example. I was just
Well sometimes we don't want to pollute the module namespace. Two functions can
have two variables with the same name but with different values that we want to
be static. And this functionality already exists in Python but as a *hack*.
This idea proposes to add a new dunder member and a keyword
Lot of programming languages have something known as static variable storage in
*functions* not *classes*. Static variable storage means a variable limited to
a function yet the data it points to persists until the end of the program.
Well Python also kind of has that functionality. Python's
Well. How can I go beyond why constant was invented in the first place? As far
as I can understand by my limited knowledge that *sometimes* constants can be
useful, sometimes they are terrible. The main reason constant was invented was
to provide an additional support to programmers so that
Reply to Paul Moore:
> But you just said it was runtime, so it definitely *isn't* similar to
> the syntax error "Can't assign to literal here". You're making
> inconsistent statements again :-(
That's exactly why I wrote SomeErrorType instead of SyntaxError. They are never
similar. I just said
Reply to Chris:
Yes I know that. sys.stdout exists there for that reason only. But if we can't
print then it means we changed it somewhere. I just gave an example. I've seen
code where constants can be really necessary. Python lets us use these things
because it's a programming language. But
I've already given one. Since Python is dynamically typed changing a critical
variable can cause huge instability. Want a demonstration? Here we go,
import sys
sys.stdout = None
Now what? Now how can we print anything? Isn't this a bug? There are lots of
code out there where we need to protect
Reply to Stestagg:
That's annotation to make sure no one uses a name. This is a proposal to
implement constant name binding in Python. There are many applications of
constants.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe
Reply to Paul Moore:
if some_condition:
constant a = 1
else:
a = 2
a = 3
Yes this is allowed. This is runtime.
for i in range(10):
constant a = []
Not sure. Though it's preferable to be runtime. Preferable is "not allowed".
And lists are also literals. Any Python Object that is
Reply to Paul Moore:
In Python terms, a constant is a name that binds itself to a value in memory
and that name cannot bind itself to a different value now (unlike variables).
The value can be mutated (if mutable) but the name cannot bind to a different
value once it has bind itself to a
> What's a const *ptr and a const *ptr const?
In C, a const pointer means a pointer that can only point to one value while
const pointer const means a pointer that can only point to one constant value.
___
Python-ideas mailing list --
Reply to Steven -
Sorry for creating confusions.
1. Leave debugging. As I said that's not a good argument for the existence of
constants.
2. "Constants doesn't mean we can't reassign the name to a different value."
was differently intended. I was trying to say that we should *treat* it like
Reply to Richard Damon:
The values can be changed. It can be mutated (if mutable). This idea suggests
we can't reassign anything to the name. Suppose,
constant x = ["List"]
x.append("something") # OK
x = [] # Error
Think of it as a const *ptr. Don't think of it as const *ptr const.
Reply to Steven -
Literals mean 10 or 20. Can you assign something to literal? No. But you can
assign something to a variable to point to another value. That's why I said
constants should behave like literals. Point is constants are names bind to a
value. We can change the value but not the
Chris wrote:
> There are many arguments in favour of constants, but this one strikes
> me as particularly weak.
That's not exactly how I meant it. I was telling that while constant should be
there it should not be used as "Use constants everywhere". I actually believe
the main reason for
Reply to Chris:
There are two things I want to say about constants :-
1) Global-Local Constants - The ALL_CAPS convention variables should become
constant.
2) Class member constants - Constants should be used only for avoiding from
being overridden. It should not be used as "We have a class.
Reply to Steven D'Aprano:
> But you've said that you want constants to be capable of being rebound
> to a new value. So your constants are identical to variables.
No, not at all. Actually to be clear, constants are supposed to behave like
literals but in implementation they are nothing more
I actually suggest a different kind of Constant in Python not the classical
const we see in Java or C/C++.
Constants doesn't mean we can't reassign the name to a different value.
Constants behave like literals. They are sort of literals actually. We
reference a value by a name. Variable is
Reply to Chris:
Wait. Deployment? Before deploying we *run the code* at least once and then we
get the errors. And I'm not sure but type checking is ok but sometimes
enforcing is a better option. Why? Mypy or typecheckers have to be run manually
and they are also not part of the stdlib.
I'm aware that Python is a "Consenting Adults" language but I think Python
should provide this functionality at least. This idea doesn't actually make it
like Java. Because why should we mess around with that member anyway. Sometimes
we want to provide members that users must use but mustn't
First it would seem useless or not necessary but soon this becomes clear. 1) It
would help programmers debug their code easily and help them find out that the
bug's not in the constant, that's for sure. 2) This would allow another branch
of OOP programming to enter Python. Read-only member
Ethan:
> Optional typing != core Python.
Exactly
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
Yes I'm aware of that. That's for typing. I'm talking about implementing it in
Python itself not Python typing.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
I posted my previous idea regarding this on the mailing list. This idea is a
little different. This idea suggests introducing constant name bindings. This
is similar to const pointer in C/C++. Once a name has been assigned to a data
we can change the data (if mutable) but we cannot change the
Sorry for the name conflict. I tried to type Steven D'Aprano but instead it
resulted in Steve D'Aprano
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
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
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
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
People always come up with hacks like Ir. Robert Vanden Eynde has come up with
the vertical bar hack. This is why I feel there's no need to have additional
performance decrease and new syntax only to solve a little problem that occurs
in some third party like sympy.
I'm +1 on the idea but -1 on the proposed syntax. Yes it would be kind of nice
*but* it's not how Python arithmetic or grammar works. And why should Python
have that functionality? AFAICT Python doesn't have a module in stdlib for
symbolic math. This looks like a feature request to third party
Why do we need this functionality? What are the benefits? What are you trying
to solve? Is it worth adding it?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
As I said in my post in your previous thread, I'm -1. Why? Because you're not
solving anything. In fact you're making it more complicated. Developers can
have difficulties studying your idea, beginners don't stand a chance (In fact I
have no idea what you described here in your idea and trust
Christopher Baker:
> Python assumes, and converts to, floats all over the place. So users need
> to understand and accommodate the limitations of floats anyway. Having
> exact fractions in seemingly arbitrary places will not result in more
> accurate (or precise) results in most cases, but would
Range here means low <= value <= high. I also don't understand what Valentine
suggested and meant by range. I thought Valentine means low..=high as low <=
value <= high and meant to say that functionality already exists. I'm really
sorry for confusing everyone.
Chris:
> What do you mean by "an object in range"? Please be very specific
>here. I gave two interpretations, both of which make plausible sense
> within Python, and it's not clear which one you're addressing, or if
> you're talking about something completely different.
>
> What exactly is "range
Chris:
> But none of the rest of your statement is an argument against Fraction
> literals.
If we have fractions.Fraction then we must have decimal.Decimal. We always
don't judge by accuracy. There are other factors in motion that are to be
considered.
Chris:
> There are two obvious definitions of a range: a range object, and a
> pair of inequalities. I'm not sure whether a range object is
> supported, but it's possible to use a built-in type with a guard as a
> range check:
By range I mean an object in range. Is it possible to match object in
hange" or simply "beginners
concerning change" since all previous versions of Python displayed floats and
now it's displaying Fractions! Some code may be hoping to find type() == float
and to it's surprise it's not that!
Thanking you,
With Rega
-1. This would require definition of what is a range and which types it
support. Defining ranges of user-defined classes doesn't make sense and it
would also be hard to implement.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe
I'm currently learning about the GIL and how can it be removed. So I'm
confessing that I understood only half of your words and I can be wrong.
As far I understood by reading your long passage, the problem is other threads
don't get enough chance to run and the CPU-Bound Python process will
+1 and -1 at the same time. I feel like :-
"This makes sense",
try:
# something
except E1, E2, E3:
# something
"This doesn't make sense",
try:
# something
except E1, E2, E3 as e:
# something
The second one according to this idea would be parsed as,
try:
# something
except
+1
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
be best if
a macro (like PY_AUTO_OBJECT maybe?) is defined then it'll add those classes
automatically. If the slot is NULL or 0 then don't add anything. But yeah they
may add more classes if they want but it doesn't matter much.
Thanking you,
With Regards,
Shreyan Avigyan
Ethan:
> As you may have noticed, this is a mailing list -- no thread is closed. I've
> seen posts to three-year-old threads.
Since the discussion has come to a halt and it's decided that we'll continue to
use the Pythonic way for private and it's also very hard to implement what I
suggested,
Steven D'Aprano:
> My guess is that you have used a lot of Java, or at least read a lot of
> Object Oriented Programming theory that is based on the Java model
I've never used Java. I don't even know Java so well. But the Java and C++
model is similar and since I know C/C++ I'm guessing about
. Thanks
anyway for considering this. This thread is closed now. Thanking you,
With Regards
Shreyan Avigyan
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org
Chris:
> I'm not sure about other people, but I have never, not once, used
> @property as a means of controlling access. So giving me another way
> to do something that I am not, and don't want to, do... isn't much of
> an argument. :)
Ok. I'm giving you another example that doesn't cause
Chris:
> That would require some definition of what's "within" and what's
> "outside" the class, and whatever definition you use, it won't work
> with all forms of dynamic code.
Yes, implementing that will be hard. But the question is I can't quite
understand why this is not acceptable by the
David Mertz:
> I am a strong -1 on this
Thanks for your feedback. But I'm not suggesting introducing a new behavior.
The @property already creates read-only member variables. What I'm suggesting
is that introducing a new keyword or decorator as required to create a variable
that can be
André Roberge:
> My own email specifically referred to two instances where I found it
necessary to **modify** methods that are indicated as being private as
their names begin with double underscores. So, I am strongly opposed to
your suggestion.
Actually as I explained in this comment
Again. See what I suggested. I changed my suggestion from "Private" to
"Non-modifiable member variables".
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
Chris :-
> Please actually quote some text so we know who you're responding to,
what you're talking about, etc.
I'm actually telling to read my comment here
https://mail.python.org/archives/list/python-ideas@python.org/message/426EPANCVEGZV2AZL7MWNG67BTZMORNG.
See the Conclusion section in
Most of the time when someone fixes a bug using a private member of another
class then it's completely considered private code. Sometimes applications can
cause crashes if there's memory leak or modification. Like there's an example
where you change the name attribute of a bank account class
Please read my whole comment.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
First of all, the reason that private members can be hacked in C++ because of
pointers. I don't know Java, so I don't know how it's possible there. But
Python doesn't have pointers and getattr, settatr can be adjusted to work with
private members. The only way the hack is possible if someone
See my comment here -
https://mail.python.org/archives/list/python-ideas@python.org/message/L5LUQDNNV5ZTF4E33L2JSOYIKPJUJJK5/
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
I don't know if it's worth adding private to python modules but what about
classes? Private in class is an important feature in OOP that Python lacks
(Most OOP languages have private like Java, C++, etc.). I don't know why it was
introduced in the first place but it's kind of a convention to
at's been
explained already (sometimes I miss out a feature in a PEP and think about
suggesting that feature when it's already there and then I realize "Oh! It's
already here in this PEP"). If that's the case then please correct me.)
With Regar
Got it
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
This thread is closed therefore. (It was mistakenly opened due to
misunderstanding.)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
Ooops...Didn't notice it. Anyway this thread is considered closed.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Ok.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
Ok. Now I'm able to understand. PEP 634 should have a reference to PEP 636 or
else it's pretty hard to understand because the syntax section demonstrates
PEG implementation of this.
___
Python-ideas mailing list -- python-ideas@python.org
To
I'm confused. PEP 634 is about switch statements in Python or PEG?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Sorry PEP 634 not PEP 643
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
Isn't PEP 643 for PEG grammar pattern matching? (I'm talking about switch
statements in Python)
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
Most of programming languages out there have switch-case statements. Python
doesn't have support for switch-case statements though. switch-case statements
can sometimes be nice and tidy and sometimes it may be a horrible nightmare.
But that also applies to if-elif-else statements. It would be
Thanks for clarifying. And I agree with you. Not writing checking code will
make the function more flexible.
Thanking you,
With Regards
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
First of all the use case is when for example we have UserDefined class and my
function or another class can only handle instances of the UserDefined class.
Second of all why not add a built-in type check decorator then?
___
Python-ideas mailing list
I am aware of all those libraries that allows us to type check. But it would be
nice to have this feature built-in. I'm not talking about modifying type
annotation but introducing a new feature. Like,
def add(int a, int b):
return a + b
If type is not provided then take in any parameter
Think it like this. We have this code in Python :-
def add(a, b):
return a + b
Here we are taking two arguments a, b and then returning a + b. But we can pass
in instance of any class like str, int, float, dict, user-defined class, etc.
But we only want to add int here. Here we can modify
Thanks for clarifying. And I wasn't telling to write
if (obj != NULL) {
Py_DECREF(obj);
}
I was actually proposing to change the code in the static inline function
_Py_DECREF by putting all of the code in the function inside the if block.
But Chris has a point. If we know for sure that
After going through the
https://github.com/python/cpython/blob/master/Include/object.h it seems that
Py_XDECREF is just calling Py_DECREF if the PyObject pointer is not NULL. This
if statement could be directly implemented in Py_DECREF right? Therefore is it
really required to have Py_XDECREF?
Got it. Thanks.
On Mon, Apr 5, 2021 at 2:24 PM Eric V. Smith wrote:
>
> > On Apr 5, 2021, at 4:43 AM, Shreyan Avigyan
> wrote:
> >
> > Yes you are right. But isn't informing people about a change the work
> of PEP? I mean this is kind of a major change becau
OkSo the text will be changed.
I've already used the issue tracker to describe this change. I'm yet to receive
confirmation from there. I'll submit the PR as soon as I receive confirmation.
Thanks a lot everyone.
With Regards
___
Python-ideas
Yes you are right. But isn't informing people about a change the work of PEP? I
mean this is kind of a major change because we're trying to change the error
message and/or the type. If the type is not changed then no PEP is required but
if the type is changed then there comes a maybe. What
OkA CursesNotFoundError derived from ModuleNotFoundError is okNow
should a draft PEP be submitted or should a PR be directly submitted to
https://github.com/python/cpython?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe
When importing the curses module, be it on Windows or Darwin or UNIX-based OS
or any other platform, if the _curses module is not found then just a
ModuleNotFoundError is raised. But this error is not very informational in case
of _curses module. Since the curses module is packaged with the
93 matches
Mail list logo