Skip to content

Commit 57d959a

Browse files
authored
Cover more lines (#7996)
1 parent 8912838 commit 57d959a

File tree

9 files changed

+39
-19
lines changed

9 files changed

+39
-19
lines changed

pylint/extensions/docparams.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,7 @@ def visit_return(self, node: nodes.Return) -> None:
332332
if self.linter.config.accept_no_return_doc:
333333
return
334334

335-
func_node = node.frame(future=True)
336-
if not isinstance(func_node, astroid.FunctionDef):
337-
return
335+
func_node: astroid.FunctionDef = node.frame(future=True)
338336

339337
# skip functions that match the 'no-docstring-rgx' config option
340338
no_docstring_rgx = self.linter.config.no_docstring_rgx
@@ -360,9 +358,7 @@ def visit_yield(self, node: nodes.Yield | nodes.YieldFrom) -> None:
360358
if self.linter.config.accept_no_yields_doc:
361359
return
362360

363-
func_node = node.frame(future=True)
364-
if not isinstance(func_node, astroid.FunctionDef):
365-
return
361+
func_node: astroid.FunctionDef = node.frame(future=True)
366362

367363
# skip functions that match the 'no-docstring-rgx' config option
368364
no_docstring_rgx = self.linter.config.no_docstring_rgx

tests/functional/ext/code_style/cs_consider_using_namedtuple_or_dataclass.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class Foo:
2323
"entry_2": {0: None, 1: None},
2424
}
2525

26+
# Subdicts have no common keys
27+
MAPPING_4 = {
28+
"entry_1": {"key_3": 0, "key_4": 1, "key_diff_1": 2},
29+
"entry_2": {"key_1": 0, "key_2": 1, "key_diff_2": 3},
30+
}
2631

2732
def func():
2833
# Not in module scope
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
consider-using-namedtuple-or-dataclass:11:12:14:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
22
consider-using-namedtuple-or-dataclass:15:12:18:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
3-
consider-using-namedtuple-or-dataclass:34:23:37:5:func:Consider using namedtuple or dataclass for dictionary values:UNDEFINED
4-
consider-using-namedtuple-or-dataclass:41:12:44:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
5-
consider-using-namedtuple-or-dataclass:53:12:56:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
3+
consider-using-namedtuple-or-dataclass:39:23:42:5:func:Consider using namedtuple or dataclass for dictionary values:UNDEFINED
4+
consider-using-namedtuple-or-dataclass:46:12:49:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED
5+
consider-using-namedtuple-or-dataclass:58:12:61:1::Consider using namedtuple or dataclass for dictionary values:UNDEFINED

tests/functional/ext/consider_ternary_expression/consider_ternary_expression.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# pylint: disable=invalid-name, undefined-variable, unused-variable, missing-function-docstring, missing-module-docstring
2+
# pylint: disable=unsupported-assignment-operation, line-too-long
3+
14
if f(): # [consider-ternary-expression]
25
x = 4
36
else:
@@ -15,3 +18,19 @@ def a():
1518
z = 4
1619
else:
1720
z = 5
21+
22+
if f():
23+
x = 4
24+
print(x)
25+
else:
26+
x = 5
27+
28+
if f():
29+
x[0] = 4
30+
else:
31+
x = 5
32+
33+
if f():
34+
x = 4
35+
else:
36+
y = 5
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
[MAIN]
22
load-plugins=pylint.extensions.consider_ternary_expression,
3-
4-
[MESSAGES CONTROL]
5-
disable=
6-
invalid-name,
7-
undefined-variable,
8-
unused-variable,
9-
missing-function-docstring,
10-
missing-module-docstring,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
consider-ternary-expression:1:0:4:9::Consider rewriting as a ternary expression:UNDEFINED
2-
consider-ternary-expression:14:4:17:13:a:Consider rewriting as a ternary expression:UNDEFINED
1+
consider-ternary-expression:4:0:7:9::Consider rewriting as a ternary expression:UNDEFINED
2+
consider-ternary-expression:17:4:20:13:a:Consider rewriting as a ternary expression:UNDEFINED

tests/functional/ext/docparams/docparams.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ def params_are_documented(par1: int, *, par2: int) -> int:
102102
"""
103103

104104
return par1 + par2
105+
106+
107+
# Only check raise nodes within FunctionDefs
108+
raise Exception()

tests/functional/ext/private_import/private_import.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,6 @@ def save(self):
137137
# Treat relative imports as internal
138138
from .other_file import _private
139139
from ..parent import _private
140+
141+
from _private_module_x import some_name # [import-private-name]
142+
var = some_name

tests/functional/ext/private_import/private_import.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ import-private-name:107:0:107:41::Imported private module (_private_module5):HIG
1818
import-private-name:111:0:111:42::Imported private module (_private_module6):HIGH
1919
import-private-name:114:0:114:40::Imported private object (_PrivateClass3):HIGH
2020
import-private-name:119:0:119:34::Imported private module (_private_module_unreachable):HIGH
21+
import-private-name:141:0:141:39::Imported private module (_private_module_x):HIGH

0 commit comments

Comments
 (0)