How come the Python's logging module doesn't follow PEP8 conventions?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 01:24:13

The logging module was developed by a separate company in 2001, and was heavily based on Log4j. As such it follows the naming conventions the original author picked, which mirror the Log4j choices; the latter has a getLogger() method too.

Not until a year later did PEP 282 propose to add it to the standard library, by which time the naming convention was set in stone.

It is a known issue with the package, but it is not the only package to violate the PEP. From the linked Wiki:

PEP8 says - consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important.

  • So True, but can't not be changed, because of backward compatibility. logging2 maybe. -- techtonik
    • It's a low priority right now, unless there's an initiative to ensure the rest of the stdlib is made to conform to PEP8. -- VinaySajip

Last but not least, the styleguide itself has this to say on applying styleguides:

A Foolish Consistency is the Hobgoblin of Little Minds

A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important.

But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!

In particular: do not break backwards compatibility just to comply with this PEP!

'Fixing' logging would break backwards compatibility, which is just not worth it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!