Skip to content

Commit

Permalink
Closes #1254
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Mar 22, 2020
1 parent e185072 commit 4f278f5
Show file tree
Hide file tree
Showing 27 changed files with 248 additions and 127 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ Semantic versioning in our case means:
- Major releases inidicate significant milestones or serious breaking changes.


## 0.14.0 aka The Walrus fighter WIP
## 0.14.0 aka The Walrus fighter

This release was focused on adding `python3.8` support,
removing dependencies that can be removed, and fixing bugs.

There are breaking changes ahead!

We also have this [nice migration guide](https://wemake-python-stylegui.de/en/latest/pages/changelog/migration_to_0_14.html).

### Features

- **Breaking**: removes `flake8-executable`, now using `WPS452` instead of `EXE001..EXE005`
- **Breaking**: removes `flake8-print`, now using `WPS421` instead of `T001`
- **Breaking**: removes `flake8-builtins`, now using `WPS125` instead of `A001..A005`
- **Breaking**: removes `flake8-annotations-complexity`,
now using `WPS234` instead of `TAE002`
- **Breaking**: removes `flake8-pep3101`, now using `WPS323` instead of `S001`,
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _get_project_meta():

pkg_meta = _get_project_meta()
project = pkg_meta['name']
copyright = '2018, wemake.services' # noqa: A001
copyright = '2018, wemake.services' # noqa: WPS125
author = 'wemake.services'

# The short X.Y version
Expand Down
1 change: 1 addition & 0 deletions docs/pages/changelog/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
:hidden:

migration_to_0_11.rst
migration_to_0_14.rst
53 changes: 53 additions & 0 deletions docs/pages/changelog/migration_to_0_14.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Migration guide to 0.14
=======================

One of the most important things in this release was
that we are focused on removing extra dependencies.

Why?

For several reasons:

1. Some dependencies do not meet our quality standards:
there are bugs, lack of recent releases, new language features support, etc

2. Some dependencies are just really simple. Just several lines of code.
We can simply recreate them inside.
The good example would be ``flake8-print``,
we have added just a single configuration line
to have the very same check internally.

3. Better installation experience. It is faster, less possible conflicts.

Dropped dependencies
--------------------

We have replaced the following dependencies in this release:

- ``flake8-executable`` (check is ported)
- ``flake8-print`` (check is ported)
- ``flake8-builtins`` (check is ported)
- ``flake8-annotations-complexity`` (check is ported)
- ``flake8-pep3101`` (check is ported and modified)
- ``flake8-loggin-format`` (check is dropped)
- ``flake8-coding`` (check is dropped)
- ``radon`` (check is dropped)
- ``cognitive-complexity`` (check is ported)


Changed codes
-------------

When we port a dependency to our own codebase,
this means that we also change the error code.

You would probably have to update it in your source code as well:

- ``EXE001..EXE005`` -> ``WPS452`` (``flake8-executable``)
- ``T001`` -> ``WPS421`` (``flake8-print``)
- ``A001..A005`` -> ``WPS125`` (``flake8-builtins``)
- ``TAE002`` -> ``WPS234`` (``flake8-annotations-complexity``)
- ``S001`` -> ``WPS323`` (``flake8-pep3101``)

You would possibly want to manually install dropped dependencies again.
In case you need them. Or just ignore them (as we do).
1 change: 0 additions & 1 deletion docs/pages/usage/violations/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ All codes are sorted alphabetically and by numerical codes.
============================= ======
Plugin Codes
----------------------------- ------
flake8-builtins `A001 - A002 <https://github.com/gforcada/flake8-builtins/blob/master/flake8_builtins.py>`_
flake8-bugbear `B001 - B008 <https://github.com/PyCQA/flake8-bugbear#list-of-warnings>`_
flake8-comprehensions `C400 - C411 <https://github.com/adamchainz/flake8-comprehensions>`_
flake8-commas `C812 - C819 <https://pypi.org/project/flake8-commas/>`_
Expand Down
30 changes: 6 additions & 24 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ astor = "^0.8"
pygments = "^2.4"
importlib-metadata = {version = "*", python = "<3.8"}

flake8-builtins = "^1.5.2"
flake8-commas = "^2.0"
flake8-quotes = "^2.0.1"
flake8-comprehensions = "^3.1.0"
Expand All @@ -78,7 +77,7 @@ darglint = "^1.2"

[tool.poetry.dev-dependencies]
nitpick = "^0.21.3"
flake8-pytest-style = "^0.2.0"
flake8-pytest-style = "^0.5.0"

pytest-cov = "^2.8"
coverage-conditional-plugin = "^0.1.0"
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/external_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
from typing import List, Union, Dict

int = 12
++int

extra_parens = list((node for node in 'abc'))
Expand All @@ -14,7 +13,6 @@
def camelCase(): ...

'{}'.format(1)
""

assert True
ipdb.set_trace()
Expand Down
13 changes: 7 additions & 6 deletions tests/fixtures/noqa/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def some_function():

used, __ = 1, 2 # noqa: WPS123

class Mem0Output(object): # noqa: WPS124
# See:
# https://github.com/wemake-services/wemake-python-styleguide/issues/1191
anti_wps124 = 'unreadable class'

type = 'type' # noqa: WPS125

some._execute() # noqa: WPS437


Expand Down Expand Up @@ -703,9 +710,3 @@ def consecutive_yields():
# https://github.com/wemake-services/wemake-python-styleguide/issues/1082
break
my_print(4)


class Mem0Output(object): # noqa: WPS124
# See:
# https://github.com/wemake-services/wemake-python-styleguide/issues/1191
anti_wps124 = 'unreadable class'
1 change: 1 addition & 0 deletions tests/test_checker/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'WPS122': 1,
'WPS123': 1,
'WPS124': 1,
'WPS125': 1,

'WPS200': 0, # logically unacceptable.
'WPS201': 0, # defined in ignored violations.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_options/test_validate_domain_names_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def test_passes_when_names_no_intersect():

def test_raises_valueerror_when_names_intersect():
"""Ensures `ValueError` exception is raised when names intersect."""
with pytest.raises(ValueError):
with pytest.raises(ValueError, match='visitor'):
validate_domain_names_options(['visitor', 'handle'], ['visitor'])
4 changes: 1 addition & 3 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@

PLUGINS = (
'B002', # flake8-bugbear
'A001', # flake8-builtins
'C400', # flake8-comprehensions
'C819', # flake8-commas
'D103', # flake8-docstring
'E225', # pycodestyle
'E800', # flake8-eradicate
'F401', # flake8
'F401', # pyflakes
'I001', # flake8-isort
'N400', # flake8-broken-line
'N802', # pep8-naming
'P101', # flake8-string-format
'Q000', # flake8-quotes
'Q003', # flake8-quotes
'S101', # flake8-bandit
'T100', # flake8-debugger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Test(object):

regression423 = """
class MyClass(object):
def action_method(self, request, object):
def action_method(self, request, second):
...
action_method.label = 'Do action'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest

from wemake_python_styleguide.violations.naming import (
BuiltinShadowingViolation,
)
from wemake_python_styleguide.visitors.ast.naming import WrongNameVisitor


@pytest.mark.parametrize('wrong_name', [
'list',
'str',
'sum',
])
def test_builtin_shadowing(
assert_errors,
assert_error_text,
parse_ast_tree,
naming_template,
default_options,
mode,
wrong_name,
):
"""Test names that shadow builtins."""
tree = parse_ast_tree(mode(naming_template.format(wrong_name)))

visitor = WrongNameVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [BuiltinShadowingViolation])
assert_error_text(visitor, wrong_name)
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ def test_short_variable_name_underscore(
visitor = WrongNameVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [
TooShortNameViolation,
assert_errors(visitor, [TooShortNameViolation], (
TrailingUnderscoreViolation,
])
))


def test_naming_length_settings(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_visitors/test_decorators/test_alias_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def first(self):

def test_raises_for_duplicates():
"""Ensures that decorator raises an exception for duplicates."""
with pytest.raises(ValueError):
with pytest.raises(ValueError, match='duplicate'):
alias('name', ('duplicate', 'duplicate'))


def test_useless_alias():
"""Ensures that decorator raises an exception for duplicates."""
with pytest.raises(ValueError):
with pytest.raises(ValueError, match='duplicate'):
alias('name', ('name',))


Expand Down
3 changes: 3 additions & 0 deletions wemake_python_styleguide/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,6 @@

# Used to determine when we are running on Windows:
WINDOWS_OS: Final = 'nt'

# Used as a placeholder for special `_` variable:
UNUSED_PLACEHOLDER: Final = '_'
2 changes: 1 addition & 1 deletion wemake_python_styleguide/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def handle(self, error: Violation) -> None: # noqa: WPS110
super().handle(error)
self._error_count += 1

def format(self, error: Violation) -> str: # noqa: A003
def format(self, error: Violation) -> str: # noqa: WPS125
"""Called to format each individual :term:`violation`."""
return '{newline} {row_col:<8} {code:<5} {text}'.format(
newline=self.newline if self._should_show_source(error) else '',
Expand Down
16 changes: 14 additions & 2 deletions wemake_python_styleguide/logic/naming/builtins.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import builtins
import inspect
import keyword

from flake8_builtins import BUILTINS
from typing_extensions import Final

from wemake_python_styleguide.constants import UNUSED_PLACEHOLDER
from wemake_python_styleguide.logic.naming.access import is_magic, is_unused

_BUILTINS_WHITELIST: Final = frozenset((
UNUSED_PLACEHOLDER,
))

_BUILTINS: Final = frozenset((
builtin[0]
for builtin in inspect.getmembers(builtins)
if builtin[0] not in _BUILTINS_WHITELIST
))

_ALL_BUILTINS: Final = frozenset((
*keyword.kwlist,
*BUILTINS,
*_BUILTINS,

# Special case.
# Some python version have them, some do not have them:
Expand Down
3 changes: 2 additions & 1 deletion wemake_python_styleguide/logic/naming/logical.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Iterable

from wemake_python_styleguide.constants import UNUSED_PLACEHOLDER
from wemake_python_styleguide.logic.naming import access


Expand Down Expand Up @@ -113,7 +114,7 @@ def is_too_short_name(
return False

if trim:
name = name.strip('_')
name = name.strip(UNUSED_PLACEHOLDER)

return len(name) < min_length

Expand Down
Loading

0 comments on commit 4f278f5

Please sign in to comment.