[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-06 Thread Guido van Rossum
Guido van Rossum added the comment: Thanks all! -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-06 Thread Guido van Rossum
Guido van Rossum added the comment: New changeset bef7d299eb911086ea5a7ccf7a9da337e38a8491 by Ben Avrahami in branch 'master': bpo-41905: Add abc.update_abstractmethods() (GH-22485) https://github.com/python/cpython/commit/bef7d299eb911086ea5a7ccf7a9da337e38a8491 --

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-04 Thread Ben Avrahami
Ben Avrahami added the comment: > Adding a function to recalculate will require everyone to use it I'd argue that this is akin to `functools.update_wrapper`. It too is a function that must be called in virtually every function decorator (the only function decorators that don't/needn't call

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-04 Thread Bar Harel
Bar Harel added the comment: > When instantiation fails, recheck to see the missing abstract methods had > been defined? I've written about it in the python-ideas discussion as well, and completely agree. There is no other approach that would guarantee correctness across all APIs, both

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-04 Thread Ben Avrahami
Ben Avrahami added the comment: Implementing this behavior automatically would be more complicated since you would also have to take subclasses into account. Current implementation enforces that the class is unused (as much as can be reasonably done) when its abstraction status is

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Guido van Rossum
Guido van Rossum added the comment: Yes, we could override ABCMeta.__setattr__ to do that. Though it seems this class is considered performance sensitive (else why have Modules/_abc.c) we would probably have to write it in C.-- --Guido (mobile) --

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: > you're effectively proposing to compute (or update) > __abstractmethods__ lazily. Would it be possible to do the update whenever the class dictionary is modified, in PyType_Modified() perhaps (using logic similar to __mro__ updates__)? I not pushing

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Guido van Rossum
Guido van Rossum added the comment: Hm, you're effectively proposing to compute (or update) __abstractmethods__ lazily. There are a number of subtleties with that, e.g. __abstractmethods__ is currently a frozenset, and a base class's __abstractmethods__ is used when computing the

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: Guido, can the method update be made automatic? When instantiation fails, recheck to see the missing abstract methods had been defined? >>> from abc import * >>> class P(ABC): @abstractmethod def m(self):

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Guido van Rossum
Guido van Rossum added the comment: Ah, okay. I wasn't familiar with @total_ordering so I assumed differently. Sorry for the continued misunderstanding. Perhaps we should just leave it alone completely then, since ISTM that any change to its implementation may cause subtle bugs in

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Ben Avrahami
Ben Avrahami added the comment: > Maybe you misunderstand what I tried to say? Possibly, right now, total_ordering avoids overriding any method that is declared, either in the class or its superclasses (except for object), regardless of whether or not it is abstract. For it to be ABC-aware,

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Guido van Rossum
Guido van Rossum added the comment: Why would that require more code? That’s already how it worked. Maybe you misunderstand what I tried to say? -- ___ Python tracker ___

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-03 Thread Ben Avrahami
Ben Avrahami added the comment: > I would prefer the isinstance(cls, ABCMeta) check to be inside that helper I had a little debate about this in my mind, I'll change it. > it's totally clear to me what @total_ordering should do -- it should define > __le__, __gt__ and __ge__ in terms of

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > it's totally clear to me what @total_ordering should do > -- it should define __le__, __gt__ and __ge__ in terms > of __lt__, and leave __lt__ alone, for some subclass to > implement. +1 -- ___ Python

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-02 Thread Guido van Rossum
Guido van Rossum added the comment: I still like to have a helper that recalculates the abstractness status of a class after adding some new methods (or deleting some). I would prefer the isinstance(cls, ABCMeta) check to be inside that helper, so that you could call it unconditionally

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I'm going to ignore this issue until you two have reached agreement. > I recommend using some example code. That won't be necessary. I now understand what the OP is trying to do and am going to recommend against it. Guido, this really a decision for

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-02 Thread Guido van Rossum
Guido van Rossum added the comment: I'm going to ignore this issue until you two have reached agreement. I recommend using some example code. -- ___ Python tracker ___

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-02 Thread Ben Avrahami
Ben Avrahami added the comment: This is a behavior that the PR changes. total_ordering should be able to override/implement abstract methods (in my opinion). If this ends up a strickling point then we can exclude total_ordering from this issue. Regardless, I think that this behavior is

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-02 Thread Raymond Hettinger
Raymond Hettinger added the comment: You might be misunderstanding what @total_ordering does. It can't be used by subclasses to override abstract methods. >>> from abc import abstractmethod, ABC >>> from functools import total_ordering >>> class X(ABC): @abstractmethod def

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-02 Thread Ben Avrahami
Ben Avrahami added the comment: Good points all, that I will try to address one by one: Firstly, this function is by no means mandatory for "post-creation mixins". Such tools can still be used without calling it (and remain ABC unaware), with absolutely no change in functionality. Indeed,

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: The downside of this proposal is that it is tightly coupled with class creation process. It requires all existing class decorators, metaclasses, and code generators to start caring about something that isn't part of their core functionality (very few

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-01 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +gvanrossum ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-01 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-01 Thread Ben Avrahami
Ben Avrahami added the comment: for the functionality to work, `total_ordering` needs to change to also override abstract methods. I believe this is an OK change since total_ordering implicitly dictates that the comparison methods are interchangable. Thus, implementing some comparison

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-01 Thread Roundup Robot
Change by Roundup Robot : -- keywords: +patch nosy: +python-dev nosy_count: 2.0 -> 3.0 pull_requests: +21502 stage: -> patch review pull_request: https://github.com/python/cpython/pull/22485 ___ Python tracker

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-01 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue41905] add update_abstractmethods function to update an ABC's abstract methods

2020-10-01 Thread Ben Avrahami
New submission from Ben Avrahami : python-ideas discussion: https://mail.python.org/archives/list/python-id...@python.org/thread/6BNJ3YSEBPHEPGXSAZGBW3TJ64ZGZIHE/ In order to allow "decorator mixins" (most notably dataclass and total_ordering) to implement ABCs, new functionality is needed. I