为什么Python的日志记录模块不遵循PEP8约定? [英] How come the Python's logging module doesn't follow PEP8 conventions?

查看:111
本文介绍了为什么Python的日志记录模块不遵循PEP8约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是出于历史目的的好奇心:

This is is just a curiosity with historical purposes:

我想知道是否有人知道为什么使用非常广泛的(和核心模块) PEP -8命名约定.

I was wondering if someone knows why the very widely used (and core module) logging doesn't follow the Python's PEP-8 naming convention.

例如,在

>>> import logging
>>> log = logging.getLogger("hello")

我希望它是get_logger,但不是.

当涉及到函数名称时,PEP8标准说:

When it comes to function names, the PEP8 standard says:

mixedCase仅在已经是 流行的样式(例如threading.py),以向后保留 兼容性.

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

是这样吗?如果是这样,它还必须与其他logging保持向后兼容性吗?还是仅仅是logging的开发人员感觉要使用驼峰式命名方式?

Was that the case? If so, with what other logging thingy it had to maintain backwards compatibility? Or was it just that the developers of logging felt like using camel-case naming?

当然,该模块文档齐全,一点也不重要.我很好奇.

Of course, the module is well documented and is not a big deal at all. I'm just curious.

推荐答案

logging模块由也是getLogger()方法.

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.

直到一年后, PEP 282 提议将其添加到标准库,那时命名约定是固定不变的.

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.

这是该软件包的已知问题,但这不是唯一违反的软件包PEP.从链接的Wiki:

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

PEP8说-与该样式指南的一致性很重要.项目内的一致性更重要.一个模块或功能的一致性至关重要.

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.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