From 40fcb10a9d49dc60ef98d9e8771fdb24fc44ab66 Mon Sep 17 00:00:00 2001 From: ikraduya Date: Tue, 23 Feb 2021 12:57:53 +0700 Subject: [PATCH 01/10] Fix False positive on Enum.__members__.items() --- pylint/checkers/typecheck.py | 11 +++++++++++ tests/functional/m/member_checks.py | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index ad4ca70472..332b4ea860 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -505,6 +505,17 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins=True, ignored_none=T return False except astroid.NotFoundError: return True + if ( + owner.parent + and isinstance(owner.parent, astroid.ClassDef) + and owner.parent.name == "EnumMeta" + and owner_name == "__members__" + and node.attrname == "items" + ): + # Avoid false positive on Enum.__members__.items() + # See https://github.com/PyCQA/pylint/issues/4123 + return False + return True diff --git a/tests/functional/m/member_checks.py b/tests/functional/m/member_checks.py index 30f16c58c6..dc9bd38cea 100644 --- a/tests/functional/m/member_checks.py +++ b/tests/functional/m/member_checks.py @@ -217,3 +217,13 @@ def __init__(self, flag): else: self.attribute = [] self.attribute.append(1) + +from enum import Enum +class Animal(Enum): + ANT = 1 + BEE = 2 + CAT = 3 + DOG = 4 +# To test false positive no-member on Enum.__members__.items() +for itm in Animal.__members__.items(): + print(itm) From 646be6db86f74b73acd3ccfc1c373efdda438346 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 23 Feb 2021 19:09:24 +0100 Subject: [PATCH 02/10] Fix benchmark test (#4138) * Don't check directories starting with '.' when using register_plugins * CI - Add benchmark job --- .github/workflows/ci.yaml | 49 +++++++++++++++++++++++++++++++++++++++ ChangeLog | 4 ++++ pylint/utils/utils.py | 6 ++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4929ce4675..d0b13c2594 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -319,6 +319,55 @@ jobs: . venv/bin/activate coveralls --rcfile=${{ env.COVERAGERC_FILE }} --service=github + benchmark-linux: + name: Run benchmark tests Python ${{ matrix.python-version }} (Linux) + runs-on: ubuntu-latest + needs: prepare-tests-linux + strategy: + fail-fast: false + matrix: + python-version: [3.8, 3.9] + steps: + - name: Check out code from GitHub + uses: actions/checkout@v2.3.4 + - name: Set up Python ${{ matrix.python-version }} + id: python + uses: actions/setup-python@v2.2.1 + with: + python-version: ${{ matrix.python-version }} + - name: Restore Python virtual environment + id: cache-venv + uses: actions/cache@v2.1.4 + with: + path: venv + key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ + needs.prepare-tests-linux.outputs.python-key }} + - name: Fail job if Python cache restore failed + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + echo "Failed to restore Python venv from cache" + exit 1 + - name: Run pytest + run: | + . venv/bin/activate + pip install pygal + pip install -e . + pytest --exitfirst \ + --benchmark-only \ + --benchmark-autosave \ + --benchmark-save-data \ + --benchmark-group-by="group" + - name: Create partial artifact name suffix + id: artifact-name-suffix + run: >- + echo "::set-output name=datetime::"$(date "+%Y%m%d_%H%M") + - name: Upload benchmark artifact + uses: actions/upload-artifact@v2.2.2 + with: + name: benchmark-${{ runner.os }}-${{ matrix.python-version }}_${{ + steps.artifact-name-suffix.outputs.datetime }} + path: .benchmarks/ + pytest-windows: name: Run tests Python ${{ matrix.python-version }} (Windows) diff --git a/ChangeLog b/ChangeLog index 7fdc1c2996..eae4b67b97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ What's New in Pylint 2.8.0? =========================== +* Don't check directories starting with '.' when using register_plugins + + Closes #4119 + What's New in Pylint 2.7.0? =========================== diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index 981bfb91b4..35a74bfcd7 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -248,7 +248,11 @@ def register_plugins(linter, directory): if ( extension in PY_EXTS and base != "__init__" - or (not extension and os.path.isdir(os.path.join(directory, base))) + or ( + not extension + and os.path.isdir(os.path.join(directory, base)) + and not filename.startswith(".") + ) ): try: module = modutils.load_module_from_file( From 581ad1b45f53b0a15c26c3cb3c000fca5a2ec47e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 23 Feb 2021 19:50:42 +0100 Subject: [PATCH 03/10] Run ci checks on every release branch --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d0b13c2594..fa9cbeb8d6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,6 +4,7 @@ on: push: branches: - master + - 2.* pull_request: ~ env: From 8f39e8fb07baf4df1d3638dae6419aee21594631 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 23 Feb 2021 19:42:45 +0100 Subject: [PATCH 04/10] Retcon the changelog after 2.7.1 release --- ChangeLog | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index eae4b67b97..df57bcf571 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,19 @@ Pylint's ChangeLog What's New in Pylint 2.8.0? =========================== +.. + Put new features here +What's New in Pylint 2.7.2? +=========================== +.. + Put bug fixes that will be cherry-picked to latest major version here + + +What's New in Pylint 2.7.1? +=========================== + +* Expose `UnittestLinter` in pylint.testutils * Don't check directories starting with '.' when using register_plugins From 8cbcf87e80cf7886a05c760a92e11ee27e913d75 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 22 Feb 2021 19:37:13 +0100 Subject: [PATCH 05/10] Guide the user more in the bug report Would probably permit to have the version more often and to have something to do a functional test with more often too. --- .github/ISSUE_TEMPLATE/1_Bug_report.md | 45 ++++++++++++++++++--- .github/ISSUE_TEMPLATE/2_Feature_request.md | 1 - 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/1_Bug_report.md b/.github/ISSUE_TEMPLATE/1_Bug_report.md index feaaeeb9ad..b4c2e1ddc7 100644 --- a/.github/ISSUE_TEMPLATE/1_Bug_report.md +++ b/.github/ISSUE_TEMPLATE/1_Bug_report.md @@ -10,19 +10,54 @@ about: Report a bug in pylint Before you submit this, make sure that the issue doesn't already exist or if it is not closed. - Is your issue fixed on the preview release?: pip install pylint astroid --pre -U - + Is your issue fixed on the preview release?: + pip install pylint astroid --pre -U --> ### Steps to reproduce -1. -2. -3. + + ### Current behavior + ### Expected behavior ### pylint --version output + +Result of `pylint --version` output: +``` + +``` + + diff --git a/.github/ISSUE_TEMPLATE/2_Feature_request.md b/.github/ISSUE_TEMPLATE/2_Feature_request.md index 6851434157..b9dca130d4 100644 --- a/.github/ISSUE_TEMPLATE/2_Feature_request.md +++ b/.github/ISSUE_TEMPLATE/2_Feature_request.md @@ -17,6 +17,5 @@ A clear and concise description of what the problem is. ### Describe the solution you'd like A clear and concise description of what you want to happen. - ### Additional context Add any other context about the feature request here. From fe609b1d104af4f8b0f0454e71c20e669c3af1aa Mon Sep 17 00:00:00 2001 From: ikraduya Date: Thu, 25 Feb 2021 01:10:53 +0700 Subject: [PATCH 06/10] Fix false positive on Enum.__members__.{values, keys} --- pylint/checkers/typecheck.py | 5 +++-- tests/functional/m/member_checks.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 332b4ea860..65f79c18bb 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -510,9 +510,10 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins=True, ignored_none=T and isinstance(owner.parent, astroid.ClassDef) and owner.parent.name == "EnumMeta" and owner_name == "__members__" - and node.attrname == "items" + and node.attrname in ["items", "values", "keys"] ): - # Avoid false positive on Enum.__members__.items() + print(node.attrname) + # Avoid false positive on Enum.__members__.{items(), values, keys} # See https://github.com/PyCQA/pylint/issues/4123 return False diff --git a/tests/functional/m/member_checks.py b/tests/functional/m/member_checks.py index dc9bd38cea..291daee125 100644 --- a/tests/functional/m/member_checks.py +++ b/tests/functional/m/member_checks.py @@ -227,3 +227,7 @@ class Animal(Enum): # To test false positive no-member on Enum.__members__.items() for itm in Animal.__members__.items(): print(itm) +for keyy in Animal.__members__.keys: + print(keyy) +for vall in Animal.__members__.values: + print(vall) From 49f859292e0612479f3a91813426cfb89491f70d Mon Sep 17 00:00:00 2001 From: ikraduya Date: Tue, 23 Feb 2021 12:57:53 +0700 Subject: [PATCH 07/10] Fix False positive on Enum.__members__.items() --- pylint/checkers/typecheck.py | 11 +++++++++++ tests/functional/m/member_checks.py | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index ad4ca70472..332b4ea860 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -505,6 +505,17 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins=True, ignored_none=T return False except astroid.NotFoundError: return True + if ( + owner.parent + and isinstance(owner.parent, astroid.ClassDef) + and owner.parent.name == "EnumMeta" + and owner_name == "__members__" + and node.attrname == "items" + ): + # Avoid false positive on Enum.__members__.items() + # See https://github.com/PyCQA/pylint/issues/4123 + return False + return True diff --git a/tests/functional/m/member_checks.py b/tests/functional/m/member_checks.py index 30f16c58c6..dc9bd38cea 100644 --- a/tests/functional/m/member_checks.py +++ b/tests/functional/m/member_checks.py @@ -217,3 +217,13 @@ def __init__(self, flag): else: self.attribute = [] self.attribute.append(1) + +from enum import Enum +class Animal(Enum): + ANT = 1 + BEE = 2 + CAT = 3 + DOG = 4 +# To test false positive no-member on Enum.__members__.items() +for itm in Animal.__members__.items(): + print(itm) From 2314f04d828a5b579de5b9c502e8cc6ecf9927c3 Mon Sep 17 00:00:00 2001 From: ikraduya Date: Thu, 25 Feb 2021 01:10:53 +0700 Subject: [PATCH 08/10] Fix false positive on Enum.__members__.{values, keys} --- pylint/checkers/typecheck.py | 5 +++-- tests/functional/m/member_checks.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 332b4ea860..65f79c18bb 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -510,9 +510,10 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins=True, ignored_none=T and isinstance(owner.parent, astroid.ClassDef) and owner.parent.name == "EnumMeta" and owner_name == "__members__" - and node.attrname == "items" + and node.attrname in ["items", "values", "keys"] ): - # Avoid false positive on Enum.__members__.items() + print(node.attrname) + # Avoid false positive on Enum.__members__.{items(), values, keys} # See https://github.com/PyCQA/pylint/issues/4123 return False diff --git a/tests/functional/m/member_checks.py b/tests/functional/m/member_checks.py index dc9bd38cea..291daee125 100644 --- a/tests/functional/m/member_checks.py +++ b/tests/functional/m/member_checks.py @@ -227,3 +227,7 @@ class Animal(Enum): # To test false positive no-member on Enum.__members__.items() for itm in Animal.__members__.items(): print(itm) +for keyy in Animal.__members__.keys: + print(keyy) +for vall in Animal.__members__.values: + print(vall) From 090a068167c364271aba3680e08c799515760186 Mon Sep 17 00:00:00 2001 From: ikraduya Date: Thu, 25 Feb 2021 01:29:06 +0700 Subject: [PATCH 09/10] Add description in ChangeLog --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index df57bcf571..2ae3f5edd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,10 @@ What's New in Pylint 2.7.2? .. Put bug fixes that will be cherry-picked to latest major version here +* Fix False Positive on `Enum.__members__.items()`, `Enum.__members__.values`, and `Enum.__members__.keys` + + Closes #4123 + What's New in Pylint 2.7.1? =========================== From 1a4b1f0fa2b0c78213017385f9e3da48c42e68bd Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 27 Feb 2021 21:18:53 +0100 Subject: [PATCH 10/10] Update ChangeLog Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- ChangeLog | 1 - 1 file changed, 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2ae3f5edd3..d3976d1e31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,6 @@ What's New in Pylint 2.7.2? Put bug fixes that will be cherry-picked to latest major version here * Fix False Positive on `Enum.__members__.items()`, `Enum.__members__.values`, and `Enum.__members__.keys` - Closes #4123