Message351400
That code in the wild that sets the level attribute directly is wrong and should be changed, right? The documentation has always been clear that setLevel() should be used. If we now take steps to support setting the level via attribute, isn't that encouraging bypassing the documented APIs? I'm not sure such misuse is widespread.
Using a property might seem a good solution, but there is a performance impact, so I am not keen on this change. I don't know what the real-world performance impact would be, but this simple script to look at the base access timing:
import timeit
class Logger(object):
def __init__(self):
self._levelprop = self.level = 0
@property
def levelprop(self):
return self.level
def main():
logger = Logger()
print(timeit.timeit('logger.level', globals=locals()))
print(timeit.timeit('logger.levelprop', globals=locals()))
if __name__ == '__main__':
main()
gives, for example,
0.12630631799993353
0.4208384449998448 |
|
Date |
User |
Action |
Args |
2019-09-09 10:02:05 | vinay.sajip | set | recipients:
+ vinay.sajip, zaneb |
2019-09-09 10:02:05 | vinay.sajip | set | messageid: <1568023325.23.0.813173753949.issue37857@roundup.psfhosted.org> |
2019-09-09 10:02:05 | vinay.sajip | link | issue37857 messages |
2019-09-09 10:02:05 | vinay.sajip | create | |
|