[Python-ideas] Generic NamedTuples

2021-02-08 Thread Ben Avrahami
In both python 3.7 and 3.8, typing.NamedTuple had some strange behaviour regarding multiple inheritance. This behaviour was solved in 3.9 (bpo-36517), but this fix also barred me from a feature very close to my heart: the generic named tuple ``` T = TypeVar('T') class LLNode(NamedTuple, Generic[T]

[Python-ideas] typing.Maybe type annotation

2021-03-09 Thread Ben Avrahami
Hi all, I recently ran into a problem trying to adapt mypy into an older codebase, and it got me thinking about a potential addition to the typing library. This idea comes in two parts (that can even be taken individually): the first is to allow the False singleton literal to be used in type annot

[Python-ideas] allow full expressions in decorators

2020-02-03 Thread Ben Avrahami
Hi all, decorators are a very powerful feature in python, but it's syntax is strangely restrictive. decorator ::= "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE for 99% of cases this is not a hindrance, but sometimes we'd rather be able to use full expression syntax. consider the follow

[Python-ideas] Re: allow full expressions in decorators

2020-02-04 Thread Ben Avrahami
changing this, but it keeps coming up, and in other > cases we don’t restrict the grammar (except when there are real > ambiguities). So maybe the SC can accept a PRP for this? > > On Mon, Feb 3, 2020 at 15:47 Ben Avrahami wrote: > >> Hi all, decorators are a very powerful featur

[Python-ideas] giving set.add a return value

2020-06-25 Thread Ben Avrahami
Hey all, Often I've found this kind of code: seen = set() for i in iterable: if i in seen: ... # do something in case of duplicates else: seen.add(i) ... # do something in case of first visit This kind of code appears whenever one needs to check for duplicates in case of a user-s

[Python-ideas] Re: giving set.add a return value

2020-06-25 Thread Ben Avrahami
On Thu, Jun 25, 2020 at 6:44 PM Alex Hall wrote: > Previous discussions on this: > > > https://mail.python.org/archives/list/[email protected]/thread/ASHOHN32BQPBVPIGBZQRS24XHXFMB6XZ/ > > https://mail.python.org/archives/list/[email protected]/thread/K5SS62AB5DFFZIJ7ASKPLB2P3XGSYFPC/

[Python-ideas] Re: giving set.add a return value

2020-06-25 Thread Ben Avrahami
On Thu, Jun 25, 2020 at 7:55 PM Christopher Barker wrote: > On Thu, Jun 25, 2020 at 9:02 AM Steele Farnsworth > wrote: > indeed -- and that is pretty darn baked in to Python, so I don't think > it's going to change. > > Except this convention doesn't hold for dict.setvalue (which I did misspell,

[Python-ideas] keyword arguments before positional arguments- syntax inconsistency

2020-08-25 Thread Ben Avrahami
consider the following function: def foo(a,b,c,x): pass The following calls are equivalent: foo(1,2,3, x=0) foo(*(1,2,3), x=0) However, since python allows keyword arguments before star-unpacking, you can also do: foo(x=0, *(1, 2, 3)) But removing the unpacking, would resul

[Python-ideas] Trouble with "decorator mixins" and ABCs

2020-09-24 Thread Ben Avrahami
Hey all, I recently ran into some trouble and that I think deserves some attention. Consider the following case: class A(ABC): @abstractmethod def __lt__(self, other): pass @dataclass(order=True) class B(A): x: int = 0 class C(B): pass

[Python-ideas] Re: Trouble with "decorator mixins" and ABCs

2020-09-24 Thread Ben Avrahami
On Thu, Sep 24, 2020 at 6:59 PM Guido van Rossum wrote: > Interesting problem. Since the solution is just updating > `__abstractmethods__`, this could be done in the `@dataclass` decorator, no > new ABC needed. > > This issue also pertains to total_ordering (and perhaps other std library class-de

[Python-ideas] Re: Trouble with "decorator mixins" and ABCs

2020-09-24 Thread Ben Avrahami
On Thu, Sep 24, 2020 at 7:02 PM Eric V. Smith wrote: > Does anyone know if attrs handles this? I don't have a recent version > installed, but I'll take a look later today. > attrs handles this only if you set slots=True (which makes sense since attrs would have to rebuild the class)

[Python-ideas] Re: Trouble with "decorator mixins" and ABCs

2020-09-29 Thread Ben Avrahami
On Tue, Sep 29, 2020 at 4:53 PM Bar Harel wrote: > I'd like to bring another insight to the table: According to the pep, > "Dynamically > adding abstract methods to a class, or attempting to modify the abstraction > status of a method or class once it is created, are not supported." > > The noti

[Python-ideas] Re: Trouble with "decorator mixins" and ABCs

2020-09-29 Thread Ben Avrahami
ed to modify `__abstractmethods__` and perform abstract logic on their own- I don't see why the standard library should keep such computations unavailable. On Tue, Sep 29, 2020 at 6:41 PM Eric V. Smith wrote: > On 9/29/2020 10:49 AM, Ben Avrahami wrote: > > On Tue, Sep 29, 2020 at 4:53

[Python-ideas] Re: Trouble with "decorator mixins" and ABCs

2020-10-01 Thread Ben Avrahami
mented, overruling whatever > the PEP says? > > On Wed, Sep 30, 2020 at 00:01 Ben Avrahami wrote: > >> I encountered this problem when I needed to implement a class that >> defined all 4 of the comparison operators, once with `dataclass` (for one >> implementation) and once

[Python-ideas] Re: Trouble with "decorator mixins" and ABCs

2020-10-01 Thread Ben Avrahami
t 1, 2020 at 5:08 PM Guido van Rossum wrote: > That might work (though not for older Python versions). What kind of API > were you thinking of for adding and deleting abstract methods? > > On Thu, Oct 1, 2020 at 01:07 Ben Avrahami wrote: > >> >> >> I suppose it'

[Python-ideas] async types?

2020-11-25 Thread Ben Avrahami
Hi all, this is a general feeler for if this idea has any traction: All too often I see the following pattern in asyncio 3rd-party libs, either in their own source code or in the inusage: ``` inst = SomeClass() await inst.initialize() ``` What happens here is that, since coroutines cannot be used