This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vinay.sajip
Recipients vinay.sajip, zaneb
Date 2019-09-09.10:02:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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

    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__':

gives, for example,

Date User Action Args
2019-09-09 10:02:05vinay.sajipsetrecipients: + vinay.sajip, zaneb
2019-09-09 10:02:05vinay.sajipsetmessageid: <>
2019-09-09 10:02:05vinay.sajiplinkissue37857 messages
2019-09-09 10:02:05vinay.sajipcreate