Skip to content

False positive undefined-variable when using class reference of sibling class #5794

Open
@laf0rge

Description

@laf0rge

Bug description

I'm getting false positives when using the following construct, where the name of a sibling class is used in the argument list of defining another sibling class.

The code works perfectly fine, cpython executes it and the result is the expected result. It is just pylint-2.12.2 which is complaining about this:

class EF_DIR(LinFixedEF):
    class ApplicationLabel(BER_TLV_IE, tag=0x50):
        _construct = GreedyString('ascii')

    class ApplicationTemplate(BER_TLV_IE, tag=0x61,
                              nested=[iso7816_4.ApplicationId, ApplicationLabel, iso7816_4.FileReference,
                                      iso7816_4.CommandApdu, iso7816_4.DiscretionaryData,
                                      iso7816_4.DiscretionaryTemplate, iso7816_4.URL,
                                      iso7816_4.ApplicationRelatedDOSet]):
        pass

    def __init__(self, fid='2f00', sfid=0x1e, name='EF.DIR', desc='Application Directory'):
        super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={5, 54})
        self._tlv = EF_DIR.ApplicationTemplate

The full code example can be fond at https://gerrit.osmocom.org/c/pysim/+/27130/6 and can be cloned via

git clone https://gerrit.osmocom.org/pysim
cd pysim
git fetch https://gerrit.osmocom.org/pysim refs/changes/30/27130/6
git checkout FETCH_HEAD

Command used

python3 -m pylint --errors-only \                                                                                              
        --disable E1102 \
        --disable E0401 \
        --enable W0301 \
        pySim *.py

Pylint output

************* Module pySim.ts_102_221
pySim/ts_102_221.py:599:63: E0602: Undefined variable 'ApplicationLabel' (undefined-variable)

Expected behavior

pylint should not throw an error for something that parses and executes fine in cpthon.

Pylint version

2.12.2

OS / Environment

Debian GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: undefined-variableIssues related to 'undefined-variable' checkFalse Positive 🦟A message is emitted but nothing is wrong with the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions