Skip to content

Commit 9c35a4d

Browse files
committed
[#3287] fix pylint warnings
- C0115: Missing class docstring (missing-class-docstring) - C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck) - C0201: Consider iterating the dictionary directly instead of calling .keys() (consider-iterating-dictionary) - C0206: Consider iterating with .items() (consider-using-dict-items) - C0411: standard import "..." should be placed before "..." (wrong-import-order) - C0415: Import outside toplevel (...) (import-outside-toplevel) - C1802: Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty (use-implicit-booleaness-not-len) - E0001: Parsing failed: 'invalid syntax (<unknown>, line 2313)' (syntax-error) - E0401: Unable to import '...' (import-error) - E0602: Undefined variable 'l' (undefined-variable) - R0205: Class 'VagrantEnv' inherits from object, can be safely removed from bases in python3 (useless-object-inheritance) - E1101: Instance of 'NSECBASE' has no 'dump_fixedpart' member (no-member) - E1123: Unexpected keyword argument 'capture' in method call (unexpected-keyword-arg) - R0902: Too many instance attributes (too-many-instance-attributes) - R0913: Too many arguments (too-many-arguments) - R0916: Too many boolean expressions in if statement (6/5) (too-many-boolean-expressions) - R1717: Consider using a dictionary comprehension (consider-using-dict-comprehension) - R1722: Consider using 'sys.exit' instead (consider-using-sys-exit) - R1732: Consider using 'with' for resource-allocating operations (consider-using-with) - R1735: Consider using '{}' instead of a call to 'dict'. (use-dict-literal) - W0102: Dangerous default value sys.argv[1:] (builtins.list) as argument (dangerous-default-value) - W0102: Dangerous default value {} as argument (dangerous-default-value) - W0106: Expression "[f.write('%02x' % x) for x in bin_address]" is assigned to nothing (expression-not-assigned) - W0107: Unnecessary pass statement (unnecessary-pass) - W0201: Attribute 'config' defined outside __init__ (attribute-defined-outside-init) - W0404: Reimport '...' (imported line ...) (reimported) - W0611: Unused import ... (unused-import) - W0612: Unused variable '...' (unused-variable) - W0613: Unused argument '...' (unused-argument) - W0621: Redefining name '...' from outer scope (line 1471) (redefined-outer-name) - W0622: Redefining built-in '...' (redefined-builtin) - W0707: Consider explicitly re-raising using 'raise ... from ...' (raise-missing-from) - W0718: Catching too general exception Exception (broad-exception-caught) - W1202: Use lazy % formatting in logging functions (logging-format-interpolation) - W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation) - W1308: Duplicate string formatting argument 'connection_type', consider passing as named argument (duplicate-string-formatting-argument) - W1401: Anomalous backslash in string: '\/'. String constant might be missing an r prefix. (anomalous-backslash-in-string) - W1406: The u prefix for strings is no longer necessary in Python >=3.0 (redundant-u-string-prefix) - W1514: Using open without explicitly specifying an encoding (unspecified-encoding) - W4901: Deprecated module 'optparse' (deprecated-module) - W4904: Using deprecated class SafeConfigParser of module configparser (deprecated-class)
1 parent 8e37580 commit 9c35a4d

File tree

12 files changed

+291
-304
lines changed

12 files changed

+291
-304
lines changed

doc/sphinx/api2doc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def read_input_files(files):
3333
if name.startswith('_'):
3434
print("Skipping %s (starts with underscore)" % f)
3535
continue
36-
with open(f) as fp:
36+
with open(f, encoding='utf-8') as fp:
3737
print("Processing %s" % f)
3838
# use OrderedDict to preserve order of fields in cmd-syntax
3939
try:
@@ -42,7 +42,7 @@ def read_input_files(files):
4242
print(f'\nError while processing {f}: {e}\n\n')
4343
raise
4444
if name != descr['name']:
45-
exit("Expected name == descr['name'], but name is {name} and descr['name'] is {descr['name']}")
45+
raise ValueError("Expected name == descr['name']. Name is {name} and descr['name'] is {descr['name']}.")
4646

4747
apis[name] = descr
4848

@@ -196,7 +196,7 @@ def generate(in_files, out_file):
196196
rst = generate_rst(apis)
197197

198198
if out_file:
199-
with open(out_file, 'w') as f:
199+
with open(out_file, 'w', encoding='utf-8') as f:
200200
f.write(rst)
201201
print('Wrote generated RST content to: %s' % out_file)
202202
else:

doc/sphinx/conf.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@
66
# full list see the documentation:
77
# http://www.sphinx-doc.org/en/master/config
88

9+
import os
10+
import sys
11+
from shutil import copyfile
12+
913
# -- Path setup --------------------------------------------------------------
1014

15+
# to avoid sphinx.errors.SphinxParallelError: RecursionError: maximum recursion depth exceeded while pickling an object
16+
sys.setrecursionlimit(5000)
17+
1118
# If extensions (or modules to document with autodoc) are in another directory,
1219
# add these directories to sys.path here. If the directory is relative to the
1320
# documentation root, use os.path.abspath to make it absolute, like shown here.
14-
#
15-
import os
16-
# import sys
17-
# sys.path.insert(0, os.path.abspath('.'))
21+
SRC_DIR = os.path.abspath(os.path.dirname(__file__))
22+
sys.path.append(SRC_DIR)
1823

