[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Serhiy Storchaka
05.12.19 21:07, Guido van Rossum пише: The case for findfirst() becomes stronger! There seem plenty of ways to get this wrong. I write several functions every day. There are many ways to get this wrong. But I do not propose to include all these functions in the stdlib. If I want to include ev

[Python-ideas] Re: lowercase exception names trip-up .

2019-12-05 Thread Serhiy Storchaka
05.12.19 21:25, Matthias Bussonnier пише: I've been tripped up a couple of time by a few Exception names being lower case both in code and tracebacks. In particular `error` (all lower case) I tend to read `error` as a function instead of a class. According to my non-scientific grep-foo, I find

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Serhiy Storchaka
05.12.19 23:47, Kyle Stanley пише: Serhiy Storchaka wrote: > We still do not know a use case for findfirst. If the OP would show his > code and several examples in others code this could be an argument for > usefulness of this feature. I'm not sure about the OP's exact

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Serhiy Storchaka
06.12.19 04:31, Guido van Rossum пише: (There are apparently subtle differences between re.search() and re.findall() -- not sure if they matter in this case.) There is no any differences. Also, analyzing examples from GitHub, in most cases the pattern contains no or single group, so the code

[Python-ideas] Re: Argumenting in favor of first()

2019-12-06 Thread Serhiy Storchaka
06.12.19 00:09, Ethan Furman пише: I haven't followed the main thread, but I can unequivocally state that for-loop version is easier to read. I completely agree.   The only thing missing to make the intent crystal clear is one more word in the function name:     def get_first_product_item(

[Python-ideas] Re: Argumenting in favor of first()

2019-12-06 Thread Serhiy Storchaka
06.12.19 07:38, Steven D'Aprano пише: I'm sorry, I can't tell what that is supposed to do. Is the "return {}" supposed to be inside the loop? If so, it has been accidentally dedented. Is it meant to be outside the loop? The "for-else" is redundent, since there is no break. for item in jsonl

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-06 Thread Serhiy Storchaka
06.12.19 19:49, Random832 пише: If match objects are too hard to use, maybe they should be made more user-friendly? What about adding str and iterable semantics to match objects so it can be used as str(re.search(...)); tuple(re.search(...)); a, b = re.search(...)? What is semantic of these

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-06 Thread Serhiy Storchaka
06.12.19 23:21, Random832 пише: On Fri, Dec 6, 2019, at 15:17, Serhiy Storchaka wrote: 06.12.19 19:49, Random832 пише: If match objects are too hard to use, maybe they should be made more user-friendly? What about adding str and iterable semantics to match objects so it can be used as str

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-06 Thread Serhiy Storchaka
06.12.19 23:20, Kyle Stanley пише: Serhiy Storchaka wrote: > It seems that in most cases the author just do not know about > re.search(). Adding re.findfirst() will not fix this. That's definitely possible, but it might be just as likely that they saw re.findall() as being more si

[Python-ideas] Re: Argumenting in favor of first()

2019-12-09 Thread Serhiy Storchaka
09.12.19 07:41, Guido van Rossum пише: Nobody is going to write a blog post about 2-arg next() (there just isn't enough for more than a sentence or two) but people write tutorials about itertools all the time, since it's such a rich module. So I think it's likely that first() will get some expo

[Python-ideas] Re: Argumenting in favor of first()

2019-12-12 Thread Serhiy Storchaka
12.12.19 03:22, Stephen J. Turnbull пише: I would prefer that it not be implemented at all, but if it is implemented, its behavior should respect the intuition of the majority of those who want it, which seems to me to be "a variant of next() that doesn't raise and returns None by default on an e

[Python-ideas] Re: Argumenting in favor of first()

2019-12-12 Thread Serhiy Storchaka
11.12.19 10:45, Steven D'Aprano пише: The thing is, we're fooled by the close similarity of iteration over iterators and other iterables (sequences and containers). Destructive iteration and non-destructive iteration is a big difference. Utility functions like the proposed `first` that try to pre

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

2019-12-15 Thread Serhiy Storchaka
14.12.19 23:37, komissar.off.and...@gmail.com пише: Hello! I think it will be useful in Python syntax if we can use "elif" in "for" and "while" statements besides "else" Example for i in range(j): ... elif i > 5: ... else: ... What you think about this change? I sometimes with

[Python-ideas] Re: Argumenting in favor of first()

2019-12-15 Thread Serhiy Storchaka
13.12.19 12:45, Steven D'Aprano пише: On Fri, Dec 13, 2019 at 09:24:20AM +0200, Serhiy Storchaka wrote: 12.12.19 03:22, Stephen J. Turnbull пише: I would prefer that it not be implemented at all, but if it is implemented, its behavior should respect the intuition of the majority of thos

[Python-ideas] Re: __eq__ and __ne__

2019-12-27 Thread Serhiy Storchaka
27.12.19 18:00, Siddharth Prajosh пише: Why do we need separate functions for == and != ? Isn't this supposed to be negation of each other? Because __eq__ and __ne__ can return not only bool. For example, for NumPy arrays they return arrays of bools. _

[Python-ideas] Re: more readable "if" for multiple "in" condition

2019-12-31 Thread Serhiy Storchaka
31.12.19 08:20, iman.h.a.kha...@gmail.com пише: Hi I think the following syntax's: if foo in foobar or bar in foobar or baz in foobar: pass if foo in foobar and bar in foobar and baz in foobar: pass can be more readable and shorter if written as: if foo or bar or baz in foobar:

[Python-ideas] Re: Add a PyObject_VaCallFunction to C API??

2020-01-06 Thread Serhiy Storchaka
06.01.20 00:20, hrfu...@gmail.com пише: I've worked out MyCallFunction() in my actual code in the same manner described above, but with Py_VaBuildValue. What I did was I send all variadic arguments to a MyBuildValue(PyObject*, const char*, ...), the in the .c file, MyBuildValue will generate a

[Python-ideas] Re: Perhaps allow leading zeroes in integer literals

2020-02-06 Thread Serhiy Storchaka
06.02.20 14:03, Jonathan Fine пише: >>> 001 SyntaxError: invalid token The error message was improved in the latest Python: 001 File "", line 1 SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers 1. It was good to remove from Py

[Python-ideas] Re: `raise as` to raise with current exception as cause

2020-02-07 Thread Serhiy Storchaka
07.02.20 16:28, Ram Rachum пише: The idea is to add `raise as` syntax, that raises an exception while setting the currently caught exception to be the cause. It'll look like this:     try:         1/0     except ZeroDivisionError:         raise as ValueError('Whatever') What it does is a

[Python-ideas] Re: Pickle to/from filename or path

2020-02-07 Thread Serhiy Storchaka
07.02.20 20:41, Antoine Pitrou пише: What you call "quite a bit of boilerplate" is just an additional line of code. If you are frequently being bothered by this (I'm curious what the context is?), it's easy to add the desired helper function to your own library. In general, I don't think adding

[Python-ideas] Re: Add Binary module.

2020-02-16 Thread Serhiy Storchaka
16.02.20 17:21, ananthakrishnan15.2...@gmail.com пише: I'll show the example using one's and two's complement. binary.ones_complement(1101100001) 0010011110 binary.twos_complement(1101100001) 001001 What is the type of the result of binary.ones_complement() and binary.

[Python-ideas] Add a way to execute code in the context of different frame

2020-02-17 Thread Serhiy Storchaka
The idea is inspired by the following StackOverflow question: https://stackoverflow.com/questions/40945752/inspect-who-imported-me and the corresponding BPO issue: https://bugs.python.org/issue39643. In the older Python versions the f_back attribute of the frame in which the module code is exe

[Python-ideas] Add __keys__ or __items__ protocol

2020-02-18 Thread Serhiy Storchaka
It is hard to distinguish a sequence and a mapping in Python 3. Both have __getitem__, __len__ and __iter__ methods, but with different semantic. In Python code you can use isinstance() and issubclass() checks against collections.abc.Mapping, but it works only with types which was explicitly r

[Python-ideas] Re: Add a way to execute code in the context of different frame

2020-02-18 Thread Serhiy Storchaka
18.02.20 11:28, M.-A. Lemburg пише: This sounds like a nice idea, but it may make sense to limit the frame to one already on the stack. Otherwise, the code you're executing may never return to your current stack... I do not think there will be such problem. exec() will temporary replace the st

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Serhiy Storchaka
18.02.20 10:34, Chris Angelico пише: Given that that's already been the case, my preferred colour for the bike shed is... Thank you for your feedback. This is my preferable color too, for both parts. ___ Python-ideas mailing list -- python-ideas@pyt

[Python-ideas] Re: Add a way to execute code in the context of different frame

2020-02-18 Thread Serhiy Storchaka
18.02.20 20:13, Guido van Rossum пише: I am a little confused how you get from "there are extra frames in the traceback" to "modify exec() to run code in another frame". Sorry for skipping several steps. I'll try to expand them here. PEP 558 does not have relation to this, as frame is not the

[Python-ideas] Re: Add __keys__ or __items__ protocol

2020-02-18 Thread Serhiy Storchaka
18.02.20 19:00, Soni L. пише: I like __items__. additionally, lists should implement it to return enumerate(self), and sets should implement it to return (v, v for v in self), and as such there should be no requirement with regards to __items__ and __iter__, and whether __iter__ returns keys or

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-20 Thread Serhiy Storchaka
20.07.11 23:48, Sven Rahmann пише: At the moment, the array module of the standard library allows to create arrays of different numeric types and to initialize them from an iterable (eg, another array). What's missing is the possiblity to specify the final size of the array (number of items), esp

[Python-ideas] Re: Specify number of items to allocate for array.array() constructor

2020-02-21 Thread Serhiy Storchaka
21.02.20 10:36, Steven D'Aprano пише: On my machine, at least, constructing a bytes object first followed by an array is significantly faster than the alternative: [steve@ando cpython]$ ./python -m timeit -s "from array import array" "array('i', bytes(50))" 100 loops, best of 5: 1.71 msec pe

[Python-ideas] Re: Proposal: Complex comprehensions containing statements

2020-02-22 Thread Serhiy Storchaka
22.02.20 09:43, David Mertz пише: Comprehension are very much based on the idea of *declarative* data collections. That's their entire reason for being. In general, one expects comprehension to be side-effect free and just build a collection according to declared rules. Obviously I know many wa

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-23 Thread Serhiy Storchaka
23.02.20 23:51, Aaron Hall via Python-ideas пише: This is not a fully baked idea, perhaps there's a good reason we haven't added a binary `~`.  It seems like I've seen discussion in the past. But I couldn't find such discussion. And as I'm currently taking some statistics courses, I'm getting R

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-24 Thread Serhiy Storchaka
24.02.20 02:27, Aaron Hall via Python-ideas пише: I have no behavior for integers in mind. I would expect high-level libraries to want to implement behavior for it. - sympy - pandas, numpy, sklearn, statsmodels - other mathematically minded libraries (monadic bind or compose?) To do this we ne

[Python-ideas] Re: Make ~ (tilde) a binary operator, e.g. __sim__(self, other)

2020-02-24 Thread Serhiy Storchaka
24.02.20 22:02, Guido van Rossum пише: Hm, that's actually an interesting take. Can you compare it to the kind of "quoting" that happens in a lambda? Is there some kind of translation of the OP's original example (Lottery ~ Literacy + Wealth + Region) to a lambda involving those words? I thin

[Python-ideas] Re: Exception for parameter errors

2020-03-04 Thread Serhiy Storchaka
04.03.20 09:06, Steven D'Aprano пише: Proposal: add a new exception, ParameterError, for parameter errors. For backwards compatibility it would have to be a subclass of TypeError. If add such exception, ArgumentError looks more appropriate name. Where the interpreter now raises TypeError for

[Python-ideas] Re: Allow star unpacking within an slice expression

2020-03-06 Thread Serhiy Storchaka
06.03.20 18:30, Neil Girdhar пише: Reviving this old thread since this is hitting me again today.  Is there any momentum on extending tuple unpacking to within slices? It does not supported by AST. But with issue34822 changes it could be implemented. https://bugs.python.org/issue34822 __

[Python-ideas] Re: More appropriate behavior for the NotImplemented object

2020-03-11 Thread Serhiy Storchaka
11.03.20 12:39, Steven D'Aprano пише: https://bugs.python.org/issue35712 I am disappointed because, to me, it is a fundamental part of Python's object model that *everything* can be interpreted as a truthy/falsey object (in the absence of bugs). NotImplemented is special. It is more special th

[Python-ideas] Re: More appropriate behavior for the NotImplemented object

2020-03-11 Thread Serhiy Storchaka
12.03.20 08:08, Ben Rudiak-Gould пише: There are some cases in the standard library, e.g. >>> import dbm.dumb >>> db = dbm.dumb.open('foo') >>> db.close() >>> not db Traceback (most recent call last): File "", line 1, in OSError: DBM object has already been closed mmap.m

[Python-ideas] Re: Make `del x` an expression evaluating to `x`

2020-03-13 Thread Serhiy Storchaka
12.03.20 17:02, Eric Wieser пише: >>> [id(v) for v in itertools.combinations([1, 2, 3], 1)] [2500926200992, 2500926199072, 2500926200992] Note that the first id is repeated for third item. And if you use larger example >>> [id(v) for v in itertools.combinations(range(10), 1)] [13

[Python-ideas] Re: Limit 'import as' syntax

2020-03-30 Thread Serhiy Storchaka
30.03.20 15:50, jope...@hotmail.fr пише: As a result, `import os.path as p` stores os.path, not os, in p. This makes it effectively the same as `from os import path as p` No, it is not the same. For example, `from os import mkdir as mkd` works, but `import os.mkdir as mkd` is an error. _

[Python-ideas] Re: Explicitly defining a string buffer object (aka StringIO += operator)

2020-03-30 Thread Serhiy Storchaka
30.03.20 20:07, Andrew Barnert via Python-ideas пише: Sadly, this isn’t possible. Large amounts of C code—including builtins and stdlib—won’t let you duck type as a string; as it will do a type check and expect an actual str (and if you subclass str, it will ignore your methods and use the PyUnico

[Python-ideas] Re: Explicitly defining a string buffer object (aka StringIO += operator)

2020-03-30 Thread Serhiy Storchaka
30.03.20 20:27, Chris Angelico пише: def __iadd__(self, s): self.data.append(s) __iadd__ should return self. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.pytho

[Python-ideas] Re: Compound with .. else statement

2020-03-30 Thread Serhiy Storchaka
31.03.20 00:27, Jimmy Thrasibule пише: In my situation, I would like to mix the `with` statement with `else`. In this case I would like that if no exception is raised within the `with` to run the `else` part. It is easy. You do not need "else". with my_context(): do_something_sensitive()

[Python-ideas] Re: Compound with .. else statement

2020-03-31 Thread Serhiy Storchaka
31.03.20 01:32, Christopher Barker пише: In case Serhiy's answer wasn't clear: context managers can be written to handle exceptions (within their context) in any way you see fit. that is: the method: | | |__exit__(||self||, exc_type, exc_value, exc_traceback):| get the exception, and informati

[Python-ideas] Re: Issue 34850: Syntax Warning in the real world (is 0 / is 1)

2020-03-31 Thread Serhiy Storchaka
31.03.20 20:21, Andrew Barnert via Python-ideas пише: Do you have code that you think actually _should_ be using is 1? Or code that you have to compile over and over (e.g., your deployment server doesn’t cache .pyc files, or you spawn new instances all the time without pre-built .pycs, or your

[Python-ideas] Re: returning a namedtuple on dict.items()

2020-03-31 Thread Serhiy Storchaka
31.03.20 20:15, Nadav Wexler пише: Hi, That is my first post here, I hope it's the right place for it. so I was using some dicts had the following code:         env = dict(t for t in os.environ.items() if 'SUBSTRING' not in t[0]) and I thought: It could have really been nice if i could do:

[Python-ideas] Re: PEP 9999: Retire animal-unfriendly language

2020-03-31 Thread Serhiy Storchaka
31.03.20 20:52, Antoine Pitrou пише: Your search is incomplete, for example you failed to account for occurrences of "cheese" and "milkshake". I thought palm trees are plants. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe sen

[Python-ideas] Optimize out unused variables

2020-04-08 Thread Serhiy Storchaka
I doubted whether or not to write, but since Guido has already touched a similar topic (see "Live variable analysis -> earlier release"), so will I write. It is common to assign some values which are never used to variables because the syntax demands this. For example: head, _, rest = pa

[Python-ideas] Re: Optimize out unused variables

2020-04-09 Thread Serhiy Storchaka
09.04.20 00:54, Andrew Barnert via Python-ideas пише: Could you go so far as to remove the variable from the locals if its only assignment(s) are optimized out? I’m not sure how much benefit that would provide. (Surely it would sometimes mean an f_locals array fits into one cache line instead

[Python-ideas] Re: Optimize out unused variables

2020-04-09 Thread Serhiy Storchaka
09.04.20 03:46, Henk-Jaap Wagenaar пише: I like the idea of formalizing "unused variables". How about having a syntax for it? Allowing a "." instead of an identifier to signify this behaviour [reusing Serhiy's examples]: head, ., rest = path.partition('/') first, second, *. = line.split() for

[Python-ideas] Re: RFC: For Loop Invariants

2020-04-10 Thread Serhiy Storchaka
10.04.20 23:21, Elliott Dehnbostel пише: If I've done this incorrectly, please let me know so that I can improve/revise. I'm new to the Python community and quite enjoy the more functional features of Python 3, but have I have a peeve about it. I'd like to propose and discuss the following enha

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-21 Thread Serhiy Storchaka
20.04.20 23:33, Andrew Barnert via Python-ideas пише: Should this print 1 or 2 or raise StopIteration or be a don’t-care? Should it matter if you zip(y, x, strict=True) instead? It should print 2 in both cases. The only way to determine whether the iterator ends is to try to get its next valu

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-21 Thread Serhiy Storchaka
21.04.20 11:49, Ram Rachum пише: There is more interesting example:      x = iter(range(5))      y = [0]      z = iter(range(5))      try:          zipped = list(zip(x, y, z, strict=True))      except ValueError: # assuming that’s the exception you want?  

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-21 Thread Serhiy Storchaka
21.04.20 11:15, Antoine Pitrou пише: Of course, the fact that zip() is the shorter form that everyone is used to means that, even if a `strict` argument is added, few people will bother adding it. The possible solution is to introduce zip_shortest() with the current behavior of zip(), make zip

[Python-ideas] Re: zip should return partial results in StopIteration

2020-04-21 Thread Serhiy Storchaka
21.04.20 17:10, Soni L. пише: I feel like zip could return partial results: try:   next(zip([0], [])) except StopIteration as exc:   assert StopIteration.args == (0,) how much would this break? Why do you need this feature? ___ Python-ideas mailin

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-21 Thread Serhiy Storchaka
21.04.20 19:35, Paul Moore пише: Hence my suggestion that maybe it's not so much an (actionable) exception that people want as an assertion. What do you mean by assertion? Raising an AssertionError? Crashing the program? ___ Python-ideas mailing lis

[Python-ideas] Re: zip should return partial results in StopIteration

2020-04-22 Thread Serhiy Storchaka
22.04.20 08:11, Greg Ewing пише: I don't this should be a guarantee, in this or any similar situation. The only purpose for the value in a StopIteration is to provide a return value for yield-from when the thing being delegated to is a generator. If you're yielding from something that's not a gen

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-22 Thread Serhiy Storchaka
22.04.20 11:20, Antoine Pitrou пише: Ideally, that's what it would do. Whether it's desirable to transition to that behaviour is an open question. But, as far as I'm concerned, the number of times where I took advantage of zip()'s current acceptance of heteregenously-sized inputs is extremely s

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-24 Thread Serhiy Storchaka
24.04.20 07:58, Andrew Barnert via Python-ideas пише: And not only that, the PEP for this first step has to make it clear that it’s useful on its own—not just to people like Serhiy who eventually want to replace zip and see it as a first step, but also to people who do not want zip to ever cha

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Serhiy Storchaka
29.04.20 17:56, Ram Rachum пише: Thanks everybody for your answers, and especially Ricky for finding this note. Please not that the optimization mentioned in the comment still keeps the linear complexity for these operations. It just reduces the constant multiplier. _

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-01 Thread Serhiy Storchaka
01.05.20 09:48, Ram Rachum пише: I wish there were a 100 more built-in exceptions in Python, that will be very specific about what went wrong. If I do this:     >>> x, y = range(3) I know it'll raise a ValueError, because I've memorized that, but it did take me a few years to remember where

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-01 Thread Serhiy Storchaka
01.05.20 10:32, Ram Rachum пише: On Fri, May 1, 2020 at 10:28 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: Could you please provide a list of these 100 exceptions? If you create a PR, with documentation and tests, it would be a good start of the discussion.

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-02 Thread Serhiy Storchaka
02.05.20 21:34, Ahmed Amr пише: I see there are ways to compare them item-wise, I'm suggesting to bake that functionality inside the core implementation of such indexed structures. Also those solutions are direct with tuples and lists, but it wouldn't be as direct with arrays-lists/tuples compa

[Python-ideas] Re: Equality between some of the indexed collections

2020-05-02 Thread Serhiy Storchaka
02.05.20 23:32, Alex Hall пише: On Sat, May 2, 2020 at 9:51 PM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: 02.05.20 21:34, Ahmed Amr пише: > I see there are ways to compare them item-wise, I'm suggesting to bake > that functionality inside the co

[Python-ideas] General methods

2020-05-08 Thread Serhiy Storchaka
Methods in Python are defined as functions in the class namespace. When call the method of the object, the function will be called with the object as the first argument. And furthermore, unbound methods can be called with passing self as the first argument. For example, str.upper('abc') returns

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

2020-05-11 Thread Serhiy Storchaka
10.05.20 10:09, Steve Barnes пише: 4. Start accepting hyphens as minus & Unicode quotation marks – this would be the ideal answer for pasted code but has a lot of possible things to iron out such as do we require that the quotes match and are in the typographically correct order. It

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

2020-05-11 Thread Serhiy Storchaka
11.05.20 03:34, Steven D'Aprano пише: There are a couple of professionally published Python books written using Restructed Text, Sphinx and Python. So people do have a choice, or at least a technical choice. There was similar issue with Sphinx. It uses a third-party tools to "improve" the HTML

[Python-ideas] Re: type hints : I'd like to suggest allowing unicode → as an alternative to ->

2020-05-20 Thread Serhiy Storchaka
17.05.20 13:47, Thierry Parmentelat пише: well it’s all in the title the specific character that I am referring to is this one In [1]: print("\u2192”) → https://unicode-table.com/en/2192/ —— just curious about how people would feel about taking better advantage of non-ascii characters when

[Python-ideas] Re: type hints : I'd like to suggest allowing unicode → as an alternative to ->

2020-05-21 Thread Serhiy Storchaka
21.05.20 16:45, Alex Hall пише: ≥ instead of >= might be an improvement because that's a symbol learned in school, but ultimately the student still needs to learn what `>=` means as it will be used most of the time. But in my school I learned ⩾, not ≥. It was used in USSR and I believe in oth

[Python-ideas] Re: An HTTP API to list versions of Python

2020-05-28 Thread Serhiy Storchaka
27.05.20 21:10, Christian Heimes пише: Barry and Guido own the Python project on PyPI, https://pypi.org/project/Python/ . There hasn't been an update since 2.5.0 in 2007. There are also https://pypi.org/project/python2/ https://pypi.org/project/python4/ https://pypi.org/project/cPython/ which

[Python-ideas] Re: Allowing assertEqual etc to take multiple items

2020-05-28 Thread Serhiy Storchaka
28.05.20 11:02, Ram Rachum пише: I recently submitted this PR , and I had to use assertSequenceEqual twice, just because I wanted to compare 3 sequences to each other rather than 2. You have wrote much more text in this message

[Python-ideas] Re: Expose PyFloat_AsDouble to Python

2020-05-29 Thread Serhiy Storchaka
29.05.20 12:48, Mark Dickinson пише: 2. Call the object's `__float__` method. But this is fraught with peril, too: for a proper equivalent, you need to be careful to look up `__float__` on the type, not the object itself. And then a new version of Python changes `PyFloat_AsDouble` to also acce

[Python-ideas] Re: Expose PyFloat_AsDouble to Python

2020-05-29 Thread Serhiy Storchaka
29.05.20 14:22, Serhiy Storchaka пише: I prefer it to be an alternative float constructor. We can also add the corresponding constructor for complex, and add constructors which accept only str, bytes or bytes-like object (i.e. parse a text representation of the number). See also previous

[Python-ideas] Re: Augment abc.Set API (support named set methods for dictionary view objects)

2020-06-01 Thread Serhiy Storchaka
01.06.20 18:28, Raymond Hettinger пише: On Jun 1, 2020, at 3:32 AM, a...@yert.pink a...@yert.pink wrote: I propose that the `Set` ABC API should be augmented to contain all of the named methods. This would provide consistency in the collections, and enhance the duck typing capabilities of th

[Python-ideas] Re: Bringing the print statement back

2020-06-10 Thread Serhiy Storchaka
10.06.20 03:06, Guido van Rossum пише: No, it's not April 1st. I am seriously proposing this (but I'll withdraw it if the response is a resounding "boo, hiss"). Well you have my "boo, hiss". I like programming languages which have such feature, but they have it from start, it is an integral pa

[Python-ideas] Re: json library: non-standards-compliant by default, and what to do about it.

2020-06-16 Thread Serhiy Storchaka
17.06.20 08:29, Steven D'Aprano пише: What exactly is getting in the way here? Standards do change. One standard (JSON) is not capable of representing all values from another standard (IEEE-754). Removing NANs and INFs would break floating point software everywhere, and a lot of hardware too. Add

[Python-ideas] Re: json library: non-standards-compliant by default, and what to do about it.

2020-06-16 Thread Serhiy Storchaka
17.06.20 08:42, David Mertz пише: I think the argument 'allow_nan' is poorly spelled. Spelling it 'strict' would have been much better. Maybe 'conformant'. I'm not sure I hate the spelling enough to propose a change with depreciation period, but I certainly wouldn't oppose that. It is not onl

[Python-ideas] Re: Support infinite temporal types

2020-06-16 Thread Serhiy Storchaka
16.06.20 13:54, Alexander Hill пише: I’d like to propose support for infinite dates, datetimes and timedeltas. They're very useful when you need to model ranges with one or both ends unbounded (e.g. “forever starting from June 15th 2020”). Without first-class infinite values, you can use None,

[Python-ideas] Re: "return if "

2020-06-19 Thread Serhiy Storchaka
18.06.20 15:30, Daniel. пише: I love the do_stuff if cond syntax in Ruby and in perl. It's very natural to real, much more to follow than if cond: do_stuff But still I don't think that it is enough to demand a language change. Something near this is to have a default of none for A if B else N

[Python-ideas] Re: Proposal to introduce pattern matching syntax

2020-06-22 Thread Serhiy Storchaka
22.06.20 18:17, nate lust пише: Matching begins by calling a __match__ (class)method on the type, with the match target as a parameter. The match method must return an object that can be evaluated as a bool. If the return value is True, the code block in this match branch is executed, and execu

[Python-ideas] Re: Please consider adding numbers.Boolean

2020-06-22 Thread Serhiy Storchaka
22.06.20 03:19, Neil Girdhar пише: I'm just curious if there was a reason why Boolean was omitted from the numeric tower in the numbers library?  It seems that builtins.bool and numpy.bool_ would both be elements of Boolean, and Boolean itself would be Integral? The abstract class for boolean

[Python-ideas] Re: json library: non-standards-compliant by default, and what to do about it.

2020-06-27 Thread Serhiy Storchaka
27.06.20 11:58, Steven D'Aprano пише: The JSON standard didn't just accidently fail to specify what to do with NANs and INFs. It mandates that they are turned into null. JSON is designed to take your numeric data and throw values away, and this is a real problem for people: Could you please giv

[Python-ideas] Re: json library: non-standards-compliant by default, and what to do about it.

2020-06-27 Thread Serhiy Storchaka
27.06.20 10:23, Steven D'Aprano пише: On Wed, Jun 17, 2020 at 09:18:00AM +0300, Serhiy Storchaka wrote: Adding NANs and INFs to JSON will break virtually every software which reads JSON because many (most?) of existing standard-conforming implementations do not support them. It won&#x

[Python-ideas] Re: An alternative way of defining properties (warning: contains creative abuse of the class statement)

2020-07-02 Thread Serhiy Storchaka
02.07.20 10:12, Greg Ewing пише: The @property.getter and @property.setter decorators are clever, but they have the disadvantage that you end up writing the name of the property no less than 5 times, all of which have to match. 5 times? How is it? Thinking there must be a better way, I came u

[Python-ideas] Re: An alternative way of defining properties (warning: contains creative abuse of the class statement)

2020-07-02 Thread Serhiy Storchaka
02.07.20 13:26, Greg Ewing пише: On 2/07/20 8:04 pm, Serhiy Storchaka wrote: It has a problem with pickling (it is solvable). Can you elaborate? The end result is a property object just the same as you would get from using @property or calling property directly. I don't see how it can

[Python-ideas] Re: Add __eq__ to colletions.abc.Sequence ?

2020-07-04 Thread Serhiy Storchaka
30.06.20 18:58, Joao S. O. Bueno пише: I ended up writting an __eq__ - and in the process I found it is not _that_ straightforward  due to  having to check subclasses types when comparing. (given Base sequence A, child class B(A), class C(A) and class B1(B) - Instances of B and B1 can be equal,

[Python-ideas] Re: Allowing -b (BytesWarning) to be activated in other ways

2020-07-16 Thread Serhiy Storchaka
16.07.20 20:05, Brett Cannon пише: I honestly wouldn't expect that flag to last forever because it exists purely to help with Python 2 -> 3 transitions. Since it fundamentally changes how things like comparison and `str()` work it isn't something to flip on needlessly and you would be better of

[Python-ideas] Re: add !p to pprint.pformat() in str.format() an f-strings

2020-07-25 Thread Serhiy Storchaka
16.07.20 07:34, Charles Machalow пише: Right now in str.format(), we have !s, !r, and !a to allow us to call str(), repr(), and ascii() respectively on the given expression. I'm proposing that we add a !p conversion to have pprint.pformat() be called to convert the given expression to a 'prett

[Python-ideas] Re: Faster object representation for UIs

2020-07-25 Thread Serhiy Storchaka
24.07.20 18:10, Gábor Bernát пише: I would like to have a lazy repr evaluation for the objects! Sometimes users have many really large objects, and when debugger is trying to show them in Variables View (=show their string representation) it can takes a lot of time. We do some tricks, but they

[Python-ideas] Re: Faster object representation for UIs

2020-07-26 Thread Serhiy Storchaka
26.07.20 01:41, Greg Ewing пише: On 26/07/20 1:34 am, Elizabeth Shashkova wrote: 1. We need this lazy `__repr__` calculation inside our debugger, where we work with different user's objects. Usually it isn't some specific type, for which you know that it'll be big and its `__repr__` calculatio

[Python-ideas] Re: Decorators for class non function properties

2020-08-05 Thread Serhiy Storchaka
05.08.20 10:36, redrad...@gmail.com пише: > Decorator will do the same thing as general decorator So the code class Neuron: @linear_activation activation would be equivalent to the following code? class Neuron: activation activation = linear_activation(ac

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Serhiy Storchaka
06.08.20 11:03, Kazantcev Andrey пише: > JSON serialization used in many different libraries without the ability for > configuration (Example > https://github.com/aio-libs/aioredis/blob/8a207609b7f8a33e74c7c8130d97186e78cc0052/aioredis/commands/pubsub.py#L18). > Propose to add something like the

[Python-ideas] Re: Inline Try-Except Clause

2020-08-07 Thread Serhiy Storchaka
06.08.20 23:32, Chris Angelico пише: > On Fri, Aug 7, 2020 at 6:28 AM wrote: >> >>> Have a look at PEP 463, which looks into this in some detail. >> >> I wish this PEP had gained more traction. Sooner or later, everyone wants >> an expression form of a try/except. >> >> When it comes to expressi

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-21 Thread Serhiy Storchaka
21.08.20 12:35, Gustav O пише: > If a file named "tkinter.py" is created and tkinter is imported and used > within the file, the following exception is raised: > "AttributeError: partially initialized module 'tkinter' has no attribute 'Tk' > (most likely due to a circular import)" > > I've spoke

[Python-ideas] Re: Improve error message for trying to import itself

2020-08-21 Thread Serhiy Storchaka
21.08.20 18:22, Greg Ewing пише: > Maybe check whether the module being imported from is shadowing another > module further along the search path and warn about that? It would have non-zero cost. There is a common idiom: try: from foo import bar except ImportError: def bar

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-05 Thread Serhiy Storchaka
05.09.20 01:10, Cade Brown пише: > I mentioned that in my post; however it doesn't satisfy the problems I > have (mainly being that eval(repr(x))==x) It cannot be satisfied if x is a NaN. ___ Python-ideas mailing list -- python-ideas@python.org To unsubs

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-05 Thread Serhiy Storchaka
05.09.20 01:43, Greg Ewing пише: > On 5/09/20 10:15 am, Chris Angelico wrote: >> Remember that if this matters to you, you can "from math import inf". > > But you still need to use full eval on your repr, which could > be a serious security problem in some contexts. If it were a > built-in constan

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-05 Thread Serhiy Storchaka
05.09.20 03:24, Chris Angelico пише: > But don't expect that to actually be secure. It mitigates SOME security > threats. > > I think Python would do very well to have a "restricted evaluation" > function. Looking at the source code for literal_eval, it doesn't seem > too hard to add a check alon

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-05 Thread Serhiy Storchaka
05.09.20 06:52, Christopher Barker пише: > I am a -0 on this, but I think it was Greg Ewing that presented a real > use case:  > > There is no way to use literal_eval that gets you an inf (or NaN value). ast.literal_eval('1e1000') ___ Python-ideas maili

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Serhiy Storchaka
12.09.20 01:57, Guido van Rossum пише: > What happened to "not every three-line function needs to be a built-in"? > This is *literally* a three-line function. And I know the proposal is > not to make it a builtin, but still... ISTM down here lies the path to PHP. Oh, I am very glad that this princ

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Serhiy Storchaka
11.09.20 23:28, The Nomadic Coder пише: > Hi All, > > This is the first time I'm posting to this mailing group, so forgive me if > I'm making any mistakes. > > So one of the most common ways to load json, is via a file. This is used > extensively in data science and the lines. We often write so

<    1   2   3   4   5   6   >