[Python-ideas] Re: Standalone bool?

2020-12-22 Thread Serhiy Storchaka
22.12.20 02:52, Christopher Barker пише: > On Mon, Dec 21, 2020 at 3:37 PM Greg Ewing > wrote: > > However, that ship has sailed. I think it would have been minimally > > disruptive when True and False were first introduced, > > It would have been j

[Python-ideas] Re: Using explicit parenthesization to convey aspects of semantic meaning?

2020-12-17 Thread Serhiy Storchaka
17.12.20 21:58, Ethan Furman пише: > On 12/17/20 11:09 AM, Chris Angelico wrote: >> "a+b" is NOT implemented as "a.__add__(b)", nor as "type(a).__add__(b)"! > > Okay, what is it implemented as? First, it can use not only method __add__ of the type of a, but also method __radd__ of the type of b.

[Python-ideas] Re: @classproperty, @abc.abstractclasspropery, etc.

2020-12-16 Thread Serhiy Storchaka
03.01.11 23:09, K. Richard Pixley пише: > There's a whole matrix of these and I'm wondering why the matrix is > currently sparse rather than implementing them all.  Or rather, why we > can't stack them as: > > class foo(object): >     @classmethod >     @property >     def bar(cls, ...): >    

[Python-ideas] Re: @classproperty, @abc.abstractclasspropery, etc.

2020-12-16 Thread Serhiy Storchaka
04.01.11 02:56, Guido van Rossum пише: > That said, I am sure there are use cases for static property and class > property -- I've run into them myself. > > An example use case for class property: in App Engine, we have a Model > class (it's similar to Django's Model class). A model has a "kind" >

[Python-ideas] Re: __init__ in module names

2020-12-10 Thread Serhiy Storchaka
10.12.20 16:40, Steven D'Aprano пише: > On Thu, Dec 10, 2020 at 03:46:37PM +0200, Serhiy Storchaka wrote: > >> Maybe it is just me, because I read the original issue. But Gregory's >> message looks to me well organized and answering questions that were >> asked

[Python-ideas] Re: __init__ in module names

2020-12-10 Thread Serhiy Storchaka
09.12.20 22:39, Steven D'Aprano пише: > On Wed, Dec 09, 2020 at 01:56:01PM +0200, Serhiy Storchaka wrote: > >> Thank you for good explanation of the problem. > > I'm sorry Serhiy, I disagree that this has been a "good explanation of > the problem". &

[Python-ideas] Re: __init__ in module names

2020-12-10 Thread Serhiy Storchaka
08.12.20 22:14, M.-A. Lemburg пише: > On 08.12.2020 20:47, Gregory Szorc wrote: >> Anyway, I was encouraged by Brett Cannon to email this list to assess the >> appetite for introducing a backwards incompatible change to this behavior. So >> here's my strawman/hardline proposal: >> >> 1. 3.10 introd

[Python-ideas] Re: __init__ in module names

2020-12-09 Thread Serhiy Storchaka
08.12.20 21:47, Gregory Szorc пише: > PyOxidizer's pure Rust implementation of a meta path importer > (https://pyoxidizer.readthedocs.io/en/stable/oxidized_importer_oxidized_finder.html) > has been surprisingly effective at finding corner cases and behavior > quirks in Python's importing mechanisms

[Python-ideas] Re: Make for/while loops nameable.

2020-12-03 Thread Serhiy Storchaka
03.12.20 15:59, Chris Angelico пише: > well... uhhh Technically you can do that already > > for a in aaa: > for b in bbb: > if condition(a, b): > break > else: > continue # We didn't break from b, so continue a > break # We did break b, so break a >

[Python-ideas] Re: adding a timeit.Timer context manager and decorator to time code/functions

2020-11-29 Thread Serhiy Storchaka
29.11.20 22:44, sdemen...@gmail.com пише: > The feature I am looking for is more about timing a code block or a function > while running the code in dev/production. Not about timing it for > benchmarking purposes. > To use timeit (or the current Timer class), one has to write the stmt as a > str

