Skip to content

Conversation

@jacobtylerwalls
Copy link
Member

Type of Changes

Type
✨ New feature

Description

I have an idea for a performance enhancement in pylint that will require having this information set correctly on Arguments nodes.

Essentially, when pylint walks the AST to parse disable comments, we can avoid deeply recursing into child nodes that exist on the same line, since there is no point

diff --git a/pylint/utils/file_state.py b/pylint/utils/file_state.py
index 45217bb7e..0293ea6a4 100644
--- a/pylint/utils/file_state.py
+++ b/pylint/utils/file_state.py
@@ -63,8 +63,9 @@ class FileState:
         """Recursively walk (depth first) AST to collect block level options
         line numbers and set the state correctly.
         """
-        for child in node.get_children():
-            self._set_state_on_block_lines(msgs_store, child, msg, msg_state)
+        if node.lineno != node.end_lineno:
+            for child in node.get_children():
+                self._set_state_on_block_lines(msgs_store, child, msg, msg_state)
         # first child line number used to distinguish between disable
         # which are the first child of scoped node with those defined later.
         # For instance in the code below:
diff --git a/tests/functional/u/unsupported/unsupported_version_for_posonly_args.txt b/tests/functional/u/unsupported/unsupported_version_for_posonly_args.txt
index 4ae1b2756..fa7661536 100644
--- a/tests/functional/u/unsupported/unsupported_version_for_posonly_args.txt
+++ b/tests/functional/u/unsupported/unsupported_version_for_posonly_args.txt
@@ -1 +1 @@
-using-positional-only-args-in-unsupported-version:2:0:None:None:add:Positional-only arguments are not supported by all versions included in the py-version setting:HIGH
+using-positional-only-args-in-unsupported-version:2:0:2:None:add:Positional-only arguments are not supported by all versions included in the py-version setting:HIGH
diff --git a/tests/functional/u/unused/unused_argument.txt b/tests/functional/u/unused/unused_argument.txt
index bca2700ac..50f6c6694 100644
--- a/tests/functional/u/unused/unused_argument.txt
+++ b/tests/functional/u/unused/unused_argument.txt
@@ -3,8 +3,8 @@ unused-argument:3:23:3:29:test_unused:Unused argument 'second':HIGH
 unused-argument:32:29:32:32:Sub.newmethod:Unused argument 'aay':INFERENCE
 unused-argument:59:13:59:16:function:Unused argument 'arg':HIGH
 unused-argument:66:21:66:24:AAAA.method:Unused argument 'arg':INFERENCE
-unused-argument:73:0:None:None:AAAA.selected:Unused argument 'args':INFERENCE
-unused-argument:73:0:None:None:AAAA.selected:Unused argument 'kwargs':INFERENCE
+unused-argument:73:0:73:None:AAAA.selected:Unused argument 'args':INFERENCE
+unused-argument:73:0:73:None:AAAA.selected:Unused argument 'kwargs':INFERENCE
 unused-argument:92:23:92:26:BBBB.__init__:Unused argument 'arg':INFERENCE
 unused-argument:103:34:103:39:Ancestor.set_thing:Unused argument 'other':INFERENCE
 unused-argument:129:21:129:25:TestClassWithOnlyNew.__new__:Unused argument 'argA':INFERENCE

@jacobtylerwalls jacobtylerwalls added this to the 4.1.0 milestone Oct 20, 2025
@jacobtylerwalls jacobtylerwalls added the pylint-tested PRs that don't cause major regressions with pylint label Oct 20, 2025
@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.34%. Comparing base (4a7e23f) to head (62fcc62).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2865      +/-   ##
==========================================
- Coverage   93.35%   93.34%   -0.01%     
==========================================
  Files          92       92              
  Lines       11190    11194       +4     
==========================================
+ Hits        10446    10449       +3     
- Misses        744      745       +1     
Flag Coverage Δ
linux 93.21% <100.00%> (-0.01%) ⬇️
pypy 93.34% <100.00%> (-0.01%) ⬇️
windows 93.32% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/rebuilder.py 98.23% <100.00%> (+0.01%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's clever !

@jacobtylerwalls jacobtylerwalls added the Enhancement ✨ Improvement to a component label Oct 20, 2025
@jacobtylerwalls jacobtylerwalls merged commit 8869509 into pylint-dev:main Oct 20, 2025
20 of 21 checks passed
@jacobtylerwalls jacobtylerwalls deleted the jtw/arguments-lineno branch October 20, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement ✨ Improvement to a component pylint-tested PRs that don't cause major regressions with pylint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants