Skip to content

Commit a6fe043

Browse files
authored
Add pylint check (#40)
Update code to be compatible with newer pylint checks
1 parent 1fe4cbe commit a6fe043

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ persistent=yes
1616

1717
# List of plugins (as comma separated values of python modules names) to load,
1818
# usually to register additional checkers.
19-
load-plugins=pylint.extensions.check_docs
19+
# load-plugins=
2020

2121

2222
[MESSAGES CONTROL]

src/sphinx_c_autodoc/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def parse_name(self) -> bool:
138138
fullname, _, path, base = match.groups() # type: ignore
139139
except AttributeError:
140140
logger.warning(
141-
"invalid signature for auto%s (%r)" % (self.objtype, self.name),
141+
"invalid signature for auto%s (%r)",
142+
self.objtype,
143+
self.name,
142144
type="c_autodoc",
143145
)
144146
return False
@@ -213,8 +215,10 @@ def import_object(self, raiseerror: bool = False) -> bool:
213215
else:
214216
logger.warning(
215217
"Unable to find file, %s, in any of the directories %s "
216-
"all directories are relative to the top documentation source directory"
217-
% (self.get_real_modname(), self.env.config.c_autodoc_roots),
218+
"all directories are relative to the top documentation source "
219+
"directory",
220+
self.get_real_modname(),
221+
self.env.config.c_autodoc_roots,
218222
location=(self.env.docname, self.directive.lineno),
219223
)
220224
return False
@@ -230,7 +234,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
230234
modules_dict = self.env.temp_data.setdefault("c:loaded_modules", {})
231235

232236
if filename not in modules_dict:
233-
with open(filename) as f:
237+
with open(filename, encoding="utf-8") as f:
234238
contents = [f.read()]
235239

236240
# let extensions preprocess files
@@ -280,7 +284,8 @@ def get_compilation_database(self) -> Optional[str]:
280284
return filename
281285

282286
logger.warning(
283-
'Compilation database "%s" not found.' % (filename,),
287+
'Compilation database "%s" not found.',
288+
filename,
284289
location=(self.env.docname, self.directive.lineno),
285290
)
286291

@@ -312,7 +317,9 @@ def get_object_members(self, want_all: bool) -> Tuple[bool, List[Tuple[str, Any]
312317
object_members.append((member, self.object.children[member]))
313318
else:
314319
logger.warning(
315-
'Missing member "%s" in object "%s"' % (member, self.fullname),
320+
'Missing member "%s" in object "%s"',
321+
member,
322+
self.fullname,
316323
type="c_autodoc",
317324
)
318325

@@ -422,7 +429,8 @@ def __init__(
422429
"""
423430
super().__init__(directive, name, indent)
424431

425-
# Sphinx 3.1 compatibility. 4.0 deprecated the "reporter" attribute. 5.0 removes it.
432+
# Sphinx 3.1 compatibility. 4.0 deprecated the "reporter" attribute. 5.0
433+
# removes it.
426434
reporter = getattr(self.directive, "reporter", None)
427435

428436
self._original_directive = self.directive

src/sphinx_c_autodoc/clang/patches.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def override_methods() -> None:
143143
pythonic and or more efficient.
144144
"""
145145
cindex.Cursor._raw_comment = None
146+
# Not sure why pylint chokes here
147+
# pylint: disable=assignment-from-no-return,too-many-function-args
146148
cindex.Cursor.raw_comment = property(Cursor_cached_raw_comment).setter(
147149
Cursor_set_raw_comment
148150
)
@@ -154,6 +156,8 @@ def add_new_methods() -> None:
154156
"""
155157
cindex.SourceLocation.isFromMainFile = SourceLocation_isFromMainFile
156158
cindex.Cursor._comment_extent = None
159+
# Not sure why pylint chokes here
160+
# pylint: disable=assignment-from-no-return,too-many-function-args
157161
cindex.Cursor.comment_extent = property(Cursor_comment_extent).setter(
158162
Cursor_set_comment_extent
159163
)

src/sphinx_c_autodoc/loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def get_parsed_declaration(self) -> str:
342342
i.spelling for i in ident_iter if i.kind == cindex.TokenKind.IDENTIFIER
343343
]
344344

345-
return "{}({})".format(self.name, ", ".join(tokens))
345+
return f"{self.name}({', '.join(tokens)})"
346346

347347

348348
class DocumentedEnumerator(DocumentedMacro):
@@ -521,7 +521,7 @@ def get_parsed_declaration(self) -> str:
521521
t.spelling for t in cindex.TokenGroup.get_tokens(tu, extent=extent)
522522
)
523523

524-
return "{} {}({})".format(return_type, func.spelling, args)
524+
return f"{return_type} {func.spelling}({args})"
525525

526526
def is_public(self) -> bool:
527527
"""

src/sphinx_c_autodoc/viewcode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def add_source_listings(app: Sphinx) -> Iterator[Tuple[str, Dict[str, Any], str]
155155
context = {
156156
"title": module,
157157
"body": (
158-
"<h1>Source code for %s</h1>" % module + "\n".join(highlighted_source)
158+
f"<h1>Source code for {module}</h1>" + "\n".join(highlighted_source)
159159
),
160160
}
161161
yield (_get_source_page_name(module), context, "page.html")

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ mintoxversion = 3.4
1212
# e.g.: tox -e py37-cov
1313
# Note: the sphinx versions are spelled out so tox doesn't try to resolve them
1414
# as python versions
15-
envlist = py{37, 38, 39, 310, 311}{,-cov}, check-{pycodestyle,black}, docs, sphinx-{three, four},
15+
envlist = py{37, 38, 39, 310, 311}{,-cov}, check-{pylint,pycodestyle,black}, docs, sphinx-{three, four},
1616

1717
[testenv]
18-
changedir = {toxinidir}/tests
1918
deps =
2019
poetry
2120
commands =

0 commit comments

Comments
 (0)