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

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

Open
laf0rge opened this issue Feb 11, 2022 · 1 comment
Labels
C: undefined-variable Issues related to 'undefined-variable' check False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@laf0rge
Copy link

laf0rge commented Feb 11, 2022

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

@laf0rge laf0rge added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 11, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title False positive E0602 when using class reference of sibling class False positive undefined-variable when using class reference of sibling class Feb 12, 2022
@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Feb 12, 2022

I confirmed the false positive with latest pylint using:

class MyClass:
    pass


class EF_DIR:
    class ApplicationLabel(MyClass, tag=0x50):
        pass

    class ApplicationTemplate(MyClass, nested=[ApplicationLabel]):
        pass

    def __init__(self):
        pass

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 12, 2022
@jacobtylerwalls jacobtylerwalls added the C: undefined-variable Issues related to 'undefined-variable' check label Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: undefined-variable Issues related to 'undefined-variable' check False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

No branches or pull requests

3 participants