[Python-ideas] Re: Pre PEP: Python Literals (was custom strings before)

2021-06-10 Thread Stephan Hoyer
On Thu, Jun 10, 2021 at 7:10 AM Chris Angelico wrote: > This proposal is basically for a way to take an f-string-like > construct and, instead of calling format() on each of the values and > joining them together into a string, you do something else with it. Or > from a language perspective, you

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-27 Thread Stephan Hoyer
On Sat, Sep 26, 2020 at 8:40 PM Steven D'Aprano wrote: > On Sat, Sep 26, 2020 at 01:47:56PM -0300, Sebastian Kreft wrote: > > > In this fashion have you considering having keyword only indices, that is > > to only allow either obj[1, 2] or obj[row=1, col=2] (if the class > supports > > it), and

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Stephan Hoyer
On Tue, Sep 1, 2020 at 9:59 AM David Mertz wrote: > On Tue, Sep 1, 2020 at 11:45 AM Steven D'Aprano > wrote: > >> (8) Dict unpacking is permitted: >> >> items = {'spam': 1, 'eggs': 2} >> obj[index, **items] >> # equivalent to obj[index, spam=1, eggs=2] >> > > I would prefer to

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-15 Thread Stephan Hoyer
On Sat, Aug 15, 2020 at 8:27 PM Guido van Rossum wrote: > On Sat, Aug 15, 2020 at 8:02 PM Todd wrote: > >> On Sat, Aug 15, 2020 at 7:26 PM Stefano Borini >> wrote: >> >>> > QUESTION >>> > Suppose we have >>> > >>> d[x=1, y=2] = 42 >>> > >>> d[x=1, y=2] >>> > 42 >>> > where d is an

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-08-07 Thread Stephan Hoyer
On Fri, Aug 7, 2020 at 6:29 PM Stephan Hoyer wrote: > On Fri, Aug 7, 2020 at 9:12 AM Ricky Teachey wrote: > >> On Fri, Aug 7, 2020 at 4:19 AM Steven D'Aprano >> wrote: >> >>> On Fri, Aug 07, 2020 at 05:54:18PM +1000, Steven D'Aprano wrote: >>> >

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-08-07 Thread Stephan Hoyer
On Fri, Aug 7, 2020 at 9:12 AM Ricky Teachey wrote: > On Fri, Aug 7, 2020 at 4:19 AM Steven D'Aprano > wrote: > >> On Fri, Aug 07, 2020 at 05:54:18PM +1000, Steven D'Aprano wrote: >> >> > This proposal doesn't say anything about reversing the decision made >> all >> > those years ago to bundle

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-21 Thread Stephan Hoyer
dexing with keyword arguments like da[space=0] > > """ > > This would be the thing I would think of first when indexing with > keywords. But, there are a few points about named dimensions: > > First, using it for named dimensions, means you don't actually need

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-19 Thread Stephan Hoyer
On Fri, Jul 17, 2020 at 9:22 PM Ricky Teachey wrote: > >>> # The positional arguments aren't part of the KeyObject > >>> d[a, b:c, d, e=5, f=6] == d.__getitem__((a, b:c, d), KeyObject(e=5, > f=6)) > > This raises a question that needs to be answered, then: what would be the > utility of mixing

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

2020-02-21 Thread Stephan Hoyer
On Fri, Feb 21, 2020 at 12:43 AM Steven D'Aprano wrote: > On Thu, Feb 20, 2020 at 02:19:13PM -0800, Stephan Hoyer wrote: > > > > > Strong +1 for an array.zeros() constructor, and/or a lower level > > > array.empty() which doesn't pre-fill values. > > > > &

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

2020-02-20 Thread Stephan Hoyer
On Thu, Feb 20, 2020 at 2:11 PM Chris Angelico wrote: > On Fri, Feb 21, 2020 at 8:52 AM Stephan Hoyer wrote: > > > > On Thu, Feb 20, 2020 at 12:41 PM Steve Jorgensen > wrote: > >> > >> Christopher Barker wrote: > >> ... > >> > &g

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

2020-02-20 Thread Stephan Hoyer
On Thu, Feb 20, 2020 at 12:41 PM Steve Jorgensen wrote: > Christopher Barker wrote: > ... > > > Perhaps the OP wanted the internal array size initialized, but not > used. > > Currently the internal array will automatically be reallocated to grow as > > needed. Which could be a performance hit if

Re: [Python-ideas] Using rightarrow "->" for typing annotation of functions

2019-04-25 Thread Stephan Hoyer
On Thu, Apr 25, 2019 at 1:51 PM Ivan Levkivskyi wrote: > TBH, I don't think it is so bad that it requires a new syntax. But I am > not strongly against it either. What I would like to add here is that if we > will go with the replacement: > > Callable[[X, Y], Z] becomes (X, Y) -> Z > > then we

Re: [Python-ideas] New explicit methods to trim strings

2019-04-02 Thread Stephan Hoyer
On Tue, Apr 2, 2019 at 5:43 PM Eric V. Smith wrote: > PS: I really tried to find a way to use := in this example so I could > put the assignment inside the 'if' statement, but as I think Tim Peters > pointed out, without C's comma operator, you can't. > Conceivably cut_prefix could return None

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

2019-03-18 Thread Stephan Hoyer
On Mon, Mar 18, 2019 at 3:42 PM Greg Ewing wrote: > Tim Delaney wrote: > > I would argue the opposite - the use of "is" shows a clear knowledge > > that True and False are each a singleton and the author explicitly > > intended to use them that way. > > I don't think you can infer that. It could

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

2019-03-09 Thread Stephan Hoyer
Would __iadd__ and __isub__ be added to collections.abc.MutableMapping? This would be consistent with other infix operations on mutable ABCs, but could potentially break backwards compatibility for anyone who has defined a MutableMapping subclass that implements __add__ but not __iadd__. On Sat,

Re: [Python-ideas] Backtick expression: similar to a shorter lambda syntax

2019-01-22 Thread Stephan Hoyer
On Mon, Jan 21, 2019 at 8:47 AM Jonathan Fine wrote: > > Backtick expressions work exactly like lambdas, except that they are > bound to the instance they are created in every time that class is used to > create one. > > I would if possible very much like to see some real world examples of >

Re: [Python-ideas] NAN handling in the statistics module

2019-01-06 Thread Stephan Hoyer
On Sun, Jan 6, 2019 at 4:27 PM Steven D'Aprano wrote: > I propose adding a "nan_policy" keyword-only parameter to the relevant > statistics functions (mean, median, variance etc), and defining the > following policies: > > IGNORE: quietly ignore all NANs > FAIL: raise an exception if

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

2018-07-30 Thread Stephan Hoyer
On Sat, Jul 28, 2018 at 9:44 AM Jonathan Fine wrote: > By all means start a PEP (on github) if you find it helps you. I think > it's too early. > > If this problem has a pure Python solution, then I think it best to > develop it as a third party module. I suggest the name slicetools. > When

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

2018-07-26 Thread Stephan Hoyer
On Mon, Jul 23, 2018 at 4:37 PM David Mertz wrote: > I find pandas.IndexSlice makes a lot of operations easier to spell. As > simple as it is, it's a valuable capability. Rather than every library—or a > number of them anyway—creating the same 4 lines of code with a different > name, it would be

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

2018-07-23 Thread Stephan Hoyer
On Mon, Jul 23, 2018 at 4:19 PM Stefan Behnel wrote: > Stephan Hoyer schrieb am 23.07.2018 um 18:01: > > I think a SliceHelper class like this is a reasonable solution, but there > > would be a lot of value having it a standard place somewhere in the > >

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

2018-07-23 Thread Stephan Hoyer
On Mon, Jul 23, 2018 at 4:24 AM Paul Moore wrote: > I thought the reason the proposal got nowhere was because it's pretty > simple to define it yourself: > > >>> class SliceHelper: > ... def __getitem__(self, slice): > ... return slice > ... > >>> SH = SliceHelper() > >>> SH[1::3] >

Re: [Python-ideas] a set of enum.Enum values rather than the construction of bit-sets as the "norm"?

2017-12-29 Thread Stephan Hoyer
We already have a built-in immutable set for Python. It's called frozenset. On Fri, Dec 29, 2017 at 10:56 AM Chris Angelico wrote: > On Sat, Dec 30, 2017 at 2:38 AM, Steven D'Aprano > wrote: > > The lack of support for the `in` operator is a major

Re: [Python-ideas] PEP 554: Stdlib Module to Support Multiple Interpreters in Python Code

2017-09-07 Thread Stephan Hoyer
On Thu, Sep 7, 2017 at 5:15 PM Nathaniel Smith wrote: > On Thu, Sep 7, 2017 at 4:23 PM, Nick Coghlan wrote: > > The gist of the idea is that with subinterpreters, your starting point > > is multiprocessing-style isolation (i.e. you have to use pickle to > >

Re: [Python-ideas] namedtuple literals [Was: RE a new namedtuple]

2017-07-19 Thread Stephan Hoyer
On Wed, Jul 19, 2017 at 6:08 PM, Guido van Rossum wrote: > Regarding that spec, I think there's something missing: given a list (or > tuple!) of values, how do you turn it into an 'ntuple'? That seems a common > use case, e.g. when taking database results like row_factory in

Re: [Python-ideas] Augmented assignment syntax for objects.

2017-04-28 Thread Stephan Hoyer
On Fri, Apr 28, 2017 at 4:55 AM, Tin Tvrtković wrote: > I'm going to posit we need declarative classes. (This is what a library > like attrs provides, basically.) For a class to be declarative, it needs to > be possible to inspect the class for its attributes and more. > >

Re: [Python-ideas] Binary arithmetic does not always call subclasses first

2017-04-24 Thread Stephan Hoyer
hows that that note hasn't changed in 10 years: > https://github.com/python/cpython/blame/master/ > Doc/reference/datamodel.rst#L2210 > > On Mon, Apr 24, 2017 at 3:15 PM, Terry Reedy <tjre...@udel.edu> wrote: > >> On 4/24/2017 12:14 PM, Stephan Hoyer wrote: >> >> Ba

Re: [Python-ideas] Binary arithmetic does not always call subclasses first

2017-04-24 Thread Stephan Hoyer
On Sun, Apr 23, 2017 at 10:57 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > Stephan Hoyer wrote: > >> In practice, CPython requires that the right operand defines a different >> method before it defers to it. >> > > I'm not sure exactly what the rationa

[Python-ideas] Binary arithmetic does not always call subclasses first

2017-04-23 Thread Stephan Hoyer
I recently filed this as a bug, and was asked to repost to python-dev or python-ideas for greater visibility: http://bugs.python.org/issue30140 Without further ado, here is my original report: --- We are writing a system for overloading NumPy operations (see PR [1] and

Re: [Python-ideas] Callable Enum values

2017-04-21 Thread Stephan Hoyer
On Fri, Apr 21, 2017 at 9:43 AM, Ethan Furman wrote: > You have to use the complete module name? Instead of `from callable_enum > import Enum, Value`? Ouch Yeah... it took me a while to come around to this one. But the rule does start to pay off in large code bases.

Re: [Python-ideas] Callable Enum values

2017-04-21 Thread Stephan Hoyer
On Thu, Apr 20, 2017 at 10:58 AM, Ethan Furman wrote: > I'm curious, what did you find ugly with: > > class TestEnum(CallableEnum): > > @enum > def hello(text): > "a pleasant greeting" > print('hello,', text) > > @enum

[Python-ideas] Callable Enum values

2017-04-14 Thread Stephan Hoyer
Enums are great. They allow you cleanly define a set of statically defined options. One way that I've found myself using enums recently is for dispatching (as keys in a dictionary) between different interchangeable functions or classes. My code looks something like this: from enum import Enum

Re: [Python-ideas] Fwd: Define a method or function attribute outside of a class with the dot operator

2017-02-10 Thread Stephan Hoyer
On Fri, Feb 10, 2017 at 9:20 AM, Nick Coghlan wrote: > What I would personally hope to see from the proposal is that given: > > class Spam: > pass > > def Spam.func(self): > return __class__ > > the effective runtime behaviour would be semantically

Re: [Python-ideas] Alternative to PEP 532: delayed evaluation of expressions

2016-11-10 Thread Stephan Hoyer
On Sun, Nov 6, 2016 at 5:32 PM, Nathaniel Smith wrote: > Filtering out a subset of rows from a data frame in pandas; 'height' > and 'age' refer to columns in the data frame (equivalent to > data_frame[data_frame["height"] > 100 and data_frame["age"] < 5], but > more ergonomic and