Skip to content

Commit

Permalink
Merge pull request #156 from jamescooke/assignment-expression
Browse files Browse the repository at this point in the history
Assert compatibility with Python 3.8's assignment expression
  • Loading branch information
jamescooke committed Jun 11, 2020
2 parents 3461f35 + 10b3294 commit 21334f9
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 47 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Unreleased_
See also `latest documentation
<https://flake8-aaa.readthedocs.io/en/latest/#__unreleased_marker__>`_.

Added
.....

* Add good example usage of the assignment expression in Python 3.8 to
guarantee compatibility. `#120
<https://github.com/jamescooke/flake8-aaa/issues/120>`_.

Changed
.......

Expand All @@ -28,7 +35,11 @@ Added
.....

* Test examples are intended to be real but simple examples. All examples added
or updated are now executed with pytest and no imports and must be green.
or updated from now on must:

- Go green when run with Pytest.

- Use only standard library imports.

Changed
.......
Expand Down
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ tox:

# --- Tox recipes ---

# Tox: -e "py3{6,7,8}-lint"
.PHONY: lint
lint:
@echo "=== flake8 ==="
Expand All @@ -48,37 +47,40 @@ fixlint:
@echo "=== fixing yapf ==="
yapf --recursive --in-place $(lint_files)

# Tox: -e "py3{6,7,8}-lintexamples"
.PHONY: lintexamples
lintexamples:
@echo "=== flake8 ==="
flake8 examples | sort > flake8.out
flake8 examples/good examples/bad | sort > flake8.out
diff examples/bad/flake8_expected.out flake8.out
@echo "=== mypy ==="
mypy examples examples/good --ignore-missing-imports
mypy examples/bad --ignore-missing-imports
@echo "=== black ==="
black --check --diff --verbose examples/good/black

.PHONY: lintexamplespy38
lintexamplespy38:
@echo "=== flake8 ==="
flake8 examples/good_py38
@echo "=== mypy ==="
mypy examples/good_py38

.PHONY: fixlintexamples
fixlintexamples:
@echo "=== black ==="
black examples/good/black

# Tox: -e "py36-doc"
.PHONY: doc
doc:
$(MAKE) -C docs html

# Tox: -e "py3{6,7,8}-cmd"
.PHONY: cmd
cmd:
for i in $(good_examples); do \
echo "\n=== $$i ==="; \
python -m flake8_aaa "$$i" || break -1; \
done

# Tox: -e "py3{6,7,8}-cmdbad"
# NOTE: Checks that all bad example files give at least 1 error and all return
# an error code greater than 0. The `echo;` is used to wipe the error code from
# the last test, or the for loop fails.
Expand Down
10 changes: 10 additions & 0 deletions examples/good_py38/test_assignment_operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test():
"""
clear() removes all items from a list
"""
shopping = ["apples", "bananas", "cabbages"]

result = shopping.clear()

