[Python-ideas] Re: The Pattern Matching Wildcard Is A Bad Idea

2021-06-02 Thread Shreyan Avigyan
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 send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DA43HZMI5BQUFZLCRH5NTIPDSZUZKQDZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-02 Thread Shreyan Avigyan
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)
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/ASN62KSMF4QCV2E4TESAW6AN3ZN5MWVV/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-02 Thread Shreyan Avigyan
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 python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3Z65WSB7HT33JQIN2QPOJ3ROMS3LBCWI/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-02 Thread Shreyan Avigyan
I want to propose a try-except expression to handle expression errors not stmt 
errors (Yes I initially proposed stmt but now I'm changing it to expressions 
after I researched a little more and found it would make a whole lot of sense 
for expressions.). For example - var if var else var2 - will result in an 
NameError. This is an expression *not* a stmt. So how about having a new type 
of error handling way that handles expression errors and also is an expression 
itself? So let's assume the syntax will be like this -

>>> try expr, Exception exceptexpr

where expr will 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,
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/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WC75JKT5DD7BRLG4OW5EDZ43M2EPFEDG/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add "try: stmt except: stmt" syntax to Python

2021-06-02 Thread Shreyan Avigyan
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 archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/AKDATM2ETKDI4FFR6NM3FX53CADDTB7Z/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Add "try: stmt except: stmt" syntax to Python

2021-06-01 Thread Shreyan Avigyan
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 nothing or 
just execute one stmt. This idea proposes to add a way to write try-except for 
one stmt in one line.

Thanking you,

With Regards
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/T7UKDECCKNXPWIJ6VLCDGAVSXRJQVZ7W/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-29 Thread Shreyan Avigyan
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: python-ideas@python.org 
Subject: [Python-ideas] Re: Introduce constants in Python (constant name 
binding)

Hello,

On Tue, 25 May 2021 11:53:20 -
"Shreyan Avigyan"  wrote:

> 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 name to point to a different data. The only way
> the data the constant points can get deallocated is if it goes out of
> scope, the program exits or the constant is manually `del` by the
> user. The proposed syntax is as follows,
>
> constant x = 10
> constant y = ["List"]
> constant z: str = "Hi"

The idea of introducing constants on the core language level in Python
is well-known topic and was brought up on multiple occasions both on
the python-ideas and python-dev mailing lists. A random example:

https://www.mail-archive.com/python-dev@python.org/msg110424.html
"constants in Python: Starting simple and gradually adding more
features, was: Re: Pattern Matching controversy"

The matter is actually implementing it in different Python
implementations. And some implementations had support for *some kind*
of constants for many years (e.g. MicroPython with it's pre-annotation
syntax of "FOO = const(1)"), while CPython still has it only on the
level of external first-generation annotation module, "typing".

As another example, I can give "strict mode"
(https://www.mail-archive.com/python-ideas@python.org/msg25403.html)
feature of my Python dialect, Pycopy
(https://github.com/pfalcon/pycopy), which implements some (but again,
not all) aspects of const'ness. E.g.:

===
print("In import-time")
a: const = 1
a: const = 2


def __main__():
print("In run-time")
global a
a = 3
===


Gives:


In import-time
Warning: strict mode: overriding (monkey-patching) const name 'a'
In run-time
Traceback (most recent call last):
  File "strict.py", line 9, in __main__
RuntimeError: strict mode: cannot override const name




--
Best regards,
 Paul  mailto:pmis...@gmail.com
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/PHU3YE47SI55JODFG3W53GZIJK6IH4FL/
Code of Conduct: http://python.org/psf/codeofconduct/
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/5UU3IYKZZ5Z5WZQH2DKJILKYVVYRRDJQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-28 Thread Shreyan Avigyan
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 Fri, May 28, 2021 at 04:20:15AM +1000, Chris Angelico wrote:
> >
> > > def f():
> > > static x = 0
> > > x += 1
> > > yield x
> > >
> > > next(f())
> > > next(f())
> > > next(f())
> > >
> > > will yield 1 every time?
> >
> > I think that this example has just about convinced me that Chris'
> > approach is correct. I wasn't thinking about generators or recursion.
> >
> > I think that closure nonlocals are almost as fast as locals, so we might
> > be able to use the closure mechanism to get this. Something vaguely
> > like this:
> >
> > def func():
> > static var = initial
> > body
> >
> > is transformed into:
> >
> > def factory():
> > var = initial
> > def func():
> > nonlocal var
> > body
> > return func
> > func = factory()
> >
> >
> > except that the factory is never actually exposed to Python code.
>
> I think that would probably work, but even better would be if the
> outer function didn't actually exist. A bit of playing around suggests
> that LOAD_DEREF could just work here. If you have multiple levels of
> nonlocals, the function flattens them out into a tuple in
> f.__closure__, identifying them by index. Statics could be another
> level of nonlocals that doesn't actually require a function as such.
>
> In terms of describing the semantics, I think this is probably the
> cleanest way to give a pure-Python equivalent.
>
> > It would be nice if there was some way to introspect the value of `var`
> > but if there is a way to do it I don't know it.
>
> No idea about other implementations, but in CPython, you can look at
> f.__closure__[*].cell_contents, but you'd need to know the mapping
> from static name to lookup index. I think the corresponding names are
> in f.__code__.co_freevars, but I'm not sure if there are any other
> things that go in there.
>
> > We might not even need new syntax if we could do that transformation
> > using a decorator.
> >
> >
> > @static(var=initial)
> > def func():
> > body
> >
>
> Hmm, there'd need to be some transformations, since the code generator
> is always going to use lexical scope. You can't magically change a
> LOAD_GLOBAL into a LOAD_DEREF with a decorator - the only way would be
> to do some fairly hairy rewriting, and you might lose a lot of the
> efficiency. This really needs proper compiler support, and if it gets
> compiler support, it may as well have dedicated syntax.
>
> ChrisA
> ___
> 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
> https://mail.python.org/archives/list/python-ideas@python.org/message/7CXYEBUKVCLB3O6APOG5TUMPACWFVUGY/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/V4QYXAECONMCXQZMFSEH2U7AUD3N4HZT/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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 to have thread unsafe state that 
can affect functions? Because locals of the different functions are different. 
Since the variable will be loaded by LOAD_FAST it will look into locals for the 
static variable and both locals will differ. The only dangerous code is op=. 
Because this depends on the current value of static variable that can make the 
function go to an undefined state.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/T5234WEZ2HJZVLJNYAV565IGRSVYQLIC/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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 depend on the user to do this locking? I don't think so. So is it possible 
to implement this in the background without affecting current performance?
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/MMC4MFCMWH2VZXKKAKVC2NFQJENOMI74/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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 multiple instances which 
actually would increase x.

And also is there another way we can make it thread safe? Steven's idea is 
actually the only solution we've encountered till now. I'd be really happy if 
someone could come up with even a better idea.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/63VEAJCXRA7MODB57JOCIPNGXXCIAML3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
> 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 code), you could store the value, then fetch back a different
> value.

I see now. Then we can go with Steven's idea. Let's keep the changes in locals 
temporarily and when it yields or returns then modify the __statics__ member. 
And even if it's a generator it will stop iteration some time and if it doesn't 
then the member wasn't meant to be modified.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/FCDWRSCIF6KZQ73N2AKOGWIEY6W4FGK3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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 
MAKE_FUNCTION. Now it will be set by STORE_STATIC_FAST. Where will the 
variables be stored? It will have references in locals and __statics__. 
Therefore LOAD_FAST can find it. So I don't hope there will be performance 
decrease but performance increase is also not guaranteed. :-)

And if these are thread unsafe then is __defaults__ also thread unsafe?
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/6FSYNBSC5HVQYMVCDGKENGT7G2MS4OTI/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FT2OTHOXJ6DRY4PFJNCFIH5IUDEMAAC6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/SLG54ROIMOROTGI7QLFB6WHCW4HL2QT5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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 trying to make it clear. But you have got the 
idea. So don't worry about that.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/VA37MHB7BH5UI52IMUFHID7QWTRC2VBJ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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 that allows us to 
use global variables but are limited to local scope. But since it's Python 
anyone can access it using the dunder member.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/B5IXIQGWXVEELTHF7ZOCRPJLUJX7MBZE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Add static variable storage in functions

