Skip to content

Conversation

@Jkhall81
Copy link

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #10766

Lowercase variables are now allowed inside main blocks.

@Jkhall81 Jkhall81 changed the title Fix C0103 constant name in __main__ block (10766) Fix C0103 constant name error for lower case variables in __main__ block (10766) Jan 24, 2026
@Jkhall81 Jkhall81 changed the title Fix C0103 constant name error for lower case variables in __main__ block (10766) Fix C0103 name error in main block (10766) Jan 24, 2026
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Could you add a changelog entry? Other than that this LGTM

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code backport maintenance/4.0.x labels Jan 26, 2026
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.0.5 milestone Jan 26, 2026
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
βœ… Project coverage is 95.97%. Comparing base (3e374c6) to head (eccd00c).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pylint/checkers/base/name_checker/checker.py 40.00% 3 Missing ⚠️
pylint/checkers/utils.py 88.88% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10824      +/-   ##
==========================================
- Coverage   95.98%   95.97%   -0.02%     
==========================================
  Files         176      176              
  Lines       19594    19608      +14     
==========================================
+ Hits        18808    18818      +10     
- Misses        786      790       +4     
Files with missing lines Coverage Ξ”
pylint/checkers/utils.py 95.94% <88.88%> (-0.06%) ⬇️
pylint/checkers/base/name_checker/checker.py 97.92% <40.00%> (-0.88%) ⬇️
πŸš€ 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.

Thank you for opening a merge request.

Performance wise it probably make more sense to check for main block only if we're going to raise an "invalid-name", checking the ancestors of all the nodes before checking the name is going to cost a lot. What alternative did you consider ?

@github-actions

This comment has been minimized.

@Jkhall81
Copy link
Author

@DanielNoord Sure thing, I'll add that changelog.

@Pierre-Sassoulas I didn't really consider performance at all. But we could do an 'All Caps' regex check, and then only run the new function if that doesn't match? Right now it would be looking at all variables outside a function, after this proposed change it would be looking at all lowercase variables outside of a function. It would be a small difference, but still less ancestor iterations than before.

The only thing I can think of to check is if the variable is all caps. Did you have anything else in mind?

@Pierre-Sassoulas
Copy link
Member

Did you have anything else in mind?

I was thinking of moving the filtering later on in _check_name, most name we check are not inside a __main__ so it makes sense to filter for this after we filtered for possible violations.

@Jkhall81
Copy link
Author

@Pierre-Sassoulas Moved the check into _check_name.
@DanielNoord Added a changelog fragment.

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

I'll let @Pierre-Sassoulas finish the review here :)

@github-actions
Copy link
Contributor

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on music21:
The following messages are now emitted:

Details
  1. invalid-name:
    Variable name "te" doesn't conform to '[a-z_][A-Za-z0-9_]{2,30}$' pattern
    https://github.com/cuthbertLab/music21/blob/b8306fcf4dc11c88a114a2ed175caa5ff80a826b/music21/configure.py#L1628

The following messages are no longer emitted:

Details
  1. invalid-name:
    Constant name "te" doesn't conform to '(([A-Z_][A-Z0-9_])|(.*))$' pattern*
    https://github.com/cuthbertLab/music21/blob/b8306fcf4dc11c88a114a2ed175caa5ff80a826b/music21/configure.py#L1628
  2. invalid-name:
    Constant name "unused_returnCode" doesn't conform to '(([A-Z_][A-Z0-9_])|(.*))$' pattern*
    https://github.com/cuthbertLab/music21/blob/b8306fcf4dc11c88a114a2ed175caa5ff80a826b/music21/test/testSingleCoreAll.py#L150
  3. invalid-name:
    Constant name "unused_returnCode" doesn't conform to '(([A-Z_][A-Z0-9_])|(.*))$' pattern*
    https://github.com/cuthbertLab/music21/blob/b8306fcf4dc11c88a114a2ed175caa5ff80a826b/music21/test/testSingleCoreAll.py#L152

This comment was generated for commit eccd00c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport maintenance/4.0.x False Positive 🦟 A message is emitted but nothing is wrong with the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive for constant naming style inside __main__ block

3 participants