[Python-ideas] Decorator to avoid a mistake
fleblanc50
fleblanc50 at gmail.com
Tue Nov 22 16:07:17 EST 2016
Hi there,
I like python easy extend class and reusse code, but sometime I overwrite involontary some functions or variables from parents.
I think about a decorator to confirm overwrite is intended and put a warning if is not present.
class A:
def hello(self):
print('Hello A')
class B:
def hello(self):
print('Hello B')
class C:
@overwrite
def hello(self):
print('Hello C')
b=B()
c=C()
b.hello()
Warning overwrite hello method...
Hello B
c.hello()
Hello C
Dont know if this should be add to language this way or another, or if this should be in pylint only ...
Perhaps someone get better way to achieve this or something already exist?
May the python be with you,
Regards
More information about the Python-ideas
mailing list