2021-05-27 Thread Shreyan Avigyan
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 default values 
provide the same type of functionality but it's a *hack* and also *problematic* 
because only mutable types that are mutated persists. Static should behave much 
like Python's for loop variables. This idea proposes to add a keyword (static, 
maybe?) that can create static variables that can persist throughout the 
program yet only accessible through the function they are declared and 
initialized in.

Thanking you,

With Regards
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/X3GQVZL3P7OLLK42AGPJBBSLKIX4ZJDK/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 they don't make a 
program unstable.  And there are code that really have this problem. Python can 
be "Consenting Adults" language but so are others they just don't claim it. 
Programming is programming, it depends on the user and author what they'll 
choose to do "enforcing" or "consenting adults". And I must confess I don't 
like type checking in this context because Python should itself help us point 
out these relatively small but extremely important bugs related to constants 
(or Final). And constants doesn't make code fast. To avoid decreasing current 
performance, I propose to add new OP code and new AST node for constants so 
that they don't mingle with variables. And all constant assignment check
 ing should be done at runtime not compile time. I hope this actually answers 
all of the questions coming up till now.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/7ZLY3PBGBUC3RGIFWEK5ZZTFU573N3NH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 the behavior would seem similar.

> I don't think you've thought this proposal through at all, to be
> honest. You seem to be making up answers as the questions arise, which
> is *not* what people are asking for here. We are asking that you
> *explain* your proposal, assuming that you already know the answers
> and are simply struggling to communicate the details.

I'm trying my best. But sometimes there are few questions coming up that 
confuses and I'm not sure of the answer and I'm ending up making inconsistent 
statements.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/KK5EL5SSQWMVHKGLIGBBAHBLQIF5O47Q/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 libraries are not programming 
languages. They are there to enhance the programming. Suppose we're testing out 
a library. Now maybe there's something really critical we shouldn't change. We 
must access but mustn't change. And we mistakenly changed it. Now we're not 
gonna deploy our application. So we don't run a type checker. Now we run and 
the program crashes and yet we can't find where is the bug. Why should tools be 
needed to solve such an obvious problem? Why can't Python itself help us like 
it does when we add int and str?
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/VWSRDEO4APJ2QFFRGYZXNDCWNEEEIZ7S/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 things from being overwritten. Though 
I'm never telling to use constants in Python stdlib or else I could have never 
done this demonstration. :)
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/VIDMLLVPQBHCNJSM5ZYXRWH5EEOLNKYS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DDDMEDIXHMYLTZP7TJHWC5ECDJRF4CWU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 not assigned to a 
variable is a literal. Python claims that itself. A preview -

[10] = [2]
SyntaxError: Can't assign to literal here.

Constants should have a similar error -

constant x = 10
x = [2]
SomeErrorType: Can't assign to constant here.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/4SOB5SQWPQVLSHLDNBZXO46Z2D7RUAGE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 value.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/CVMLMQIQMKPKNGF2LKRYGRW4UO2CL2X4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
> 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 -- 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 
https://mail.python.org/archives/list/python-ideas@python.org/message/M22PBZ4ODALXOXBGGG5HHN2UARX44E6I/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 a 
*literal*. I never said constant will be a type of variable. I was a little bit 
unclear in that message.

3. Constant will be constant name binding. Value can be mutated (if mutable) 
but the name cannot be reassigned.

4. constant pi = 3.14
# later
pi = 3.1415 # Error
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/N3OEMQVQ5EZSNW4ZG223RMPP4VATF3F6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/IGGDFIPNS3IQ5HRHMQGRGI6V7BB2VBXX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 name to point to a different value. 
Simply think "const type *pointer" not "type *pointer const".

