Skip to content

SONARPY-4540 Handle built-in type assignments - #2297

Closed
erwan-leforestier-sonarsource wants to merge 2 commits into
masterfrom
fix/sonarpy-4540-handle-built-in-type-assignments
Closed

SONARPY-4540 Handle built-in type assignments#2297
erwan-leforestier-sonarsource wants to merge 2 commits into
masterfrom
fix/sonarpy-4540-handle-built-in-type-assignments

Conversation

@erwan-leforestier-sonarsource

Copy link
Copy Markdown

Summary

Prevents S117 from reporting PascalCase local variables directly assigned from the built-in type() function, including a conditional None fallback.

Changes

  • Detect assignments that directly call the resolved built-in type function.
  • Support type(...) if condition else None expressions without broadening the exemption to wrapped calls.
  • Cover direct, conditional, parenthesized, wrapped, and shadowed type assignments.

Functional Validation

Artifact: SONARPY-4540-fv.zip

Once the file is attached to the PR description, unzip and run:
./run.sh

Expected output:

******************* MASTER *******************
Analyzing "sample.py"...
Results:
    - Rule "python:S117" -> L.3
    - Rule "python:S117" -> L.4
****** Branch "fix/sonarpy-4540-handle-built-in-type-assignments" ******
Analyzing "sample.py"...
Results:
    - Rule "python:S117" -> L.4

⚠️⚠️ This is not ready for review ⚠️⚠️

@erwan-leforestier-sonarsource

Copy link
Copy Markdown
Author

Superseded by the corresponding sonar-python-enterprise PR.

@gitar-bot

gitar-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Updates rule S117 to prevent false positives on PascalCase local variables assigned from built-in type() calls, including conditional None fallbacks. No issues found.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant