Add hacking check D710 for LOG.warn()

Python 3 deprecated the logger.warn method, see:
https://docs.python.org/3/library/logging.html#logging.warning
so we prefer to use warning to avoid DeprecationWarning.

This patch adds a hacking check, similar to other projects, that enforces
using LOG.warning() instead of LOG.warn().

Change-Id: I424ccc14ec09dd6c7662aaee1096dfd56917aef2
This commit is contained in:
Michael Johnson
2021-11-30 00:20:52 +00:00
parent acd930d342
commit 256f889279
2 changed files with 12 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ import pycodestyle
# D707: basestring is not Python3-compatible, use str instead.
# D708: Do not use xrange. Use range for large loops.
# D709: LOG.audit is deprecated, please use LOG.info!
# D710: LOG.warn() is not allowed. Use LOG.warning()
UNDERSCORE_IMPORT_FILES = []
@@ -150,3 +151,13 @@ def check_no_log_audit(logical_line):
"""
if "LOG.audit(" in logical_line:
yield(0, "D709: LOG.audit is deprecated, please use LOG.info!")
@core.flake8ext
def check_no_log_warn(logical_line):
"""Disallow 'LOG.warn('
D710
"""
if logical_line.startswith('LOG.warn('):
yield(0, "D710:Use LOG.warning() rather than LOG.warn()")

View File

@@ -177,6 +177,7 @@ extension =
D707 = checks:check_no_basestring
D708 = checks:check_python3_xrange
D709 = checks:check_no_log_audit
D710 = checks:check_no_log_warn
paths = ./designate/hacking
[testenv:lower-constraints]