And by debugging I meant it would immediately be detectable if someone tries to 
change the constant or not. (Not a good argument in constant's favor though)
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/35ZKTEAQEUHJEXC7YZJSSG5FUWXAM2T5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 constants should "Debugging". Our program can become 
unstable if something really important changes. And yeah sometimes stopping 
people from doing dangerous things is a good idea and sometimes not.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/WBTQCTBI5YDFD3LMBITLWTFOUXGBNBPH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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. Use constants.". 
Sometimes if someone changes a critical value especially in Python a 
dynamically typed language it can have bad effects. Suppose we have a Windows 
and we go to registry editor and delete keys and set different values and then 
Windows won't boot up the next time. That's why class member constants is 
necessary.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/RX4LMZ3BIALTDBBYJMQBFMQN6MMYIZJW/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-26 Thread Shreyan Avigyan
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 than names that are bind 
to a value.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/PAQVBP6UZKCNOA5WZK43FRQWLYGC5IQH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-25 Thread Shreyan Avigyan
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 just a reference to a value and can 
change to provide reference to another value. Constants on the other hand are 
name for a value. So constant is a name we can alternatively use for a value. 
So 10 is same as constant while 10 is same as the value dereferenced by 
variable. 

I propose this logic to work behind the scenes though not sure whether this is 
possible at all.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/NTDZ4EZGKCWRK7FX7WGKF3MOWQUIRT3U/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-25 Thread Shreyan Avigyan
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. Enforcing can help us catch it during 
editing because we don't deploy before running it at least once. So we're 
writing our own code and we don't run it before deploying? Mypy will catch at 
step 2 but enforcing can help as catch at step 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 
https://mail.python.org/archives/list/python-ideas@python.org/message/IMD7WH43HFJ2IUJZG3HNYNWBQ3LRYYNM/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-25 Thread Shreyan Avigyan
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 change. Well if the 
user does, then "crash"! Suppose we have filename member and we must access 
that but if we change it by any chance then what will happen is Python will not 
close the file instead it will create a new file leaving it in an undefined 
state - "Half written half not".
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/HUCKCWP6T323KQ7HOZGUIVVAECBXPXJK/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-25 Thread Shreyan Avigyan
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 variables. There are 
Private members in Java and C++. But I believe they are not their to hide 
things. They are there to debug.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/PU4DFQRCAEXXQVECJ3IIZQK2UQLAENCX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-25 Thread Shreyan Avigyan
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/75CEJRJ5ZWXZIXXDVQNBDI5BB757L3TN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Introduce constants in Python (constant name binding)

2021-05-25 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/G4M4R3X5NQIJNN44OA23NLRDOHAFB32K/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Introduce constants in Python (constant name binding)

2021-05-25 Thread Shreyan Avigyan
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 name to point to a 
different data. The only way the data the constant points can get deallocated 
is if it goes out of scope, the program exits or the constant is manually `del` 
by the user. The proposed syntax is as follows,

constant x = 10
constant y = ["List"]
constant z: str = "Hi"

Thanking you,

With Regards
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/WEFUZH5P4RI47C44ULCBGM7MUVW5D6GA/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-25 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MQVLOF2EJ2GYHTIMYAQAHE55TV5CTZHO/
Code of Conduct: http://python.org/psf/codeofconduct/


[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 new 
> references to the object.

Well I thought about constant name binding with freeze protocol but it didn't 
seem to be Pythonic. So I changed my initial idea to have constant name 
binding. Now we can create multiple references.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/EFDQMW4JBQ4F7ZQYQRU3DGB6DLJFSMWL/
Code of Conduct: http://python.org/psf/codeofconduct/


[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 this is a 
convention. mypy will detect it. *But* I have a feeling that constants can have 
performance improvements though I'm not sure.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/2T4N5GCN6VWNZM5T7RXKSRDXSTSRVZBX/
Code of Conduct: http://python.org/psf/codeofconduct/


[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 
neither change the variable to point to another value nor the value itself 
anymore. For example, if we have a list we cannot change it. If we try to then 
"Error". So for lists,

constant variable = ["List"]
variable.append("Some") # Error
variable = ["Another"] # Error

Usually if we have a constant we don't create another reference to it. So do 
not support two references. Why not? Many reasons, especially deallocation 
problems.

Thanking you,
With Regards
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/V2CJQ5C5TYZGOCI5P5BHBTHJZFTT6WTX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Shreyan Avigyan
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.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/NCKWLCRIFHYNYC4UIAN32CK3GLIXUSGQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: symbolic math in Python

2021-05-19 Thread Shreyan Avigyan
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 modules that 
support symbolic math like sympy. People usually doesn't use symbolic math in 
Python but those who do know the drawbacks and have already come up with hacks 
to overcome those.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/NBBNTKTXTUXR2CQEQ5JQ3G3X2NICPLXA/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/H4XAZ35SEALD7ORI2J4NWEW4HSFHROGO/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Fractions vs. floats - let's have the cake and eat it

2021-05-18 Thread Shreyan Avigyan
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 me I'd move on to 
another programming language if this change was brought to Python. This is one 
of the things that doesn't fit in my brain.). Python is a simple language and 
we, the community, like to keep it simple. Yes we can extend it by providing 
more changes that improve performance or by adding functionality to third-party 
modules but introducing this big a change is not a great idea. But yeah I could 
be wrong.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/NFQOL57LVLQ6UBBKQCKPUQMTI2L4Q4FU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-17 Thread Shreyan Avigyan
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 result in more
> confusion and more difficult error analysis.

Exactly. That's what I have been trying to phrase.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/ARFMB5LRYQKJHFBTHBD542KRR3PGYFA5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Python 3.10: ranges in pattern matching

2021-05-17 Thread Shreyan Avigyan
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.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/VATPCBPSBWYXJA5V4NPLDEABU5GUI7F5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Python 3.10: ranges in pattern matching

2021-05-17 Thread Shreyan Avigyan
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 checking" other than a pair of inequalities?

Range here means that a range or a list. Of What? A list between two numbers, 
characters, etc. Python interprets numbers, characters as a kind of PyObject. 
Yes it makes sense to have ranges of int and str but not for others. It doesn't 
make sense to have ranges for some and not for others. And as you demonstrated 
there's a current approach to use <= x <= to have ranges only for the required 
types. The current approach is very good.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/OORUNLGTGLLNEN7U4BZHE7ZVEUTLMYPS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-17 Thread Shreyan Avigyan
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.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/Y272MZQRK6GQVB2I62XOBB6FXIS3SOXJ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Python 3.10: ranges in pattern matching

2021-05-17 Thread Shreyan Avigyan
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 range? 
No. Yes we can have a guard as a range check but Valentin is suggesting to have 
a different operator for range checking. I'm don't think that's possible.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/2A6CMG2ZQT37LRMFSHGY2MH6NIVDPCH5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: division of integers should result in fractions not floats

2021-05-17 Thread Shreyan Avigyan
I'm -1 on this change. Don't get me wrong I'd love having this change in 
Python. *But* we use float not decimal.Decimal right? Why not? Because of 
memory and precisions. Decimal takes more memory than float and also 
0.33 (float) is accurate and very easy to deal with rather than 
0.121211211200134333434343 (Decimal). I believe the same reason applies 
to fractions.Fraction. It's available to users if they don't want to lose 
precision. But including it as a built-in I don't think is a good idea. And it 
will also be  a "non-pep-reading-users-concerning-change" 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 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/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZI46MHPDELBNFERXMYS4QJFMA2Z26OJC/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Python 3.10: ranges in pattern matching

2021-05-13 Thread Shreyan Avigyan
-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 send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QUPV7F4DBQLK4IF2DHKDZ4CCO3X7VUYQ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Improved multi-tasking performance through deterministic GIL hand-off

2021-05-11 Thread Shreyan Avigyan
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 re-acquire 
the GIL right? If that's what you're trying to say, Antoine Pitrou already 
solved this by implementing the "new gil" which tells that before reacquiring 
the GIL make sure that other threads have a chance to run. However as I 
confessed earlier I can be wrong and I misunderstood what you're trying to say. 
Please correct me if that's the case.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/DWGJ7RKWEVF53VDUQ5ZADYJC5OK43XYV/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-10 Thread Shreyan Avigyan
+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 (E1, E2, E3) as e:
# something

Though it would seem this way to people,
try:
# something
except E1, E2, (E3 as e):
# something

The first example I gave is much more logical. Because (E1, E2, E3) and E1, E2, 
E3 are the same thing logically.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/J7FUCBFV2TPA7SY3DYNPEBGZ354CYNFR/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-09 Thread Shreyan Avigyan
+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 
https://mail.python.org/archives/list/python-ideas@python.org/message/OEU3NVLZVFIEUIRSYONB5AQZRVMRJWF3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Adding classes to modules is a tedious job. Wait! What about introducing a slot in PyModuleDef to hold the objects?

2021-05-07 Thread Shreyan Avigyan
It's tedious to add classes one by one using PyModule_AddObject in 
PyInit_module function. Wouldn't it be much easier if there's a slot that has 
an array of all the classes in their PyObject form and it'll automatically add 
those classes. Since this is a backwards compatibility change it'll 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
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/H6VU6PKXRYZEZSDVX2JPVQOYQ7LU2PD7/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-07 Thread 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, I think no more discussion should be there regarding this. But if 
someone is interested then they are always welcome to 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 
https://mail.python.org/archives/list/python-ideas@python.org/message/QJQXRLGP424VDXNMYL3BR25KO323XSLR/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 Java.

Anyway this thread is 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/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QS45YLJ5CZARLI73UDJBAJFUGUR2CHAW/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
The problem is that whatever programming language it is, there's always a hack 
to do things. And since it also doesn't make sense to introduce readonly 
function names (What a terrible nightmare!), maybe readonly variable also 
doesn't make sense to be added. Anyway, this was quite a discussion. 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/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/I2TVA53UKSZ36DHQEIMOUMPSLWMHKPBM/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 security issues but 
instead instability. Consider this,

class A:
def __init__(self, name):
self.name = name
def create_file(self):
with open(name, "a") as file:
  name.write("something")

Now consider this,

[1]: x = A("Name")
[2]: x.create_file() # Creates a file named "Name"
[3]: x.name = "name"
[4]: x.create_file() # Creates a file named "name"

We never created a object for "name" but still there's a file named "name" out 
there. This is the work of read-only attribute. They prevent such instability 
issues.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/LCRQI233EELWOVMNI2IDMF4YXJRU4YMT/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 Python community? Private members 
may be a disaster but I don't think readonly attributes is. In fact that's what 
have been implemented for years using @property.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZDBM554BX5VRIMIQ7WIOY64FQA2NRVH3/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 modified from within the class but not outside the class.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/FH3MH426QFU7S6PQ2XJPXOBTNO4ND7XS/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/426EPANCVEGZV2AZL7MWNG67BTZMORNG
 I'm never suggesting to make member methods non-modifiable. I'm suggesting to 
add a keyword that can make **member variables** non-modifiable.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/XCLFUC7FITXGDMYZGONBKXCBUBSYAK5O/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LSOF6LE2PSHFCFLMTKQVZTA5XYUHZNNN/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 there.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/FJDBXXBIS4DIOHTGBW5WBKQRGDFN3RRD/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 and then there's a 
new account file created with that name when we never created or told to create 
that account file. And as I suggested,

> The main aim of private is to avoid modifying not accessing.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/3KI7I4GQSVWLEJ2M2FOGWLEHIQHKM2N5/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/UJKIJ35EWBUGU5FI4QRK2WWK5DKFQPKX/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-06 Thread Shreyan Avigyan
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 wrote a Extension 
module in which they would get a PyObject* as a parameter and from there they 
would manually get the attribute variable using pointer and then return the 
value. Therefore if private is implemented in Python it would be more secure 
than private in other OOPs.

The benefit of private is actually debugging. If somehow, someone finds that 
the private member has changed they would immediately know that it was a memory 
leak or the value was changed through a set method defined in the class (This 
is one of most important pillar of access modifiers in OOP). Python's private 
convention most of the time helps but since it doesn't enforce it someone just 
might introduce a bug in an application by modifying a private member. I just 
gave an example of security it was not the main point.

The main aim of private is to avoid modifying not accessing. I know @property 
can be used to turn a member variable into a non-modifiable member variable but 
that also means you can't change it inside the class also.

When applying private on functions, I think that's when it becomes private. 
You're hiding interfaces when you don't need to. In fact hiding interfaces is 
worse than hacking. Functions can't be hacked.

Conclusion


Therefore I actually kind of change my suggestion to introduce a new keyword 
that avoids modifying member variables from outside the class not the inside. 
This would preserve @property behavior plus introducing a new kind of behavior. 
 Also this member variables would be inherited.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/426EPANCVEGZV2AZL7MWNG67BTZMORNG/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-05 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/P5SBXBPZAXKHY75KKXWIAKPPSKGCYC3I/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-05 Thread Shreyan Avigyan
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 have that 
feature in OOP. Moreover why does private exist in the first place? If there's 
a reason then shouldn't it apply to Python as well. 

And yes you're right the unprivileged code can just do the same thing. But I'm 
not only speaking of security in this context.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/L5LUQDNNV5ZTF4E33L2JSOYIKPJUJJK5/
Code of Conduct: http://python.org/psf/codeofconduct/


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

2021-05-05 Thread Shreyan Avigyan
Private methods, functions and variables are very common in programming 
languages. But Python doesn't support private. It has conventions for naming so 
considered private but not private. Most of the time private is never required, 
what Python provides is more than enough. But the need for private come into 
place when we're dealing with passphrases and servers. For example consider 
this code,

class A:
def get():
// code to get the password
self.password = password

Now consider this,

>>> x = A(); x.get(); x.password

See what just happened? Someone just got the member variable value that the 
person wasn't supposed to.

I suggest to add private support for functions (module __all__ methods to be 
more clear), methods and variables (module __all__ variables or class 
variables).

(I very bad at reading PEPs so I may miss out something critical that'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 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/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DD2L56GCOCWEUBBZBDKKKMPPVWB7PRFB/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/SB7KKXMYBRYKRX25GDKVGO5OROZWW7EY/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/J5CXG2ITBLWGT2ZUWMXVGTU5DU442Q6Q/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DQ6BN5I5ZUYRYBWWBD6LCSNQ5PDHP46S/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/UFGJ2TJI3IMOVBJUBPVXCPQOBVVCENXL/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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 unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/APKN7AV5TLLNSO3EHLK2MBEEBCB5NMEF/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JSZEXJQSAJFUZTF4PWO35UQZGVH2X56X/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/AGQLYE3D6X54A524ZRIPYTAMHSI5ZEXV/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZCGQYPC2JWKNRWNNEPHQVPG5FT4NGDJZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Add switch-case statements in Python

2021-05-04 Thread Shreyan Avigyan
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 nice to have 
switch-case statements support in python.

Suggested syntax :-
---

switch expr:
case expr2:
case expr3:
statements
default:
statements


How should it be implemented?
---

First of all this will require a new syntax. Second I suggest for comparing the 
case expr with switch expr, compare the pointers instead of objects for better 
performance. Usually if the ladder is represented using if-elif-else logic then 
it would be lower performance because we'll end up comparing objects not 
pointers.
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/32SKTIZCNJP74ZJSHQ4R2R4A3ODC3LMN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Accepting a function argument of a particular type specified by the user

2021-04-25 Thread Shreyan Avigyan
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 python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CKOSXKYYWTDDIA3JIKNPJMUW7P536IK7/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Accepting a function argument of a particular type specified by the user

2021-04-25 Thread Shreyan Avigyan
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 -- 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 
https://mail.python.org/archives/list/python-ideas@python.org/message/D6SETA5RVNAWKEYI7Z6HK6D7YIPG7QVJ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Accepting a function argument of a particular type specified by the user

2021-04-25 Thread Shreyan Avigyan
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 types. Like,

def example(c):
print(c)
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/BSE7RQ5EL2EFLYY6LTZRY5FARKN2XZW4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Accepting a function argument of a particular type specified by the user

2021-04-25 Thread Shreyan Avigyan
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 it to be,

def add(a, b):
if type(a) == int and type(b) == int:
return a +b
raise Exception("Error")

In this example it's pretty easy to check if the arguments are int. But in real 
world programs as the functions become bigger and bigger it's very difficult to 
check arguments using an if statement.  Therefore why not let the user specify 
what parameter types are gonna be? Like,

def add(int a, int b):
return a + b

If instance of a different class is passed in then raise a TypeError perhaps? 
If parameter types are not given then let the parameter accept any kind of 
class instance.

This kind of functionality will minimize a lot of if statements related to 
parameter types and arguments.

Thanking you,
With Regards
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/MVUE5CVE2KXCA6B3TEBUOOFGKRT2HRNK/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Why not deprecate Py_XDECREF in a future python version? Maybe a DeprecationWarning for now?

2021-04-15 Thread Shreyan Avigyan
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 it isn't NULL, why have an 
unnecessary branch? And it's true. It would have to execute one more step (the 
if block) every time Py_DECREF is used when it is actually not needed.

Moreover I thought about what you said Serhiy about breaking every bit of code. 
Actually I knew it would break that's why I said in future Python version.

But anyway it's not necessary to change Py_DECREF and moreover deprecating 
Py_XDECREF would cause even more problem.

Thanking you,
With Regards
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/U5MWF7FHQDPFBZ3M3SYFWNLVUCRSDT3E/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Why not deprecate Py_XDECREF in a future python version? Maybe a DeprecationWarning for now?

2021-04-15 Thread Shreyan Avigyan
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? Why not use a DeprecationWarning for now 
and plan to deprecate Py_XDECREF in the near future?
How about implementing an if statement in Py_DECREF to make it work like 
Py_XDECREF?

Thanking you,

With Regards
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/TDXJZJF35JF2WVZXE6L6EIJRZSKLSZBU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Change the exception type and message raised when _curses is not found

2021-04-05 Thread Shreyan Avigyan
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 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 should be the perfect solution?
>
> There’s no need for a new exception type. What code would catch this new
> exception? Just update the text of the existing exception, and update the
> documentation if need be.
>
> There’s no need for a PEP. Many, many changes are made without PEPs. Just
> open an issue on bugs.python.org and create a PR.
>
> Eric
>
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/PSPTM73FBEF6AK5QQGDRIO7BZVDJ27NS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Change the exception type and message raised when _curses is not found

2021-04-05 Thread Shreyan Avigyan
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 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 
https://mail.python.org/archives/list/python-ideas@python.org/message/KBLLX4FXYVX7CXLYRNAGVBSNWKUJVT3L/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Change the exception type and message raised when _curses is not found

2021-04-05 Thread Shreyan Avigyan
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 should be the perfect 
solution?
___
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 
https://mail.python.org/archives/list/python-ideas@python.org/message/J3UTLI56TUMMDVOPSO27PDGIZLKWZDA5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Change the exception type and message raised when _curses is not found

2021-04-05 Thread Shreyan Avigyan
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 send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WFAAHYKNZCRMCZZNV2WFLKK6IGZR/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Change the exception type and message raised when _curses is not found

2021-04-04 Thread Shreyan Avigyan
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 Python 
interpreter itself at first it may seem, to beginners especially, that the 
Python interpreter was not installed correctly and then they would go searching 
for an answer for about 4-5 days. 

We know that curses library is not installed on windows by default and may or 
may not be present on other operating systems. Most UNIX system have ncurses or 
other curses library installed by default. 

Python errors have a reputation of being very informational. I would like to 
submit a PR to modify the curses module a little bit by declaring a 
BaseException class and raising that Exception with the message "_curses module 
not found. Make sure a curses library is installed" or some kind of message 
like that.

But before I do that I would like to take advice from experienced developers 
about somethings. Is this change in the exception, raised when _curses module 
is not found, acceptable by the Python Community? If it is then 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 send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BY7L2DM4HL26V4CZTXH5F4YTHQ2MRRZM/
Code of Conduct: http://python.org/psf/codeofconduct/