Skip to content
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

Make undefined-variable flag type annotation without value assignment #5158

Merged
merged 3 commits into from Oct 15, 2021

Conversation

DanielNoord
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature, or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Type of Changes

Type
🐛 Bug fix

Description

Closes #5140

@DanielNoord DanielNoord added the False Negative 🦋 No message is emitted but something is wrong with the code label Oct 15, 2021
@DanielNoord DanielNoord added this to the 2.12.0 milestone Oct 15, 2021
@coveralls
Copy link

coveralls commented Oct 15, 2021

Pull Request Test Coverage Report for Build 1345355352

  • 11 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 93.217%

Totals Coverage Status
Change from base Build 1341360957: 0.005%
Covered Lines: 13592
Relevant Lines: 14581

💛 - Coveralls

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.

Looks good ! I have a nitpick :)

pylint/checkers/variables.py Outdated Show resolved Hide resolved
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
@DanielNoord DanielNoord merged commit b1c4735 into pylint-dev:main Oct 15, 2021
@DanielNoord DanielNoord deleted the undefined-variable-type branch October 15, 2021 11:50
@cdce8p
Copy link
Member

cdce8p commented Oct 15, 2021

This change causes a crash when testing Home Assistant.

Exception on node <Name.event_ids l.16 at 0x1052e2230> in file '/Users/marc/Develop/pylint/test5.py'
Traceback (most recent call last):
  File "/Users/marc/Develop/pylint/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/Users/marc/Develop/pylint/pylint/checkers/variables.py", line 1189, in visit_name
    elif self._is_only_type_assignment(node, name, defstmt):
  File "/Users/marc/Develop/pylint/pylint/checkers/variables.py", line 1560, in _is_only_type_assignment
    for ref_node in node.scope().locals[name][1:]:
KeyError: 'event_ids'

To reproduce

# pylint: disable=undefined-variable

def _purge_filtered_states(session) -> None:
    """Remove filtered states and linked events."""
    state_ids: list[int]
    event_ids: list[int | None]
    state_ids, event_ids = zip(
        *(
            session.query(States.state_id, States.event_id)
            .filter(States.entity_id.in_(excluded_entity_ids))
            .limit(MAX_ROWS_TO_PURGE)
            .all()
        )
    )
    event_ids = [id_ for id_ in event_ids if id_ is not None]

--
Taken from here: homeassistant/components/recorder/purge.py -> _purge_filtered_states

@cdce8p
Copy link
Member

cdce8p commented Oct 15, 2021

Tracking the issue in #5162

cdce8p added a commit to cdce8p/pylint that referenced this pull request Oct 16, 2021
cdce8p added a commit to cdce8p/pylint that referenced this pull request Oct 17, 2021
cdce8p added a commit to cdce8p/pylint that referenced this pull request Oct 17, 2021
cdce8p added a commit to cdce8p/pylint that referenced this pull request Oct 21, 2021
cdce8p added a commit to cdce8p/pylint that referenced this pull request Oct 21, 2021
cdce8p added a commit to cdce8p/pylint that referenced this pull request Oct 23, 2021
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
4 participants