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] 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] 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] 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] 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] 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] 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] 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] 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] 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-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-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] 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] 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] 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] 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] 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-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-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-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
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-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] 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] 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] 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

[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] 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

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] 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] 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] 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] dict.merge(d1, d2, ...) (Counter proposal for PEP 584)

2019-03-24 Thread Serhiy Storchaka
23.03.19 18:24, Christopher Barker пише: I wonder how often + is used with lists in the stdlib... Searching for "+ [" shows that even concatenating with the string display and comprehensions is several times more common that merging dicts. And there should be cases not covered by this simple

Re: [Python-ideas] Unified style of cache management API

2019-03-27 Thread Serhiy Storchaka
27.03.19 15:46, Ma Lin пише: re module [1] and struct module [2] have module-level cache for compiled stuffs. Other third-party modules may also need cache for something. Do we need an unified cache management API like this? I suppose it's not mandatory, but welcome each module to use this API.

Re: [Python-ideas] Unified style of cache management API

2019-03-28 Thread Serhiy Storchaka
28.03.19 19:45, Brett Cannon пише: So I would say that a cache-clearing function convention would be a reasonable starting point. If that turns out to not be enough for folks we can talk about expanding it, but I think we should start small and grow from there as needed. So what name would pe

Re: [Python-ideas] Unified style of cache management API

2019-03-30 Thread Serhiy Storchaka
29.03.19 20:52, Brett Cannon пише: On Thu, Mar 28, 2019 at 10:53 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: 28.03.19 19:45, Brett Cannon пише: > So I would say that a cache-clearing function convention would be a > reasonable starting point. If that t

Re: [Python-ideas] Add output() helper function to subprocess module

2019-04-04 Thread Serhiy Storchaka
04.04.19 11:59, Greg Ewing пише: Nathaniel Smith wrote: On Thu, Apr 4, 2019 at 12:48 AM Greg Ewing wrote: output(args) --> (status, output) Isn't this already available as: run(args, stdout=PIPE)? Yes, but you need to do more than that to get the output as a string. This is the relevant pa

Re: [Python-ideas] Starap function exists but it seems there's not such thing as "doublestarmap"

2019-04-10 Thread Serhiy Storchaka
10.04.19 12:55, Krokosh Nikita пише: I need smth like starstarmap('{a} / {b}/ {c}'.format, [{a:1, b:2, c:3}, {a:4, b:5, c:6}, ...]) Use the format_map method of str. >>> list(map('{a} / {b}/ {c}'.format_map, [{'a':1, 'b':2, 'c':3}, {'a':4, 'b':5, 'c':6}])) ['1 / 2/ 3', '4 / 5/ 6'] _

[Python-ideas] Custom converters in str.format() and f-strings

2019-05-04 Thread Serhiy Storchaka
Currently str.format() and f-strings support three converters. Converting is specified by the "!" character followed by a letter which denotes the converter. s: str() r: repr() a: ascii() In some cases it would be useful to apply other converters. One obvious example is escaping special chara

[Python-ideas] More alternate constructors for builtin type

2019-05-06 Thread Serhiy Storchaka
Constructors for builtin types is too overloaded. For example, int constructor: * Converts a number (with truncation) to an integer. * Parses human readable representation of integer from string or bytes-like object. Optional base can be specified. Note that there is an alternate constructor f

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-06 Thread Serhiy Storchaka
06.05.19 17:49, Guido van Rossum пише: 20-25 years ago this might have been a good idea. Unfortunately there's so much code (including well-publicized example code) that I'm not sure it's a good use of anyone's time to try and fix this. I do not propose to change the current behavior. I propos

Re: [Python-ideas] shutil.symlink to allow non-race replacement of existing link targets

2019-05-14 Thread Serhiy Storchaka
13.05.19 12:38, Tom Hale пише: As suggested by Toshio Kuratomi at https://bugs.python.org/issue36656, I am raising this here for inclusion in the shutil module. Mimicking POSIX, os.symlink() will raise FileExistsError if the link name to be created already exists. A common use case is overwr

Re: [Python-ideas] Passing positional arguments as keyword arguments (to provide function arguments out of order)

2019-05-15 Thread Serhiy Storchaka
16.05.19 08:46, Anders Hovmöller пише: In the general case because of features that until / was introduced was unique to functions defined in C. But in the case of the dict constructor that's just a weird misfeature. If it did in fact take *args and handled it it would be perfectly fine and us

Re: [Python-ideas] shutil.symlink to allow non-race replacement of existing link targets

2019-05-16 Thread Serhiy Storchaka
14.05.19 19:50, Steven D'Aprano пише: On Tue, May 14, 2019 at 02:43:03PM +0300, Serhiy Storchaka wrote: Sorry, but I do not understand what problem do you try to solve. If somebody can create a file named link_name between unlink and symlink, he can also remove and create a file named link

Re: [Python-ideas] shutil.symlink to allow non-race replacement of existing link targets

2019-05-16 Thread Serhiy Storchaka
16.05.19 11:28, Barry Scott пише: To replace one symlink with another atomically is possible by using rename() or renameat() something like: os.symlink( src, tmp_symlink ) os.rename( tmp_symlink, dst ) Somebody can replace tmp_symlink between os.symlink() and os.rename(). ___

Re: [Python-ideas] shutil.symlink to allow non-race replacement of existing link targets

2019-05-16 Thread Serhiy Storchaka
16.05.19 14:33, Antoine Pitrou пише: On Thu, 16 May 2019 13:05:48 +0300 Serhiy Storchaka wrote: 16.05.19 11:28, Barry Scott пише: To replace one symlink with another atomically is possible by using rename() or renameat() something like: os.symlink( src, tmp_symlink

Re: [Python-ideas] shutil.symlink to allow non-race replacement of existing link targets

2019-05-16 Thread Serhiy Storchaka
16.05.19 17:05, Antoine Pitrou пише: On Thu, 16 May 2019 16:04:36 +0300 Serhiy Storchaka wrote: 16.05.19 14:33, Antoine Pitrou пише: On Thu, 16 May 2019 13:05:48 +0300 Serhiy Storchaka wrote: 16.05.19 11:28, Barry Scott пише: To replace one symlink with another atomically is possible by

Re: [Python-ideas] Implement POSIX ln via shutil.link and shutil.symlink

2019-06-01 Thread Serhiy Storchaka
30.05.19 00:22, Barry пише: Serhiy, I think, is conflating two things. 1. How to write software robust aginst attack. 2. How to replace a symlink atomically. Why do you need to replace a symlink atomically? This is a solution, what problem it solves? _

[Python-ideas] Re: Comparison operator support (>= and <=) for type

2019-06-18 Thread Serhiy Storchaka
17.06.19 17:47, Guido van Rossum пише: Indeed it would work the same way as set comparison does, if you interpret a type as the set of its instances. But I imagine that many Python users are not so familiar with this abstraction level (even if they use isinstance() and issubclass() all day lo

[Python-ideas] Re: Implement POSIX ln via shutil.link and shutil.symlink

2019-06-25 Thread Serhiy Storchaka
04.06.19 10:25, Inada Naoki пише: On Sat, Jun 1, 2019 at 4:10 PM Serhiy Storchaka wrote: Why do you need to replace a symlink atomically? This is a solution, what problem it solves? There is another, more common / realistic usage of atomic symlink replacing. When deploy PHP application or

[Python-ideas] Re: Make tuple a context manager

2019-07-12 Thread Serhiy Storchaka
12.07.19 16:27, haael пише: Could we add __enter__ and __exit__ to the tuple type? Look at the following code: a = open('a.tmp', 'w') b = open('b.tmp', 'w') with (a, b) as (af, bf):     af.write("1")     bf.write("2") Even better example: with tuple(open(str(_n) + '.tmp', 'w') for _n

[Python-ideas] Re: Make tuple a context manager

2019-07-14 Thread Serhiy Storchaka
13.07.19 23:25, Kyle Stanley пише: Serhiy Storchaka wrote: Are your aware of contextlib.nested()? And why it was deprecated and removed? Was contextlib.nested() removed primarily due to to the inconsistencies mentioned in https://bugs.python.org/issue5251 or was it something else? Yes, it

[Python-ideas] Re: Non-standard evaluation for Python

2019-07-14 Thread Serhiy Storchaka
14.07.19 07:06, Andrew Barnert via Python-ideas пише: (Re-sending, because this was originally a reply to an off-list message by Nima Hamidi) On Jul 13, 2019, at 14:12, Nima Hamidi > wrote: Sometimes it's necessary not to evaluate the expression. Two such applica

[Python-ideas] Re: Non-standard evaluation for Python

2019-07-15 Thread Serhiy Storchaka
14.07.19 23:20, Nima Hamidi пише: Thank you for your question! It would depend on the implementation of DataFrame.__getitem__. Note that BoundExpression is endowed with locals and globals of the callee. So, it does have access to x in your example. I think the way that data.table in R handles

[Python-ideas] Re: PEP's shouldn't require a sponsor

2019-07-25 Thread Serhiy Storchaka
25.07.19 15:14, Batuhan Taskaya пише: Why do i need to convince a core developer for my PEP? AFAIK the steering council can include non core developers (i know it isn't that current case but for the future this is important). And if the last authority who will approve my PEP is the steering cou

[Python-ideas] Skip modules by default in star-import

2019-07-26 Thread Serhiy Storchaka
From the description of the import statement in the language reference [1]: The *public names* defined by a module are determined by checking the module's namespace for a variable named ``__all__``; if defined, it must be a sequence of strings which are names defined or imported by that module.

[Python-ideas] for ... except, with ... except

2019-07-26 Thread Serhiy Storchaka
Python allows you to write code in tight and readable form. Consider the following example. with connect() as stream: # connect() or __enter__() can fail. for data in stream: # __next__() can fail write(data) # write() can fail The problem is that different lines can

[Python-ideas] Re: Skip modules by default in star-import

2019-07-26 Thread Serhiy Storchaka
26.07.19 21:10, Anders Hovmöller пише: This doesn't really solve the problem imo. Imported symbols shouldn't be i portable elsewhere. Not by import * or explicitly. That's the problem. I do not think that this is always a problem. It is common to refactor the code by defining names in submodu

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Serhiy Storchaka
26.07.19 23:46, MRAB пише: On 2019-07-26 19:26, Serhiy Storchaka wrote: [snip] I propose to add "except" clause to "for" and "with" statement to catch exceptions in the code that can't be wrapped with "try ... except".   for VAR in EXPR:   

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Serhiy Storchaka
26.07.19 23:57, Guido van Rossum пише: These are interesting ideas. It looks like you intend the except clause of the for loop to *only* cover the iter() and next() calls that are implicit in the for loop. You're right that it's awkward to catch exceptions there. Right. If you want to catch a

[Python-ideas] Re: Skip modules by default in star-import

2019-07-27 Thread Serhiy Storchaka
26.07.19 23:53, Guido van Rossum пише: Serhiy proposed a relatively minor change to the behavior of `import *` in the absence of __all__. This sounds like an idea we could try though we should have a look at the implications for various well-known packages. It is also a relatively minor problem

[Python-ideas] Re: for ... except, with ... except

2019-07-27 Thread Serhiy Storchaka
26.07.19 21:52, Bruce Leban пише: On Fri, Jul 26, 2019 at 11:27 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: So you will be able to add errors handling like in:      with connect() as stream:          for data in stream:        

[Python-ideas] Re: Custom string prefixes

2019-08-26 Thread Serhiy Storchaka
27.08.19 06:38, Andrew Barnert via Python-ideas пише: * JSON (register the stdlib or simplejson or ujson), What if the JSON suffix for? JSON is virtually a subset of Python except that that it uses true, false and null instead of True, False and None. If you set these three variables you ca

[Python-ideas] Re: Custom string prefixes

2019-08-27 Thread Serhiy Storchaka
27.08.19 20:07, Andrew Barnert via Python-ideas пише: Before I get into this, let me ask you a question. What does the j suffix give us? You can write complex numbers without it just fine: c = complex c(1, 2) And you can even write a j function trivially: def j(x): return compl

[Python-ideas] Re: Skip modules by default in star-import

2019-09-18 Thread Serhiy Storchaka
26.07.19 20:43, Serhiy Storchaka пише: I propose to change the rule for determining the set of public names if `__all__` is not defined. In addition to underscored names I propose to exclude names of modules. Opened an issue and a PR: https://bugs.python.org/issue38215 https://github.com

[Python-ideas] Add a slot for "keys" in tp_as_mapping

2019-09-18 Thread Serhiy Storchaka
Most C API uses type slots instead looking up in the type's dictionary for methods. But there are few methods used in basic operations which do not have corresponding slots. For example "keys", "__trunc__" and "__length_hint__". In particularly, "keys" is checked in dict.__init__() and dict.up

[Python-ideas] Re: Add a slot for "keys" in tp_as_mapping

2019-09-24 Thread Serhiy Storchaka
19.09.19 11:00, Greg Ewing пише: Serhiy Storchaka wrote: PyDict_Merge() is called every time when you have a call like `f(a=1, **kw)` So would not be worth to add slots for keys (and maybe for values and items) to the tp_as_mapping structure? Only if looking up those methods is taking a

[Python-ideas] Re: Error handling toggle / levels

2019-09-26 Thread Serhiy Storchaka
26.09.19 12:07, salemalbr...@gmail.com пише: So when coding, at deferent stages we need different levels of error handling. For example at stage of finding the concept, initial implementation, alpha, releasing testing, etc. By some bits of code we can simulate enable/disable error handling. B

[Python-ideas] Re: Add __slots__ to dataclasses to use less than half as much RAM

2019-09-27 Thread Serhiy Storchaka
27.09.19 19:48, Andrew Barnert via Python-ideas пише: On Friday, September 27, 2019, 07:47:41 AM PDT, Johnny Dahlberg wrote: > My proposal: Implement `@dataclass(slots=True)` which does the same thing as attrs: Replaces the class with a modified class that has a `__slots__` property instead

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-13 Thread Serhiy Storchaka
14.10.19 03:47, Chris Angelico пише: Though a set.__setitem__() method might be helpful here. If you set an item to any truthy value, it is added to the set; set it to a falsy value and it will be discarded (without error if it wasn't there, so assignment in this way is idempotent). That would ma

[Python-ideas] Re: Resolve append/add API inconsistency between set and list

2019-10-14 Thread Serhiy Storchaka
14.10.19 09:54, Chris Angelico пише: On Mon, Oct 14, 2019 at 5:41 PM Serhiy Storchaka wrote: 14.10.19 03:47, Chris Angelico пише: Though a set.__setitem__() method might be helpful here. If you set an item to any truthy value, it is added to the set; set it to a falsy value and it will be

[Python-ideas] Re: Extending @ syntax to allow expressions

2019-10-22 Thread Serhiy Storchaka
22.10.19 06:41, Andrew Barnert via Python-ideas пише: 2: I'm not sure what this would to to uses of "@" as an operator, as has been suggested various times for various laudable reasons; remember that an @decorator or other function definition is just another statement, and arbitrary expressions

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread Serhiy Storchaka
23.10.19 13:08, Steven D'Aprano пише: But the advantage of changing the syntax is that it becomes the One Obvious Way, and you know it will be efficient whatever version or implementation of Python you are using. There is already the One Obvious Way, and you know it will work whatever version

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread Serhiy Storchaka
23.10.19 14:00, Steven D'Aprano пише: On Wed, Oct 23, 2019 at 01:42:11PM +0300, Serhiy Storchaka wrote: 23.10.19 13:08, Steven D'Aprano пише: But the advantage of changing the syntax is that it becomes the One Obvious Way, and you know it will be efficient whatever version or impleme

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-23 Thread Serhiy Storchaka
23.10.19 18:16, Steven D'Aprano пише: The average word length in English is five characters. That means that in a list of typical English words, more than a third of the expression is made up of the quotes and commas. In the example you give, there are twelve characters in the words themselves an

[Python-ideas] Re: Percent notation for array and string literals, similar to Perl, Ruby

2019-10-24 Thread Serhiy Storchaka
24.10.19 14:27, David Mertz пише: On Thu, Oct 24, 2019, 7:19 AM Richard Damon > wrote: My one comment about this is to quote from PEP 20, the Zen of Python There should be one-- and preferably only one --obvious way to do it. No problem, the new synta

[Python-ideas] Re: Python 4000: Have stringlike objects provide sequence views rather than being sequences

2019-10-25 Thread Serhiy Storchaka
25.10.19 15:53, Andrew Barnert via Python-ideas пише: If you were designing a new Python-like language today, or if you had a time machine back to the 90s, it would be a different story. Interesting, how far in past you will need to travel? Initially builtin types did not have methods or prop

[Python-ideas] Re: foo.setParseAction(lambda a, b, c: raise FuckPython(":("))

2019-10-28 Thread Serhiy Storchaka
28.10.19 20:38, Andrew Barnert via Python-ideas пише: Many of them are abusing throw(StopIteration) to fake a “takewhile clause” in comprehensions Well, so actually you needed the break expression. Or multistatement comprehension. ___ Python-ideas

[Python-ideas] Re: Suggestion for behaviour change import mechanics

2019-10-30 Thread Serhiy Storchaka
30.10.19 00:41, Steven D'Aprano пише: Think about the behaviour of ``from module import name`` in pure Python. Currently, it is straightforward to explain: try to import module, or fail if it doesn't exist; name = module.name, or fail if the name doesn't exist. Things are more compli

[Python-ideas] Re: Allow Path object instances in subprocess.Popen

2019-11-03 Thread Serhiy Storchaka
03.11.19 12:31, Anders Hovmöller пише: On 3 Nov 2019, at 10:28, Steven D'Aprano wrote: Given: values = ["Hello", b"World"] would you expect ' '.join(values) to return "Hello b'World'" because that's what you'll get calling str automatically. Side note! That misfeature of python 3

[Python-ideas] Re: Using 'with' with extra brackets for nicer indentation

2019-11-15 Thread Serhiy Storchaka
15.11.19 12:40, Jonathan Fine пише: The original poster wanted, inside 'with' context management, to open several files. Context management is, roughly speaking, deferred execution wrapped in a try ... except statement. In case of open() there is no deferred execution. The resource is ac

[Python-ideas] Re: Tuple Comprehension

2019-11-18 Thread Serhiy Storchaka
18.11.19 04:39, Daniel Zeng пише: Syntax for tuple comprehension, something like: (i, for i in range(10)) (**(i for i in range(10))) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.

[Python-ideas] Re: Update pep8 for stressing type hinted long parameter in functions

2019-11-27 Thread Serhiy Storchaka
Stefano Borini Wrote in message:r > This may be a pet peeve of mine, but with the introduction of typehints, more > and more function definitions have become longer than 80characters. This used > to seldom happen in the past.The problem, as I see it, is that there seem to > be a general tendenc

[Python-ideas] Re: Calendar.year()

2019-11-27 Thread Serhiy Storchaka
Abdur-Rahmaan Janhangeer Wrote in message:r > Greetings list,In the calendar module, i find it terribly unintuitive to have > a calendar.month but not a calendar.year, the default being > calendar.calendarSuggestion: replace calendar.calendar by > calendar.yearYours,Abdur-Rahmaan Janhangeerpyth

[Python-ideas] Re: namedtuple for dict.items()/collections.abc.Mappings.items()

2019-12-01 Thread Serhiy Storchaka
30.11.19 23:16, Soni L. пише: It'd be quite nice if dict.items() returned a namedtuple so all these x[0], x[1], el[0], el[1], etc would instead be x.key, x.value, el.key, el.value, etc. It would be more readable and more maintainable. It was discussed before. The problem is that creating, usin

[Python-ideas] Re: Sets for easy interning(?)

2019-12-03 Thread Serhiy Storchaka
03.12.19 02:25, Soni L. пише: This is an odd request but it'd be nice if, given a set s = {"foo"}, s["foo"] returned the "foo" object that is actually in the set, or KeyError if the object is not present. Even use-cases where you have different objects whose differences are ignored for __eq__

[Python-ideas] Re: Suggestion for language addition

2019-12-03 Thread Serhiy Storchaka
03.12.19 02:02, Jan Bakuwel пише: Idea: To include optional "end if", "end while", "end for" and "end name>", "end " in the language. The Python interpreter would test that any "end" matches with the correct corresponding statements and have the correct indentation, in other words throw an err

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-03 Thread Serhiy Storchaka
I general, I am against this proposition. It makes the language more complex without adding any benefit. There are already many ways of merging dicts, including the expression form. It conflicts with Counter. It can make the code more errorprone because + or | for dicts will no longer fail imme

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-03 Thread Serhiy Storchaka
03.12.19 07:04, Guido van Rossum пише: Actually there's no need to optimize the |= operator -- for strings we have to optimize += *because* strings are immutable, but for dicts we would define |= as essentially an alias for .update(), just like the relationship between += and .extend() for list

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

2019-12-03 Thread Serhiy Storchaka
03.12.19 13:53, Juancarlo Añez пише: There are many ugly recipes about to handle the common use case that could be handled by: def findfirst(regex, text, default=None, flags=0):      return next(finditer(regex, text, flags=flags), default=default) Oh, this is the most strange use of

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-03 Thread Serhiy Storchaka
03.12.19 21:04, Andrew Barnert via Python-ideas пише: On Dec 3, 2019, at 02:00, Serhiy Storchaka wrote: What it will return if implement | for dicts? It should be mentioned in the PEP. It should be tested with a preliminary implementation what behavior is possible and more natural. What is

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-03 Thread Serhiy Storchaka
03.12.19 20:51, Brett Cannon пише: On Tue, Dec 3, 2019 at 2:00 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: [SNIP] > ## What about performance? It should be mentioned in the PEP that `dict1 | dict2 | dict3` is less efficient than `{**dict1, **di

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

2019-12-04 Thread Serhiy Storchaka
04.12.19 03:46, Oscar Benjamin пише: result = next(re.finditer(...), None) if result is None: # raise or something else: # use result `next(re.finditer(...), None)` is a weird way of writing `re.search(...)`. `next(re.finditer(...), defaults)` is the same as `re.search(...) or defau

[Python-ideas] Re: Allow user extensions to operators [related to: Moving PEP 584 forward (dict + and += operators)]

2019-12-04 Thread Serhiy Storchaka
03.12.19 20:43, Brett Cannon пише: -1 from me. I can see someone not realizing an operator was changed, assuming it's standard semantics, and then having things break subtly. And debugging this wouldn't be fun either. To me this is monkeypatching without an explicit need for it, i.e. if you rea

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

2019-12-04 Thread Serhiy Storchaka
04.12.19 18:05, Guido van Rossum пише: On Wed, Dec 4, 2019 at 12:34 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: `next(re.finditer(...), None)` is a weird way of writing `re.search(...)`. `next(re.finditer(...), defaults)` is the same as `re.search(...) or

[Python-ideas] Re: Allow user extensions to operators [related to: Moving PEP 584 forward (dict + and += operators)]

2019-12-04 Thread Serhiy Storchaka
04.12.19 18:39, Random832 пише: On Wed, Dec 4, 2019, at 08:26, Serhiy Storchaka wrote: 03.12.19 20:43, Brett Cannon пише: -1 from me. I can see someone not realizing an operator was changed, assuming it's standard semantics, and then having things break subtly. And debugging this wouldn

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

2019-12-04 Thread Serhiy Storchaka
04.12.19 20:01, Guido van Rossum пише: On Wed, Dec 4, 2019 at 9:18 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: [Guido]  > I think I am +1 on  > adding re.findfirst() as proposed by the OP. It is not clear what it should return. A Match obje

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-04 Thread Serhiy Storchaka
04.12.19 20:24, Guido van Rossum пише: Your example uses sets -- did you mean {3: 4} instead of {3}? Sorry. Yes, I meant {3: 4}. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org htt

[Python-ideas] Re: Moving PEP 584 forward (dict + and += operators)

2019-12-04 Thread Serhiy Storchaka
04.12.19 20:18, Guido van Rossum пише: On Tue, Dec 3, 2019 at 2:10 AM Serhiy Storchaka <mailto:storch...@gmail.com>> wrote: And the same question for |. Should `{} | Mapping()` and `{} | []` work? Ditto -- {} | Mapping() should work, but {} | [] should not. set() | Set() fall

[Python-ideas] Re: Suggestion for language addition

2019-12-04 Thread Serhiy Storchaka
05.12.19 04:43, Andrew Barnert via Python-ideas пише: Yes, you have to unlearn it. Exceptions are not that expensive in Python (and in a lot of other modern languages)—but even if they were, you’d still have to deal with the fact that Python uses them pervasively. Every for loop ends with an e

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

2019-12-04 Thread Serhiy Storchaka
On Wed, Dec 4, 2019 at 16:33 Juancarlo Añez > wrote: The OP thinks that the case for wanting just the string for a first regex match, or a verifiable default if there is no match, is way too common, that the advice on the web is not very good (it shoul

<    1   2   3   4   5   6   >