Re: [Python-ideas] Dict joining using + and +=

2019-03-22 Thread Serhiy Storchaka
04.03.19 15:43, Serhiy Storchaka пише: 01.03.19 12:44, Steven D'Aprano пише: On Fri, Mar 01, 2019 at 08:47:36AM +0200, Serhiy Storchaka wrote: Also, if the custom dict subclass implemented the plus operator with different semantic which supports the addition with a dict, this change will

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-21 Thread Serhiy Storchaka
21.03.19 15:24, Chris Angelico пише: On Fri, Mar 22, 2019 at 12:17 AM Serhiy Storchaka wrote: 21.03.19 14:51, Chris Angelico пише: ... then, in the interests of productive discussion, could you please explain? What is it about dict addition that makes it harder to understand than other

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-21 Thread Serhiy Storchaka
21.03.19 14:51, Chris Angelico пише: ... then, in the interests of productive discussion, could you please explain? What is it about dict addition that makes it harder to understand than other addition? Currently the + operator has 2 meanings for builtin types (both are widely used), after add

Re: [Python-ideas] True and False are singletons

2019-03-19 Thread Serhiy Storchaka
18.03.19 22:52, Wes Turner пише: >>> True = 1   File "", line 1 SyntaxError: can't assign to keyword The error message will be changed in 3.8. >>> True = 1 File "", line 1 SyntaxError: cannot assign to True ___ Python-ideas mailing list Python-i

Re: [Python-ideas] True and False are singletons

2019-03-19 Thread Serhiy Storchaka
18.03.19 22:58, Greg Ewing пише: Oleg Broytman wrote:    Three-way (tri state) checkbox. You have to distinguish False and None if the possible valuse are None, False and True. In that case the conventional way to write it would be     if settings[MY_KEY] == True:     ... It's not a ma

[Python-ideas] Not all operators are useful (was Why operators are useful)

2019-03-16 Thread Serhiy Storchaka
15.03.19 19:51, Guido van Rossum пише: There's been a lot of discussion about an operator to merge two dicts. I participated in the beginning but quickly felt overwhelmed by the endless repetition, so I muted most of the threads. But I have been thinking about the reason (some) people like ope

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-09 Thread Serhiy Storchaka
08.03.19 23:16, Martin Bammer пише: what about the idea that the interpreter preallocates and preinitializes the tuples and dicts for function calls where possible when loading a module? Before calling a function then the interpreter would just need to update the items which are dynamic and then

Re: [Python-ideas] Preallocated tuples and dicts for function calls

2019-03-09 Thread Serhiy Storchaka
09.03.19 03:02, Greg Ewing пише: Martin Bammer wrote: what about the idea that the interpreter preallocates and preinitializes the tuples and dicts for function calls where possible when loading a module? This would not be thread-safe. Locking would be needed around uses of the preallocated

Re: [Python-ideas] unittest: 0 tests pass means failure of the testsuite

2019-03-06 Thread Serhiy Storchaka
06.03.19 22:12, Matěj Cepl пише: I am a lead maintainer of Python packages in OpenSUSE and I can see the pattern of many packagers adding blindly python setup.py test to %check section of our SPEC file. The problem is that if the package doesn't use unittest (it actually uses nose, pytest

Re: [Python-ideas] Dict joining using + and +=

2019-03-05 Thread Serhiy Storchaka
04.03.19 15:29, Serhiy Storchaka пише: Using "|" looks more natural to me than using "+". We should look at discussions for using the "|" operator for sets, if the alternative of using "+" was considered, I think the same arguments for preferring &

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Serhiy Storchaka
04.03.19 21:24, Guido van Rossum пише: * Dicts are not like sets because the ordering operators (<, <=, >, >=) are not defined on dicts, but they implement subset comparisons for sets. I think this is another argument pleading against | as the operator to combine two dicts. Well, I suppose th

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Serhiy Storchaka
01.03.19 12:44, Steven D'Aprano пише: On Fri, Mar 01, 2019 at 08:47:36AM +0200, Serhiy Storchaka wrote: Currently Counter += dict works and Counter + dict is an error. With this change Counter + dict will return a value, but it will be different from the result of the += operator. That&

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Serhiy Storchaka
01.03.19 21:31, Guido van Rossum пише: On Thu, Feb 28, 2019 at 10:30 PM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: And this opens a non-easy problem: how to create a mapping of the same type? Not all mappings, and even not all dict subclasses have a copying co

Re: [Python-ideas] Dict joining using + and +=

2019-02-28 Thread Serhiy Storchaka
01.03.19 06:21, Guido van Rossum пише: On Wed, Feb 27, 2019 at 11:18 PM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: Counter uses + for a *different* behavior!  >>> Counter(a=2) + Counter(a=3) Counter({'a': 5}) Well, you can see this as

Re: [Python-ideas] Dict joining using + and +=

2019-02-28 Thread Serhiy Storchaka
28.02.19 23:19, Greg Ewing пише: Serhiy Storchaka wrote: I do not understand why we discuss a new syntax for dict merging if we already have a syntax for dict merging: {**d1, **d2} (which works with *all* mappings). But that always returns a dict. A '+' operator could be implemente

Re: [Python-ideas] Dict joining using + and +=

2019-02-27 Thread Serhiy Storchaka
27.02.19 20:48, Guido van Rossum пише: On Wed, Feb 27, 2019 at 10:42 AM Michael Selik > wrote > The dict subclass collections.Counter overrides the update method for adding values instead of overwriting values. https://docs.python.org/3/library/collections.

Re: [Python-ideas] Make the @contextmanager of contextlib to be a real contextmanager

2019-01-05 Thread Serhiy Storchaka
05.01.19 14:52, Moon丶sun пише: As we know,when we import the module--'contextlib',we can use the decorator '@contextmanager' and keyword ‘yield’ to make a 'instance' of Class '_GeneratorContextManager' in 'contextlib' module,then we can use it like: with 'instance' as 'xx':     'code block'

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-05 Thread Serhiy Storchaka
06.11.18 02:17, Chris Barker via Python-ideas пише: and other nifty things -- any plans to support JSON5 in the stdlib json library? I think that would be great. When it be widely used official standard. There is a number of general data exchange formats more popular than JSON5. _

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread Serhiy Storchaka
02.11.18 19:26, Chris Barker via Python-ideas пише: On Fri, Nov 2, 2018 at 9:31 AM, M.-A. Lemburg > wrote: Serialization of those data types is not defined in the JSON standard: https://www.json.org/ That being said, ISO 8601 is a standard for datetime stamps,

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-11-02 Thread Serhiy Storchaka
31.10.18 21:23, Robert Vanden Eynde пише: Should I write a PEP even though I know it's going to be rejected because the mailing list was not really into it ? It is better to not do this. PEP 572 was initially written with the intention to be rejected.

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-11-01 Thread Serhiy Storchaka
31.10.18 13:08, Antoine Pitrou пише: +1 from me. dict.pop() already has an optional default. This is a straight-forward improvement to the API and no Python programmer will be surprised. list.pop() corresponds two dict methods. With argument it corresponds dict.pop(). But there are differenc

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-11-01 Thread Serhiy Storchaka
31.10.18 13:07, Antoine Pitrou пише: l.pop(default=...) has the potential to be multi-thread-safe, while your alternatives haven't. The multi-thread-safe alternative is: try: value = l.pop() except IndexError: value = default ___

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-30 Thread Serhiy Storchaka
31.10.18 01:44, Giampaolo Rodola' пише: Sorry in advance if this has been proposed in the past but I couldn't find anything on python-ideas: >>> l = [] >>> l.pop(default=1) 1 FWIW my use case consists in reading entries from /proc/diskstats where lines can have a variable number of fields d

Re: [Python-ideas] Decide if `type.__subclasses__` is part of future Python or not

2018-10-29 Thread Serhiy Storchaka
29.10.18 20:11, Joy Diamond пише: Currently `type.__subclasses__` is not documented at docs.python.org (and works in both python 2 & python 3). I would like to keep `.__subclasses__` and have it documented at docs.python.org . Is there a reaso

Re: [Python-ideas] Set starting point for itertools.product()

