Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53d4541

Browse files
Fixundefined-variable etc for Python 3.12 generic type syntax (#9195) (#9199)
(cherry picked from commitc648f16)Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
1 parentefee961 commit53d4541

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix false positives for ``undefined-variable`` and ``unused-argument`` for
2+
classes and functions using Python 3.12 generic type syntax.
3+
4+
Closes #9193

‎pylint/checkers/variables.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,9 @@ def _should_node_be_skipped(
17381738
elifconsumer.scope_type=="function"andself._defined_in_function_definition(
17391739
node,consumer.node
17401740
):
1741+
ifany(node.name==param.name.nameforparaminconsumer.node.type_params):
1742+
returnFalse
1743+
17411744
# If the name node is used as a function default argument's value or as
17421745
# a decorator, then start from the parent frame of the function instead
17431746
# of the function frame - and thus open an inner class scope
@@ -2262,10 +2265,13 @@ def _is_variable_violation(
22622265
isinstance(defframe,nodes.FunctionDef)
22632266
andframeisdefframe
22642267
anddefframe.parent_of(node)
2265-
andstmtisnotdefstmt
2268+
and (
2269+
defnodeindefframe.type_params
2270+
# Single statement function, with the statement on the
2271+
# same line as the function definition
2272+
orstmtisnotdefstmt
2273+
)
22662274
):
2267-
# Single statement function, with the statement on the
2268-
# same line as the function definition
22692275
maybe_before_assign=False
22702276
elif (
22712277
isinstance(defstmt,NODES_WITH_VALUE_ATTR)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# pylint: disable=missing-function-docstring,missing-module-docstring,missing-class-docstring,too-few-public-methods
2+
3+
deff[T](a:T)->T:
4+
print(a)
5+
6+
classChildClass[T,*Ts,**P]:
7+
...
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.12

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp