Skip to content

Fix possibly-used-before-assignment false negative for type-annotated assignment #10437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2025

Conversation

zenlyj
Copy link
Contributor

@zenlyj zenlyj commented Jun 22, 2025

Type of Changes

Type
βœ“ πŸ› Bug fix
✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Description

The issue lies in the predicate for variable annotations. It currently checks whether a Name node is a child of an AnnAssign node, but it should also check whether the Name node is used as type annotation.

Closes #10421

@zenlyj zenlyj added the False Negative πŸ¦‹ No message is emitted but something is wrong with the code label Jun 22, 2025
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.0.0 milestone Jun 22, 2025
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.

LGTM

Copy link

codecov bot commented Jun 22, 2025 β€’

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.88%. Comparing base (f5aa766) to head (646b503).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #10437   +/-   ##
=======================================
  Coverage   95.88%   95.88%           
=======================================
  Files         176      176           
  Lines       19140    19140           
=======================================
  Hits        18352    18352           
  Misses        788      788           
Files with missing lines Coverage Ξ”
pylint/checkers/variables.py 97.29% <100.00%> (ΓΈ)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This comment has been minimized.

@zenlyj
Copy link
Contributor Author

zenlyj commented Jun 22, 2025

Went through primer results, this probably needs to be refined. will make an update soon

@zenlyj zenlyj changed the title Fix possibly-used-before-assignment false negative for type-annotated assignation Fix possibly-used-before-assignment false negative for type-annotated assignment Jun 23, 2025
Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit 646b503

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.

In 4.0.0 it goes !

@Pierre-Sassoulas Pierre-Sassoulas merged commit d9927e4 into pylint-dev:main Jun 24, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative πŸ¦‹ No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negative: possibly-used-before-assignment with type annotation after assignment in conditional/loop
3 participants