Vinay Sajip <vinay_sa...@yahoo.co.uk> added the comment:

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

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37857>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to