assert result is None
assert (n := len(shopping)) == 0, f"Expected 0 items of shopping, got {n}"
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# pip-compile --output-file=base.txt base.in
#
asttokens==2.0.4 # via -r base.in
flake8==3.8.2 # via -r base.in
importlib-metadata==1.6.0 # via flake8
flake8==3.8.3 # via -r base.in
importlib-metadata==1.6.1 # via flake8
mccabe==0.6.1 # via flake8
pycodestyle==2.6.0 # via flake8
pyflakes==2.2.0 # via flake8
Expand Down
8 changes: 4 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# pip-compile --output-file=dev.txt dev.in
#
bleach==3.1.5 # via readme-renderer
certifi==2020.4.5.1 # via -c test.txt, requests
certifi==2020.4.5.2 # via -c test.txt, requests
cffi==1.14.0 # via cryptography
chardet==3.0.4 # via -c test.txt, requests
click==7.1.2 # via pip-tools
cryptography==2.9.2 # via secretstorage
docutils==0.16 # via -c test.txt, readme-renderer
idna==2.9 # via -c test.txt, requests
importlib-metadata==1.6.0 # via -c base.txt, -c test.txt, keyring, twine
importlib-metadata==1.6.1 # via -c base.txt, -c test.txt, keyring, twine
jeepney==0.4.3 # via keyring, secretstorage
keyring==21.2.1 # via twine
packaging==20.4 # via -c test.txt, bleach
pip-tools==5.1.2 # via -r dev.in
pip-tools==5.2.1 # via -r dev.in
pkginfo==1.5.0.1 # via twine
pycparser==2.20 # via cffi
pygments==2.6.1 # via -c test.txt, readme-renderer
Expand All @@ -26,7 +26,7 @@ requests-toolbelt==0.9.1 # via twine
requests==2.23.0 # via -c test.txt, requests-toolbelt, twine
secretstorage==3.1.2 # via keyring
six==1.15.0 # via -c base.txt, -c test.txt, bleach, cryptography, packaging, pip-tools, readme-renderer
tqdm==4.46.0 # via twine
tqdm==4.46.1 # via twine
twine==3.1.1 # via -r dev.in
urllib3==1.25.9 # via -c test.txt, requests
webencodings==0.5.1 # via bleach
Expand Down
12 changes: 6 additions & 6 deletions requirements/examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ appdirs==1.4.4 # via black
attrs==19.3.0 # via black, pytest
black==19.10b0 # via -r examples.in
click==7.1.2 # via black
flake8==3.8.2 # via -r examples.in
importlib-metadata==1.6.0 # via flake8, pluggy, pytest
flake8==3.8.3 # via -r examples.in
importlib-metadata==1.6.1 # via flake8, pluggy, pytest
mccabe==0.6.1 # via flake8
more-itertools==8.3.0 # via pytest
mypy-extensions==0.4.3 # via mypy
mypy==0.770 # via -r examples.in
mypy==0.780 # via -r examples.in
packaging==20.4 # via pytest
pathspec==0.8.0 # via black
pluggy==0.13.1 # via pytest
py==1.8.1 # via pytest
pycodestyle==2.6.0 # via flake8
pyflakes==2.2.0 # via flake8
pyparsing==2.4.7 # via packaging
pytest==5.4.2 # via -r examples.in
regex==2020.5.14 # via black
pytest==5.4.3 # via -r examples.in
regex==2020.6.8 # via black
six==1.15.0 # via packaging
toml==0.10.1 # via black
typed-ast==1.4.1 # via black, mypy
typing-extensions==3.7.4.2 # via mypy
wcwidth==0.1.9 # via pytest
wcwidth==0.2.4 # via pytest
zipp==3.1.0 # via importlib-metadata
18 changes: 9 additions & 9 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,51 @@ alabaster==0.7.12 # via sphinx
appdirs==1.4.4 # via virtualenv
attrs==19.3.0 # via pytest
babel==2.8.0 # via sphinx
certifi==2020.4.5.1 # via requests
certifi==2020.4.5.2 # via requests
chardet==3.0.4 # via requests
distlib==0.3.0 # via virtualenv
docutils==0.16 # via restructuredtext-lint, sphinx
filelock==3.0.12 # via tox, virtualenv
flake8==3.8.2 # via -c base.txt, -r test.in
flake8==3.8.3 # via -c base.txt, -r test.in
idna==2.9 # via requests
imagesize==1.2.0 # via sphinx
importlib-metadata==1.6.0 # via -c base.txt, flake8, importlib-resources, pluggy, pytest, tox, virtualenv
importlib-metadata==1.6.1 # via -c base.txt, flake8, importlib-resources, pluggy, pytest, tox, virtualenv
importlib-resources==1.5.0 # via virtualenv
isort==4.3.21 # via -r test.in
jinja2==2.11.2 # via sphinx
markupsafe==1.1.1 # via jinja2
mccabe==0.6.1 # via -c base.txt, flake8
more-itertools==8.3.0 # via pytest
mypy-extensions==0.4.3 # via mypy
mypy==0.770 # via -r test.in
mypy==0.780 # via -r test.in
packaging==20.4 # via pytest, sphinx, tox
pluggy==0.13.1 # via pytest, tox
py==1.8.1 # via pytest, tox
pycodestyle==2.6.0 # via -c base.txt, flake8
pyflakes==2.2.0 # via -c base.txt, flake8
pygments==2.6.1 # via -r test.in, sphinx
pyparsing==2.4.7 # via packaging
pytest==5.4.2 # via -r test.in
pytest==5.4.3 # via -r test.in
pytz==2020.1 # via babel
requests==2.23.0 # via sphinx
restructuredtext-lint==1.3.0 # via -r test.in
restructuredtext-lint==1.3.1 # via -r test.in
six==1.15.0 # via -c base.txt, -r test.in, packaging, tox, virtualenv
snowballstemmer==2.0.0 # via sphinx
sphinx-rtd-theme==0.4.3 # via -r test.in
sphinx==3.0.3 # via -r test.in, sphinx-rtd-theme
sphinx==3.1.0 # via -r test.in, sphinx-rtd-theme
sphinxcontrib-applehelp==1.0.2 # via sphinx
sphinxcontrib-devhelp==1.0.2 # via sphinx
sphinxcontrib-htmlhelp==1.0.3 # via sphinx
sphinxcontrib-jsmath==1.0.1 # via sphinx
sphinxcontrib-qthelp==1.0.3 # via sphinx
sphinxcontrib-serializinghtml==1.1.4 # via sphinx
toml==0.10.1 # via tox
tox==3.15.1 # via -r test.in
tox==3.15.2 # via -r test.in
typed-ast==1.4.1 # via mypy
typing-extensions==3.7.4.2 # via mypy
urllib3==1.25.9 # via requests
virtualenv==20.0.21 # via tox
wcwidth==0.1.9 # via pytest
wcwidth==0.2.4 # via pytest
yapf==0.30.0 # via -r test.in
zipp==3.1.0 # via -c base.txt, importlib-metadata, importlib-resources

Expand Down
Empty file removed tests_py36_plus/__init__.py
Empty file.
Empty file.
18 changes: 0 additions & 18 deletions tests_py36_plus/conftest.py

This file was deleted.

Empty file.
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ commands =
cmdbad: make cmdbad
doc: make doc
examples: {[examples]commands}
py38-examples: {[py38-examples]commands}
examples_aaa: {[examples_aaa]commands}
install: {[install]commands}
lint: make lint
Expand All @@ -69,13 +70,19 @@ commands =
commands =
make lintexamples
pytest \
examples/good/black/test_context_block_act.py \
examples/good/test_with_statement.py \
examples/good/test_with_statement_unittest.py \
examples/good/black/test_context_block_act.py \
examples/bad/test_aaa03.py \
examples/bad/test_aaa03_04.py \
examples/bad/test_aaa04.py

[py38-examples]
# Add extra checks on Python 3.8 files
commands =
make lintexamplespy38
pytest examples/good_py38/test_assignment_operator.py

[examples_aaa]
commands =
flake8 --version
Expand Down

0 comments on commit 21334f9

Please sign in to comment.