[Python-ideas] Re: [PoC] Implementing block-scope for the "for" statement variables

2020-11-29 Thread Serhiy Storchaka
29.11.20 18:27, Paul Sokolovsky пише: > Here's example of it in action: > > $ cat example_for1.py > def fun(): > x = 123 > for x in range(5): > print(x) > print("old x:", x) > > fun() I am strong -1. 1. It will break existing code. Including a lot of code written by me. 2

[Python-ideas] Re: Move semantics

2020-11-27 Thread Serhiy Storchaka
26.11.20 13:44, 3mi...@gmail.com пише: > Add something like Move type hint to typing module. It will tell the analyzer > that the input parameter of the function is moved and can not be used after. > For example: > ``` > def f(d: Move[dict]) -> dict: > d['a'] = 2 > return d > > d = {1: 2

[Python-ideas] Re: Move semantics

2020-11-27 Thread Serhiy Storchaka
27.11.20 13:25, Ned Batchelder пише: > On 11/26/20 11:45 PM, Guido van Rossum wrote: > Yes, I see that now.  As Chris points out elsewhere in the thread, this > proposal would have the type annotations change the actual behavior of > the code. No, it will not change the runtime behavior. But it can

[Python-ideas] Re: Move semantics

2020-11-27 Thread Serhiy Storchaka
26.11.20 19:07, Guido van Rossum пише: > This reminds me of something in C++. Does it exist in other languages? Indeed, this is a term from C++. In older C++ you could pass argument by value, which makes a copy, and by reference, which is equivalent to passing a pointer by value plus syntax sugar.

[Python-ideas] Re: Circular Indexing and FOR loop minimization

2020-11-25 Thread Serhiy Storchaka
25.11.20 06:29, Mathew M. Noel via Python-ideas пише: > 2.) If circular indexing is used then instead of using a double FOR loop > to go through a loop twice we can iterate from 0 to 2n ! If you just need to iterate list indices twice, iterate range(-n, n) instead of range(n).

[Python-ideas] Re: Use __bytes__ to access buffer-protocol from "user-land"

2020-11-16 Thread Serhiy Storchaka
15.11.20 21:19, Ben Rudiak-Gould пише: > I don't think __bytes__ is necessarily a bad idea, but I want to point > out a couple of things you may be unaware of. First, slicing a > memoryview object creates a subview, so you can wrap your mmap object in > a memoryview and then create slices for each

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
21.10.20 05:23, Steve Barnes пише: > Of course there is also the problem of detecting any functions assigned > to _ or _T that may be called - otherwise there is a risk of breaking > the typical gettext usage in I18n! gettext is usually mapped to global _, so it is not affected. Also, even if eli

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
20.10.20 20:13, Steven D'Aprano пише: > On Tue, Oct 20, 2020 at 05:30:54PM +0300, Serhiy Storchaka wrote: > >> I do not want to create tens of alternate PEPs with minor variations, >> and this issue is not worth a PEP. What is your opinion about this? Is >> it worth

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
20.10.20 19:35, Guido van Rossum пише: > I think it's a micro-optimization that's probably not worth it for most > code and more likely to occasionally disappoint people who are using the > debugger. I thought so too. But these reasons make PEP 640 even more useless. __

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Serhiy Storchaka
21.10.20 05:05, Michael Smith пише: > There are many ways to invoke a function from the commandline. You can > use setuptools' console_scripts entrypoint. You can use a decorator > from click. And of course you can always do the classic > > if __name__ == "__main__": > main() > > to call whatev

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

2020-10-20 Thread Serhiy Storchaka
20.10.20 12:54, J. Pic пише: > At the same time, Guido says he can remove that cost for no extra > cost, so there's that: how do we find a good reason to not remove a > cost for free ? Sounds like a win/win situation, both for most users > and for the new pegparser. It may have closer to zero cost

[Python-ideas] Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
It is common to use _ as a placeholder for variable whose value is not used. For example: for _ in range(n) head, _, tail = name.partition(':') first, *_, last = items I though about optimizing out unnecessary assignments. Actually I wrote a patch half year ago and tested it. It did n

[Python-ideas] Re: Weakrefs for lru_cache?

2020-10-16 Thread Serhiy Storchaka
15.10.20 20:49, Ram Rachum пише: > Hi everyone, > > For many years, I've used a `cache` decorator that I built > > for caching Python functions. Then `functools.lru_cache` was > implemented, which is m

[Python-ideas] Re: Add _KB, _MB, _GB to numeric literals

2020-10-13 Thread Serhiy Storchaka
13.10.20 08:06, malin...@163.com пише: > PEP 515 added underscore to numeric literals, it brings better readability. > > PEP 515 -- Underscores in Numeric Literals > https://www.python.org/dev/peps/pep-0515/ > > Is it possible to add _KB, _MB, _GB to numeric literals, for example: > >

[Python-ideas] Re: New feature

2020-10-13 Thread Serhiy Storchaka
13.10.20 09:07, ankith abhayan пише: > I would like to request a new feature that allows you to clear the > console screen. > Like in c++, the CLS function There is no the CLS function in C++. ___ Python-ideas mailing list -- python-ideas@python.org To u

[Python-ideas] Re: SupportsString Protocol Type Annotation

2020-10-08 Thread Serhiy Storchaka
07.10.20 18:43, Guido van Rossum пише: > Usability in a different context. > ``` z = 1j float(z) > Traceback (most recent call last): >   File "", line 1, in > TypeError: can't convert complex to float float(object()) > Traceback (most recent call last): >   File "", line 1, in > T

