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

Fix False positive on Enum.__members__.items() #4135

Merged
merged 11 commits into from
Feb 27, 2021
45 changes: 40 additions & 5 deletions .github/ISSUE_TEMPLATE/1_Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!--
Given a file `a.py`:
```python
# (Disable message unrelated to the bug)
# pylint: disable=missing-docstring,...

```

Given multiple files:
```
__init__.py
a.py
module\
__init__.py
b.py
c.py
```
-->

### Current behavior
<!--
Result of `pylint a.py`:
```

```
-->

### Expected behavior


### pylint --version output

Result of `pylint --version` output:
```

```

<!--
Additional dependencies:
```
pandas==0.23.2
marshmallow==3.10.0
...
```
-->
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/2_Feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
50 changes: 50 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- 2.*
pull_request: ~

env:
Expand Down Expand Up @@ -319,6 +320,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/[email protected]
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
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/[email protected]
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)
Expand Down
20 changes: 20 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@ 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

* Fix False Positive on `Enum.__members__.items()`, `Enum.__members__.values`, and `Enum.__members__.keys`

Pierre-Sassoulas marked this conversation as resolved.
Show resolved Hide resolved
Closes #4123


What's New in Pylint 2.7.1?
===========================

* Expose `UnittestLinter` in pylint.testutils

* Don't check directories starting with '.' when using register_plugins

Closes #4119


What's New in Pylint 2.7.0?
Expand Down
12 changes: 12 additions & 0 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,18 @@ 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 in ["items", "values", "keys"]
):
print(node.attrname)
# Avoid false positive on Enum.__members__.{items(), values, keys}
# See https://github.com/PyCQA/pylint/issues/4123
return False

return True


Expand Down
6 changes: 5 additions & 1 deletion pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/m/member_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,17 @@ 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)
for keyy in Animal.__members__.keys:
print(keyy)
for vall in Animal.__members__.values:
print(vall)