[Python-ideas] Decorator to avoid a mistake

France3 fleblanc50 at gmail.com
Sat Nov 26 07:24:38 EST 2016


If we can sawp base class object with a flag It would be possible to use
a special base object

that could warn for this kind of problem? This can let write specifics
metaclass witch

replace base object by default, and when all is checked for end user
don't use the flag...

Does it is possible? What do you think about?

Le 26/11/2016 à 12:26, Nick Coghlan a écrit :
> On 26 November 2016 at 21:15, Paul Moore <p.f.moore at gmail.com> wrote:
>> On 26 November 2016 at 07:16, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>> On 26 November 2016 at 13:26, Guido van Rossum <guido at python.org> wrote:
>>>> I think one reason why such proposals are unwelcome to experienced users may
>>>> be that when done right this is totally legitimate, and the requirement to
>>>> use an @override decorator is just making code more verbose with very little
>>>> benefit.
>>> It's also the case that if we're going to provide decorators to help
>>> with class definitions, there are more valuable things that we can do
>>> beyond merely warning about accidental method and attribute overrides.
>> This comment made me think about another potential issue with the
>> @override proposal. If overriding a method without using the decorator
>> were to produce a warning, how would that interact with custom class
>> decorators or metaclasses that inject methods into a class? Would they
>> have to take special care to detect and mark overrides?
> It would potentially be even more annoying than that - if we did
> something like this without being sufficiently careful about it, you'd
> need to use the decorator any time you overwrote a special method
> that's actually implemented on "object". Ditto for method overrides
> when inheriting from an abstract base class, or any other base class
> that defines an API where the base class method implementation raises
> NotImplementedError.
>
> By contrast, if it's opt-in via a class decorator, then folks that
> want additional definition time assistance from the interpreter can
> request that explicitly, while existing code remains unaffected.
>
> Cheers,
> Nick.
>




More information about the Python-ideas mailing list