19-
# to avoid sphinx.errors.SphinxParallelError: RecursionError: maximum recursion depth exceeded while pickling an object
20-
import sys
21-
sys.setrecursionlimit(5000)
24+
import api2doc # noqa # pylint: disable=wrong-import-position
25+
import mes2doc # noqa # pylint: disable=wrong-import-position
2226

2327
# -- Project information -----------------------------------------------------
2428

2529
project = 'Kea'
26-
copyright = '2019-2024, Internet Systems Consortium'
30+
copyright = '2019-2024, Internet Systems Consortium' # pylint: disable=redefined-builtin
2731
author = 'Internet Systems Consortium'
2832

2933
# get current kea version
3034
config_ac_path = '../../configure.ac'
3135
changelog_path = '../../ChangeLog'
3236
release = 'UNRELEASED'
33-
with open(config_ac_path) as f:
37+
with open(config_ac_path, encoding='utf-8') as f:
3438
for line in f.readlines():
3539
if line.startswith('AC_INIT(kea'):
3640
parts = line.split(',')
@@ -39,7 +43,7 @@
3943
# that this is the final release.
4044
dash_parts = release.split('-')
4145
candidate_release = dash_parts[0]
42-
with open(changelog_path) as changelog_file:
46+
with open(changelog_path, encoding='utf-8') as changelog_file:
4347
first_line = changelog_file.readline()
4448
if candidate_release in first_line and "released" in first_line:
4549
release = candidate_release
@@ -251,23 +255,15 @@
251255
# Do generation of api.rst and kea-messages.rst here in conf.py instead of Makefile.am
252256
# so they are available on ReadTheDocs as there makefiles are not used for building docs.
253257
def run_generate_docs(_):
254-
import os
255-
import sys
256-
src_dir = os.path.abspath(os.path.dirname(__file__))
257-
print(src_dir)
258-
sys.path.append(src_dir)
259-
260-
import api2doc
261-
with open(os.path.join(src_dir, 'api-files.txt')) as af:
258+
with open(os.path.join(SRC_DIR, 'api-files.txt'), encoding='utf-8') as af:
262259
api_files = af.read().split()
263-
api_files = [os.path.abspath(os.path.join(src_dir, '../..', af)) for af in api_files]
264-
api2doc.generate(api_files, os.path.join(src_dir, 'api.rst'))
260+
api_files = [os.path.abspath(os.path.join(SRC_DIR, '../..', af)) for af in api_files]
261+
api2doc.generate(api_files, os.path.join(SRC_DIR, 'api.rst'))
265262

266-
import mes2doc
267-
with open(os.path.join(src_dir, 'mes-files.txt')) as mf:
263+
with open(os.path.join(SRC_DIR, 'mes-files.txt'), encoding='utf-8') as mf:
268264
mes_files = mf.read().split()
269-
mes_files = [os.path.abspath(os.path.join(src_dir, '../..', mf)) for mf in mes_files]
270-
mes2doc.generate(mes_files, os.path.join(src_dir, 'kea-messages.rst'))
265+
mes_files = [os.path.abspath(os.path.join(SRC_DIR, '../..', mf)) for mf in mes_files]
266+
mes2doc.generate(mes_files, os.path.join(SRC_DIR, 'kea-messages.rst'))
271267

272268
# Sphinx has some limitations. It can't import files from outside its directory, which
273269
# in our case is src/sphinx. On the other hand, we need to have platforms.rst file
@@ -292,10 +288,9 @@ def run_generate_docs(_):
292288
['../examples/template-ha-mt-tls/kea-dhcp4-2.conf', 'template-ha-mt-tls-dhcp4-2.conf']
293289
]
294290

295-
from shutil import copyfile
296291
for [a, b] in FILES_TO_COPY:
297-
src = os.path.join(src_dir, a)
298-
dst = os.path.join(src_dir, 'arm', b)
292+
src = os.path.join(SRC_DIR, a)
293+
dst = os.path.join(SRC_DIR, 'arm', b)
299294
print("Copying %s to %s" % (src, dst))
300295
copyfile(src, dst)
301296

doc/sphinx/mes2doc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ def parse_args():
3636
def read_input_files(files):
3737
messages = {}
3838
for f in files:
39-
with open(f) as fp:
39+
with open(f, encoding='utf-8') as fp:
4040
print("Processing %s" % f)
41-
namespace = None
4241
msg_descr = None
4342
msg_id = None
4443
msg_text = None
@@ -119,7 +118,7 @@ def generate(in_files, out_file):
119118
rst = generate_rst(messages)
120119

121120
if out_file:
122-
with open(out_file, 'w') as f:
121+
with open(out_file, 'w', encoding='utf-8') as f:
123122
f.write(rst)
124123
print('Wrote generated RST content to: %s' % out_file)
125124
else:

0 commit comments

Comments
 (0)