[Python-ideas] Re: SupportsString Protocol Type Annotation

2020-10-07 Thread Serhiy Storchaka
07.10.20 06:04, Guido van Rossum пише: > Ironically, complex numbers have a `__float__` > method that always fails, and floats don't have a `__complex__` method > but complex(x) succeeds if x is a float... I wonder why not remove complex.__float__ (and complex.__int__, complex.__floordiv__, etc)?

[Python-ideas] Re: Add the brotli & zstandard compression algorithms as modules

2020-09-29 Thread Serhiy Storchaka
29.09.20 16:26, Omer Katz пише: > What are the use-cases for LZMA that make it qualify to be part of the > stdlib? Why was that library included? > I think we shouldn't discriminate. If there are a couple of use-cases users > need and the implementation is sufficiently stable, I see no reason not

[Python-ideas] Re: Improved Error Message for "Unhashable Type"

2020-09-28 Thread Serhiy Storchaka
28.09.20 16:31, Samuel Freilich via Python-ideas пише: > The error message for using a mutable sequence as a set item or map key > seems to frequently confuse Python beginners. The current wording is: > {[1, 2, 3]: [4, 5, 6]} > TypeError: unhashable type: 'list' > > The first thing a Google

[Python-ideas] Re: Suggestion: annotated exceptions

2020-09-25 Thread Serhiy Storchaka
24.09.20 11:47, Sergio Fenoll пише: > In the same vein as adding type annotations to code, I think it'd be > very useful to have exception "raises" annotations, i.e. a way to > annotate what exceptions a function raises. Again, like type > annotations, it shouldn't be mandatory nor actually be enfo

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

2020-09-14 Thread Serhiy Storchaka
14.09.20 19:55, Chris Angelico пише: > I think not; unless there are API details to be hashed out or > counterarguments to be rebuffed, I think this is fairly simple and > non-controversial. I also considered this issue simple and non-controversial. But the discussion turned in an unexpected direc

[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

[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: '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: '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 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 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 __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: 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: 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: 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: 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: 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: 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: "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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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] 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: 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] 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: 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: 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: 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: 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: 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 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-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-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 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(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
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: 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: 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: 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] 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: 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] 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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

<    1   2   3   4   5   6   >