Skip to content

Commit d65b249

Browse files
Merge remote-tracking branch 'origin/main' into fix-docs
2 parents c6c06c5 + 4471242 commit d65b249

21 files changed

+66
-17
lines changed

doc/whatsnew/fragments/9357.feature

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The verbose option now outputs the filenames of the files that have been checked.
2+
Previously, it only included the number of checked and skipped files.
3+
4+
Closes #9357
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
We now raise a ``logging-too-few-args`` for format string with no
2+
interpolation arguments at all (i.e. for something like ``logging.debug("Awaiting process %s")``
3+
or ``logging.debug("Awaiting process {pid}")``). Previously we did not raise for such case.
4+
5+
Closes #9999

pylint/checkers/logging.py

-5
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,6 @@ def _check_format_string(self, node: nodes.Call, format_arg: Literal[0, 1]) -> N
326326
format_arg: Index of the format string in the node arguments.
327327
"""
328328
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
329-
if not num_args:
330-
# If no args were supplied the string is not interpolated and can contain
331-
# formatting characters - it's used verbatim. Don't check any further.
332-
return
333-
334329
format_string = node.args[format_arg].value
335330
required_num_args = 0
336331
if isinstance(format_string, bytes):

pylint/lint/pylinter.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ def _lint_files(
764764
continue
765765
try:
766766
self._lint_file(fileitem, module, check_astroid_module)
767+
self.stats.modules_names.add(fileitem.filepath)
767768
except Exception as ex: # pylint: disable=broad-except
768769
template_path = prepare_crash_report(
769770
ex, fileitem.filepath, self.crash_file_path
@@ -1161,7 +1162,12 @@ def _report_evaluation(self, verbose: bool = False) -> int | None:
11611162

11621163
if verbose:
11631164
checked_files_count = self.stats.node_count["module"]
1164-
msg += f"\nChecked {checked_files_count} files, skipped {self.stats.skipped} files/modules"
1165+
unchecked_files_count = self.stats.undocumented["module"]
1166+
checked_files = ", ".join(self.stats.modules_names)
1167+
msg += (
1168+
f"\nChecked {checked_files_count} files/modules ({checked_files}),"
1169+
f" skipped {unchecked_files_count} files/modules"
1170+
)
11651171

11661172
if self.config.score:
11671173
sect = report_nodes.EvaluationSection(msg)

pylint/utils/linterstats.py

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(
109109
self.code_type_count = code_type_count or CodeTypeCount(
110110
code=0, comment=0, docstring=0, empty=0, total=0
111111
)
112+
self.modules_names: set[str] = set()
112113

113114
self.dependencies: dict[str, set[str]] = dependencies or {}
114115
self.duplicated_lines = duplicated_lines or DuplicatedLines(

tests/config/data/logging_format_interpolation_style.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66

77
logging.error("constant string")
8-
logging.error("{}")
98
logging.error("{}", 1)
109
logging.error("{0}", 1)
1110
logging.error("{named}", {"named": 1})

tests/functional/l/logging/logging_format_interpolation_style.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44

55
logging.error("constant string")
6-
logging.error("{}")
76
logging.error("{}", 1)
87
logging.error("{0}", 1)
98
logging.error("{named}", {"named": 1})

tests/functional/l/logging/logging_too_few_args.txt

-6
This file was deleted.

tests/functional/l/logging/logging_too_few_args.py renamed to tests/functional/l/logging/logging_too_few_args_new_style.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
"""Tests for logging-too-few-args"""
1+
"""Tests for logging-too-few-args new style"""
22

33
import logging
44

55
logging.error("{}, {}", 1) # [logging-too-few-args]
66
logging.error("{0}, {1}", 1) # [logging-too-few-args]
7+
logging.error("{}") # [logging-too-few-args]
8+
logging.error("{0}") # [logging-too-few-args]
9+
logging.error("{named}") # [logging-too-few-args]
710
logging.error("{named1}, {named2}", {"named1": 1}) # [logging-too-few-args]
811
logging.error("{0}, {named}", 1) # [logging-too-few-args]
912
logging.error("{}, {named}", {"named": 1}) # [logging-too-few-args]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
logging-too-few-args:5:0:5:26::Not enough arguments for logging format string:UNDEFINED
2+
logging-too-few-args:6:0:6:28::Not enough arguments for logging format string:UNDEFINED
3+
logging-too-few-args:7:0:7:19::Not enough arguments for logging format string:UNDEFINED
4+
logging-too-few-args:8:0:8:20::Not enough arguments for logging format string:UNDEFINED
5+
logging-too-few-args:9:0:9:24::Not enough arguments for logging format string:UNDEFINED
6+
logging-too-few-args:10:0:10:50::Not enough arguments for logging format string:UNDEFINED
7+
logging-too-few-args:11:0:11:32::Not enough arguments for logging format string:UNDEFINED
8+
logging-too-few-args:12:0:12:42::Not enough arguments for logging format string:UNDEFINED
9+
logging-too-few-args:13:0:13:43::Not enough arguments for logging format string:UNDEFINED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Tests for logging-too-few-args old style"""
2+
3+
import logging
4+
5+
logging.error("%s, %s", 1) # [logging-too-few-args]
6+
logging.debug("Sisyphus table %s: sleep") # [logging-too-few-args]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[LOGGING]
2+
logging-format-style=old
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
logging-too-few-args:5:0:5:26::Not enough arguments for logging format string:UNDEFINED
2+
logging-too-few-args:6:0:6:41::Not enough arguments for logging format string:UNDEFINED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# pylint: disable=missing-docstring,too-few-public-methods
2+
3+
class DynamicGetitem:
4+
def __getitem__(self, key):
5+
if key == 'attributes':
6+
return []
7+
return {'world': 123}
8+
9+
10+
ex = DynamicGetitem()
11+
a = ex['hello']['world'] # [invalid-sequence-index] known false-positive
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid-sequence-index:11:4:11:24::Sequence index is not an int, slice, or instance with __index__:UNDEFINED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# pylint: disable=missing-docstring
2+
3+
data = {
4+
'abc': None,
5+
}
6+
data['abc'] = lambda: print("Callback called")
7+
data['abc']() # [not-callable] known false-positive
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
not-callable:7:0:7:13::data['abc'] is not callable:UNDEFINED

tests/functional/s/string/string_log_formatting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def pprint():
2222
logging.info(1)
2323
logging.info(True)
2424
logging.info('')
25-
logging.info('%s%')
25+
logging.info('%s%') # [logging-format-truncated]
2626
logging.info('%s', '')
2727
logging.info('%s%%', '')
2828
logging.info('%s%s', '', '')

tests/functional/s/string/string_log_formatting.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ logging-format-truncated:16:4:16:27:pprint:Logging format string ends in middle
44
logging-too-few-args:17:4:17:28:pprint:Not enough arguments for logging format string:UNDEFINED
55
logging-unsupported-format:18:4:18:32:pprint:Unsupported logging format character 'y' (0x79) at index 3:UNDEFINED
66
logging-too-many-args:19:4:19:36:pprint:Too many arguments for logging format string:HIGH
7+
logging-format-truncated:25:4:25:23:pprint:Logging format string ends in middle of conversion specifier:UNDEFINED

tests/test_self.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ def test_output_with_verbose(self) -> None:
257257
out=out,
258258
code=4,
259259
)
260-
assert "Checked 1 files, skipped 1 files/modules" in out.getvalue().strip()
260+
stripped = out.getvalue().strip()
261+
assert "Checked 1 files/modules" in stripped
262+
assert "unnecessary_lambda.py" in stripped
263+
assert "skipped 0 files/modules" in stripped
261264

262265
def test_no_out_encoding(self) -> None:
263266
"""Test redirection of stdout with non ascii characters."""

0 commit comments

Comments
 (0)