2018-10-25 Thread Serhiy Storchaka
25.10.18 09:31, Ronie Martinez пише: Here is an example: import itertools import time def main(): datetime_odometer = itertools.product( range(2018,10_000),# year range(1,13),# month range(1,31),# days range(0,24),# hours range(0,60),# minutes range(0,60)# seconds ) datetim

Re: [Python-ideas] Multi Statement Lambdas

2018-10-22 Thread Serhiy Storchaka
22.10.18 02:16, Terry Reedy пише: All functions created from lambda expressions get the same pseudo-name ''.  This can make tracebacks worse.  Perhaps more importantly, proper testing may become harder. See https://bugs.python.org/issue34856. But this can work only while lambda's body is a s

Re: [Python-ideas] Python Enhancement Proposal for List methods

2018-10-21 Thread Serhiy Storchaka
21.10.18 16:00, Siva Sukumar Reddy пише: I am really new to Python contribution community want to propose below methods for List object. Forgive me if this is not the format to send an email. 1. *list.replace( item_to_be_replaced, new_item )*: which replaces all the occurrences of an element

Re: [Python-ideas] Revisiting Immutable Mappings

2018-10-10 Thread Serhiy Storchaka
11.10.18 07:20, João Santos пише: One important difference between MappingProxyType and a "proper" frozendict, as analog to frozenset, is that MappingProxyType doesn't have any method to return mutated versions of itself. MappingProxyType.copy()? __

Re: [Python-ideas] async unittest.TestCase

2018-10-10 Thread Serhiy Storchaka
10.10.18 20:19, Yury Selivanov пише: Thanks for proposing this. Yes, it makes sense to have unittest.AsyncTestCase in 3.8. AFAIK Lisa Roach (copied) was working on that (as well as on async Mock object), but I'm not sure what's the status of her work. I suggest to search for an open issue for

Re: [Python-ideas] Support parsing stream with `re`

2018-10-06 Thread Serhiy Storchaka
06.10.18 10:22, Ram Rachum пише: I'd like to use the re module to parse a long text file, 1GB in size. I wish that the re module could parse a stream, so I wouldn't have to load the whole thing into memory. I'd like to iterate over matches from the stream without keeping the old matches and inp

Re: [Python-ideas] Suggestion: Extend integers to include iNaN

2018-09-30 Thread Serhiy Storchaka
30.09.18 04:07, Steven D'Aprano пише: Telling people that they don't understand their own code when you don't know their code is not very productive. I can't tell him what he should do with his (not working) code, but it doesn't look like a good justification for changes in the Python core.

Re: [Python-ideas] Make None a subclass of int [alternative to iNaN]

2018-09-30 Thread Serhiy Storchaka
30.09.18 09:05, Ken Hilton пише: Reading the iNaN discussion, most of the opposition seems to be that adding iNaN would add a new special value to integers and therefore add new complexity. I propose, instead, that we make None a subclass of int (or even a certain value of int) to represent i

Re: [Python-ideas] Suggestion: Extend integers to include iNaN

2018-09-29 Thread Serhiy Storchaka
29.09.18 21:38, Steve Barnes пише: On 29/09/2018 09:56, Serhiy Storchaka wrote: 29.09.18 11:43, Steve Barnes пише: On 29/09/2018 08:50, Serhiy Storchaka wrote: Python is dynamically typed language. What is such processing that would work with iNaN, but doesn't work with float('na

Re: [Python-ideas] Suggestion: Extend integers to include iNaN

2018-09-29 Thread Serhiy Storchaka
29.09.18 15:19, Steven D'Aprano пише: On Sat, Sep 29, 2018 at 10:50:24AM +0300, Serhiy Storchaka wrote: How does it differ from float('nan')? It is still an integer and would pass through any processing that expected an integer as one, (with a value of iNaN). Python is dy

Re: [Python-ideas] Suggestion: Extend integers to include iNaN

2018-09-29 Thread Serhiy Storchaka
29.09.18 11:43, Steve Barnes пише: On 29/09/2018 08:50, Serhiy Storchaka wrote: Python is dynamically typed language. What is such processing that would work with iNaN, but doesn't work with float('nan')? One simplistic example would be print(int(float('nan'))) (

Re: [Python-ideas] Suggestion: Extend integers to include iNaN

2018-09-29 Thread Serhiy Storchaka
29.09.18 10:35, Steve Barnes пише: On 29/09/2018 08:24, Serhiy Storchaka wrote: 29.09.18 09:31, Steve Barnes пише: I think that it should be relatively simple to extend the Python integer class to have a NaN flag, possibly by having a bit length of 0, and have it follow the same rules for the

Re: [Python-ideas] Suggestion: Extend integers to include iNaN

2018-09-29 Thread Serhiy Storchaka
29.09.18 09:31, Steve Barnes пише: I think that it should be relatively simple to extend the Python integer class to have a NaN flag, possibly by having a bit length of 0, and have it follow the same rules for the handling of floating point NaN, i.e. any mathematical operation on an iNaN returns

Re: [Python-ideas] __iter__(), keys(), and the mapping protocol

2018-09-10 Thread Serhiy Storchaka
11.09.18 05:04, Elias Tarhini пише: This has been bouncing around in my head for a while regarding the requisite keys() method on mappings: How come the ** unpacking operator, a built-in language feature, relies on a non-dunder to operate? To me, I mean to say, requiring that classes impleme

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-08-02 Thread Serhiy Storchaka
27.07.18 16:29, Chris Angelico пише: Ah, fair point. Interestingly, the same problem hits repr(dict(od)), which I would have thought a reliable solution here. The simplest way that I've found is: dict(od.items()) {'b': 2, 'a': 1} That seems very odd. Iterating over the OD produces its keys in

Re: [Python-ideas] Is this PEP-able? "with" statement inside genexps / list comprehensions

2018-07-31 Thread Serhiy Storchaka
31.07.18 00:26, Oscar Benjamin пише: On 30 July 2018 at 20:15, Rudy Matela wrote: Yielding from a with block should be discouraged rather than given special syntax. There is essentially a contradiction between the meaning/purpose of yield (suspend indefinitely) and with (definitely call __exit__

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-27 Thread Serhiy Storchaka
27.07.18 12:53, Chris Angelico пише: from collections import OrderedDict od = OrderedDict([('a', 1), ('b', 2)]) dict.__repr__(od) "{'a': 1, 'b': 2}" dict.__repr__() can output items in wrong order. >>> from collections import OrderedDict >>> od = OrderedDict([('a', 1), ('b', 2)]) >>> od.move_

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Serhiy Storchaka
23.07.18 18:16, Guido van Rossum пише: On Mon, Jul 23, 2018 at 3:24 AM, Jeroen Demeyer > wrote: On 2018-07-23 11:58, Grégory Lielens wrote: Not sure slice[1::3] can be done It can be done. Since "slice" is a class, it would require a metaclass t

Re: [Python-ideas] slice[] to get more complex slices

2018-07-22 Thread Serhiy Storchaka
22.07.18 22:03, Todd пише: For basic slices, the normal "slice(start, stop, step)" syntax works well.  But it becomes much more verbose to create more complicated slices that you want to re-use for multiple multidimensional data structures, like numpy, pandas, xarray, etc. One idea I had was

Re: [Python-ideas] Add the imath module

2018-07-12 Thread Serhiy Storchaka
12.07.18 19:14, Steven D'Aprano пише: Sorry, I don't understand why you say that divide and round up can't be trivially written in Python. Don't you give two implementations yourself? Sorry, perhaps I was unclear, but I said the opposite. ___ Python-

Re: [Python-ideas] Add the imath module

2018-07-12 Thread Serhiy Storchaka
12.07.18 17:30, Paul Moore пише: I'm -1 on having inefficient versions like your primes(n) implementation above in the stdlib. People will use them not realising they may not be suitable for anything other than toy problems. This is just the shortest version that I write every time when I need

Re: [Python-ideas] Add the imath module

2018-07-12 Thread Serhiy Storchaka
12.07.18 16:15, Robert Vanden Eynde пише: About the name, why not intmath ? Because cmath. But if most core developers prefer intmath, I have no objections. And why not using sage ? Or create a package on pypi ? Because some of these function could be useful in the stdlib. Because the spe

Re: [Python-ideas] Add the imath module

2018-07-12 Thread Serhiy Storchaka
12.07.18 15:15, David Mertz пише: On Thu, Jul 12, 2018, 7:56 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: * isprime(n) Tests if n is a prime number. How would you test this? The Miller-Rabin Primality test? For large numbers, iterating through candidate prime di

Re: [Python-ideas] Add the imath module

2018-07-12 Thread Serhiy Storchaka
12.07.18 14:55, Serhiy Storchaka пише: What are your thoughts about adding a new imath module for integer mathematics? It could contain the following functions: I forgot yet one useful function: def divide_and_round(a, b): q, r = divmod(a, b) r *= 2 greater_than_half = r > b i

[Python-ideas] Add the imath module

2018-07-12 Thread Serhiy Storchaka
What are your thoughts about adding a new imath module for integer mathematics? It could contain the following functions: * factorial(n) Is just moved from the math module, but non-integer types are rejected. Currently math.factorial() accepts also integer floats like 3.0. It looks to me, the

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-12 Thread Serhiy Storchaka
12.07.18 02:25, Gregory P. Smith пише: (c) adding a .freeze() method to sets which would raise an exception if the set's refcount were > 1 and would mutate the type of the set object into a frozenset object in place.  refcount assertions are bad, not all VMs need refcounts.  The concept of a me

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-12 Thread Serhiy Storchaka
12.07.18 08:33, Gregory P. Smith пише: Agreed, bytearray(b'...') should be way less common.  I don't immediately have a use for that beyond merely than disliking the copy from temporary bytes object and gc behind the scenes. You can't avoid this since bytearray is mutable. The constant bytes

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-30 Thread Serhiy Storchaka
29.06.18 03:25, Steven D'Aprano пише: On Thu, Jun 28, 2018 at 06:57:45AM +0300, Serhiy Storchaka wrote: Making a nested class a member you don't lost anything, because you always can make it not-nested if you don't want it be a member. You lose the

Re: [Python-ideas] grouping / dict of lists

2018-06-30 Thread Serhiy Storchaka
30.06.18 00:42, Guido van Rossum пише: On a quick skim I see nothing particularly objectionable or controversial in your PEP, except I'm unclear why it needs to be a class method on `dict`. Adding something to a builtin like this is rather heavy-handed. Is there a really good reason why it can'

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Serhiy Storchaka
27.06.18 17:46, Ethan Furman пише: Question:   Should `SomeClass` be an enum member?  When would it be useful to have an embedded class in an Enum be an enum member? The only example I have seen so far of nested classes in an Enum is when folks want to make an Enum of Enums, and the nested

Re: [Python-ideas] staticmethod and classmethod should be callable

2018-06-21 Thread Serhiy Storchaka
21.06.18 10:45, Jeroen Demeyer пише: On 2018-06-20 19:33, Serhiy Storchaka wrote: 20.06.18 12:56, Jeroen Demeyer пише: Are there any reasons to *not* make staticmethod and classmethod callable? There were no reasons to make staticmethod and classmethod callable. You have to compare the

Re: [Python-ideas] staticmethod and classmethod should be callable

2018-06-20 Thread Serhiy Storchaka
20.06.18 12:56, Jeroen Demeyer пише: Are there any reasons to *not* make staticmethod and classmethod callable? There were no reasons to make staticmethod and classmethod callable. Just "for consistency" is not considered a good reason. ___ Python-

Re: [Python-ideas] staticmethod and classmethod should be callable

2018-06-20 Thread Serhiy Storchaka
20.06.18 20:07, Guido van Rossum пише: Maybe we're misunderstanding each other? I would think that calling the classmethod object directly would just call the underlying function, so this should have to call utility() with a single arg. This is really the only option, since the descriptor doesn

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-20 Thread Serhiy Storchaka
20.06.18 10:00, Steven D'Aprano пише: On Wed, Jun 20, 2018 at 07:05:19AM +0300, Serhiy Storchaka wrote: 1. What to do with additional min() and max() arguments: key and default. Since there are no reflected versions of min/max, there is no trouble with extra arguments. Just pass them th

Re: [Python-ideas] staticmethod and classmethod should be callable

2018-06-20 Thread Serhiy Storchaka
20.06.18 19:37, Guido van Rossum пише: On Wed, Jun 20, 2018 at 9:31 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: 20.06.18 19:20, Guido van Rossum пише: > +1 -- when we introduced these we didn't see the use case so clearly, > but it definit

Re: [Python-ideas] staticmethod and classmethod should be callable

2018-06-20 Thread Serhiy Storchaka
20.06.18 19:20, Guido van Rossum пише: +1 -- when we introduced these we didn't see the use case so clearly, but it definitely exists. How would you call a classmethod descriptor in this case? ___ Python-ideas mailing list Python-ideas@python.org htt

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-19 Thread Serhiy Storchaka
19.06.18 22:18, James Edwards пише: I've only recently looked for these special methods, so that in and of itself may be the reason these methods aren't exposed, but I could think of objects that may wish to implement __min__ and __max__ themselves, for efficiency. There are two questions. 1

Re: [Python-ideas] Operator for inserting an element into a list

2018-06-12 Thread Serhiy Storchaka
12.06.18 17:54, Mikhail V пише: I think it would be logical to have the insert operator for lists. Similar to list extend operator += , it could use one of augmented assignment operators, e,g, /=. L = ["aa"] L[0] /= "bb" -> ["bb", "aa"] L[0] /= [1,2] -> [[1,2], "aa

Re: [Python-ideas] Was `os.errno` undocumented?

2018-05-29 Thread Serhiy Storchaka
29.05.18 13:06, Petr Viktorin пише: As you can see, the built-in documentation does not contain *any* warnings against using `os.errno`. You might think the fact that it's called "errno" and not "os.errno" is a red flag, but it's not, really -- "os.path" is (on my system) named "posixpath", yet

Re: [Python-ideas] ternary without else

2018-05-25 Thread Serhiy Storchaka
25.05.18 13:06, Jacco van Dorp пише: I would like to carefully suggest a half form of the ternary expression. Currently, you can write code like: if cond: do_something However, especially if the condition and action are both really simple, taking two lines feels like a bit of a waste. So

Re: [Python-ideas] Reuse "for" to express "given"

2018-05-24 Thread Serhiy Storchaka
24.05.18 18:54, Alexander Belopolsky пише: I have read most of the PEP 572 related threads, but I don't think I've seen this idea.  As many other people mentioned, Python already allows a trick to introduce local bindings in generator expressions and list comprehensions.  This can be achieved b

Re: [Python-ideas] Thoughts on "extended mapping unpacking"

2018-05-24 Thread Serhiy Storchaka
24.05.18 18:46, Neil Girdhar пише: p = parameters.pop('some_parameter') q = parameters.pop('some_other_parameter') if parameters:      raise ValueError parameters is a Mapping subclass and I don't want to destroy it Oh, right. It works if parameters is a var-keyword parameter.

Re: [Python-ideas] Thoughts on "extended mapping unpacking"

2018-05-24 Thread Serhiy Storchaka
24.05.18 11:38, Neil Girdhar пише: I was previously constructing an object like this: tb = TemporalBehavior(**kwargs, **parameters) where various subclasses were doing things like def __init__(self, some_kwarg, some_other_kwargs, some_parameter, some_other_parameter): Then I realized that I

Re: [Python-ideas] String and bytes bitwise operations

2018-05-17 Thread Serhiy Storchaka
17.05.18 15:20, Steven D'Aprano пише: On Thu, May 17, 2018 at 02:14:10PM +0300, Serhiy Storchaka wrote: 17.05.18 13:53, Ken Hilton пише: But it might be useful in some cases to (let's say) xor a string (or bytestring): The question is how common a need of these operations? If

Re: [Python-ideas] String and bytes bitwise operations

2018-05-17 Thread Serhiy Storchaka
17.05.18 13:53, Ken Hilton пише: We all know the bitwise operators: & (and), | (or), ^ (xor), and ~ (not). We know how they work with numbers: 420 ^ 502 110100100 10110 == XOR == 001010010 = 82 But it might be useful in some cases to (let's say) xor a string (or bytestring): The questi

Re: [Python-ideas] Have a "j" format option for lists

2018-05-10 Thread Serhiy Storchaka
09.05.18 15:39, Facundo Batista пише: authors = ["John", "Mary", "Estela"] "Authors: {:, j}".format(authors) 'Authors: John, Mary, Estela' In the case of the list of book or article authors it would be better to get "John, Mary and Estela" or "John, Mary, and Estela". In other cases "John, M

Re: [Python-ideas] Runtime assertion with no overhead when not active

2018-05-08 Thread Serhiy Storchaka
08.05.18 18:34, Steven D'Aprano пише: I don't even know which builds of Python I'm running. My *guess* is that the OS-provided Python is probably a non-debug build, and the ones I've compiled from source will be whatever the default build settings are, but I don't know what that is or how to find

Re: [Python-ideas] Runtime assertion with no overhead when not active

2018-05-08 Thread Serhiy Storchaka
07.05.18 20:52, Guido van Rossum пише: He basically wants a macro so that   runtime_assert() expands to   if and ():   raise AssertionError In Lisp this would be easy. :-) Python is not Lisp (still). But there is the MacroPy project. And at end you always can use an external tool f

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-07 Thread Serhiy Storchaka
07.05.18 17:42, Eric Snow пише: I'm not necessarily saying we should add ModuleSpec.dirname(), but it (or something like it) is what I'd advocate for *if* we were to add a convenient shortcut to the directory a module is in. FWIW, I'd probably use it. The question is *why* you need the absolut

Re: [Python-ideas] Runtime assertion with no overhead when not active

2018-05-07 Thread Serhiy Storchaka
07.05.18 12:58, Eloi Gaudry пише: I didn't mean to replace the current (debug) assert but I wanted to add another one that would allow to be switch on or off on production builds. The need for a new keyword (not syntax) comes from this difference.  I cannot think of another example that woul

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-07 Thread Serhiy Storchaka
06.05.18 09:53, Yuval Greenfield пише: I often need to reference a script's current directory. I end up writing: import os SRC_DIR = os.path.dirname(__file__) But I would prefer to have a new dunder for that. I propose: "__dir__". I was wondering if others would find it convenient to

Re: [Python-ideas] Runtime assertion with no overhead when not active

2018-05-05 Thread Serhiy Storchaka
05.05.18 18:04, Eloi Gaudry пише: By 'self-contained', I meant that using the assert keyword and its expression is sufficient. An inline assertive expression as the one you describe does not fulfill this assert requirement. Sufficient for what? And why writing with using the existing syntax is

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-05 Thread Serhiy Storchaka
05.05.18 18:26, Nick Coghlan пише: 3. writing back to the local namespace via exec doesn't work consistently at function scope (and assuming PEP 558 is eventually accepted, will some day reliably *never* work) At end you can convert the source of the whole script to a string literal and write

Re: [Python-ideas] Runtime assertion with no overhead when not active

2018-05-05 Thread Serhiy Storchaka
05.05.18 15:54, Eloi Gaudry пише: I meant avoiding the overhead of the expression evaluation enclosed in the assert itself, not the active/disabled state (that comes at virtually no cost). ex: runtime_assert( { i:None for i in range( 1000 ) } ) By using the syntax you describe ('boolean a

Re: [Python-ideas] Runtime assertion with no overhead when not active

2018-05-05 Thread Serhiy Storchaka
05.05.18 11:04, Eloi Gaudry пише: Briefly, the idea is to add a new assert that can be switch on/off depending on some variable/mechanism at runtime. The whole point of this assert is that it should not bring any overhead when off, i.e. by avoiding evaluating the expression enclos

Re: [Python-ideas] Pattern Matching Syntax

2018-05-04 Thread Serhiy Storchaka
05.05.18 09:23, Tim Peters пише: [Tim] ... I liked the way he _reached_ that conclusion: by looking at real- life Python code that may have been written instead to use constructs "like this". I find such examination far more persuasive than abstract arguments or made-up examples.

Re: [Python-ideas] Pattern Matching Syntax

2018-05-04 Thread Serhiy Storchaka
04.05.18 20:48, Tim Peters пише: [Guido] Can I recommend going slow here? This is a very interesting topic where many languages have gone before. I liked Daniel F Moisset's analysis about the choices of a language designer and his conclusion that match should be a statement. Just to be annoyin

Re: [Python-ideas] Inline assignments using "given" clauses

2018-05-04 Thread Serhiy Storchaka
04.05.18 15:06, Nick Coghlan пише: Recapping the use cases where the inline assignment capability received the most agreement regarding being potentially more readable than the status quo: Sorry, but these examples don't look as good examples for inline assignments to me. I think that all the

Re: [Python-ideas] Add "default" kw argument to operator.itemgetter and operator.attrgetter

2018-05-03 Thread Serhiy Storchaka
03.05.18 08:28, Raymond Hettinger пише: On May 2, 2018, at 1:08 AM, Vincent Maillol wrote: Our PEP idea would be to purpose to add a global default value for itemgeet and attrgetter method. My preference is to not grow that API further. It is creep well beyond its intended uses. At some po

Re: [Python-ideas] Allow multiple imports from a package while preserving its namespace

2018-04-26 Thread Serhiy Storchaka
27.04.18 02:12, Greg Ewing пише: Chris Angelico wrote: +0 for an easier way to import multiple submodules at once. It's not something I've personally had a need for, but it's a sane and logical thing to do. Maybe:    import display, event, mixer in pygame I read this as import display

Re: [Python-ideas] Allow multiple imports from a package while preserving its namespace

2018-04-26 Thread Serhiy Storchaka
26.04.18 16:51, Nick Coghlan пише: Forcing submodule imports would be the main thing, as at the moment, you have to choose between repeating the base name multiple times (once per submodule) or losing the hierarchical namespace. If the base name is short, there are no problems with repeating it

Re: [Python-ideas] Allow multiple imports from a package while preserving its namespace

2018-04-26 Thread Serhiy Storchaka
The following works today: Python 3.6.3 (default, Oct  4 2017, 06:09:15) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import os.path >>> os '/Users/pradyunsg/.venvwrap/venvs/pip/bin/../lib/python3.6

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Serhiy Storchaka
25.04.18 13:15, Ivan Levkivskyi пише: Hm, this is what I wanted to know. I think by rewriting EnumMeta in C we can reduce the creation time of an Enum class (almost) down to the creation time of a normal class, which may be a 4-5x speed-up. What do you think? It could be great. But I afraid th

Re: [Python-ideas] Change magic strings to enums

2018-04-25 Thread Serhiy Storchaka
25.04.18 10:57, Ivan Levkivskyi пише: On 25 April 2018 at 06:03, INADA Naoki > wrote: enum class&member creation cost is much heavier than "import enum" cost. Especially, "import socket, ssl" is much slower than before... Is it slow simply because we are c

Re: [Python-ideas] Checking interned string after stringobjects concat?

2018-04-21 Thread Serhiy Storchaka
21.04.18 17:47, Chris Angelico пише: On Sat, Apr 21, 2018 at 10:29 PM, Serhiy Storchaka wrote: 21.04.18 13:42, Chris Angelico пише: What you're seeing there is actually the peephole optimizer at work. Since 3.7 constant folding is the AST optimizer work. The end result is the same in

Re: [Python-ideas] Checking interned string after stringobjects concat?

2018-04-21 Thread Serhiy Storchaka
21.04.18 13:42, Chris Angelico пише: What you're seeing there is actually the peephole optimizer at work. Since 3.7 constant folding is the AST optimizer work. The end result is the same in most cases though. Other optimization takes place here too. Constants strings that look like identifi

Re: [Python-ideas] collections.Counter should implement __mul__, __rmul__

2018-04-18 Thread Serhiy Storchaka
18.04.18 21:45, Tim Peters пише: (*) The obvious implementation: def __mul__(self, other): if isinstance(other, Sized): raise TypeError("cannot multiply Counter by Sized type %s" % type(other)) Wouldn't be better to return NotImplemented here? result = Count

Re: [Python-ideas] collections.Counter should implement __mul__, __rmul__

2018-04-18 Thread Serhiy Storchaka
18.04.18 22:34, Tim Peters пише: Counter supports a wonderfully weird mix of methods driven by use cases, not by ideology. + (binary) - (binary) | & have semantics driven by viewing a Counter as a multiset implementation. That's why they discard values <= 0. They correspon

Re: [Python-ideas] collections.Counter should implement __mul__, __rmul__

2018-04-18 Thread Serhiy Storchaka
16.04.18 08:07, Tim Peters пише: Adding Counter * integer doesn't bother me a bit, but the definition of what that should compute isn't obvious. In particular, that implementation doesn't preserve that `x+x == 2*x` if x has any negative values: x = Counter(a=-1) x Counter({'a': -1}) x+x Cou

Re: [Python-ideas] A cute Python implementation of itertools.tee

2018-04-15 Thread Serhiy Storchaka
15.04.18 19:52, Tim Peters пише: No, I don't ;-) If I have to catch StopIteration myself now, then I want the entire "white True:" loop in the "try" block. Setting up try/except machinery anew on each iteration would add significant overhead; doing it just once per derived generator wouldn't.

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-15 Thread Serhiy Storchaka
15.04.18 12:49, Alexey Shrub пише: В Воскресенье, 15 апр. 2018 в 12:40 , Serhiy Storchaka написал: If the problem is that you want to use a single line instead of three line, you can add a function Yes, I think that single line with word 'rewrite' is much more readable than t

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-15 Thread Serhiy Storchaka
15.04.18 11:57, Alexey Shrub пише: I am new in python (i am moving from Perl world), but I always love Python for hight level, beatuful and clean syntax. Now I have question/idea about working with files. On mine opinion it very popular use case: 1. Open file (for read and write) 2. Read data fr

Re: [Python-ideas] Accepting multiple mappings as positional arguments to create dicts

2018-04-12 Thread Serhiy Storchaka
12.04.18 22:42, Andrés Delfino пише: I think the update method can (and personally, should) stay unchanged: spam.update(dict(x, y)) seems succinct and elegant enough, with the proposed constructor syntax. Sorry my ignorance, do (Mutable)Mapping ABC say anything about constructors? Mapping a

Re: [Python-ideas] Default values in multi-target assignment

2018-04-12 Thread Serhiy Storchaka
12.04.18 18:12, Guido van Rossum пише: I hear where you're coming from but I really don't think we should do this. If you don't have the right expectation already it's hard to guess what it means. I would much rather spend effort on a proper matching statement. There are few applications of t

Re: [Python-ideas] Accepting multiple mappings as positional arguments to create dicts

2018-04-12 Thread Serhiy Storchaka
09.04.18 00:18, Andrés Delfino пише: I thought that maybe dict could accept several mappings as positional arguments, like this: class Dict4(dict):     def __init__(self, *args, **kwargs):     if len(args) > 1:     if not all([isinstance(arg, dict) for arg in args

Re: [Python-ideas] Accepting multiple mappings as positional arguments to create dicts

2018-04-12 Thread Serhiy Storchaka
12.04.18 17:34, Ed Kellett пише: It allows for creating a flattened dict from an iterable of dicts, too, which I've occasionally wanted: configs = {'a': 'yes'}, {'b': 'no'}, {'c': 3} dict(*configs) {'a': 'yes', 'b': 'no', 'c': 3} versus: dict(chain.from_iterable(c.items() for c in configs))

<    1   2   3   4   5   6   >