Skip to content

Commit

Permalink
Fixes for latest flake8 (#903)
Browse files Browse the repository at this point in the history
`action='store_true'` + `type=None` is not valid for argparse

See also wemake-services/flake8-eradicate#79
  • Loading branch information
asottile authored and sobolevn committed Oct 15, 2019
1 parent 5c4de1c commit 5aacfbf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ We used to have incremental versioning before `0.1.0`.

- Fixes ``ImplicitElifViolation`` false positives on a specific edge cases
- Fixes ``I_CONTROL_CODE setting`` for ``BadMagicModuleFunctionViolation``
- Fixes compatibility with flake8 3.8.x


## 0.12.5
Expand Down
8 changes: 8 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ def test_option_help():
assert len(option.help) > 10
assert '%default' in option.help
assert option.help.split(' Defaults to:')[0].endswith('.')


def test_option_asdict_no_none():
"""Ensure that `None` is not returned from `asdict_no_none()`."""
opt = config._Option( # noqa: WPS437
'--foo', default=False, action='store_true', type=None, help='',
)
assert 'type' not in opt.asdict_no_none()
16 changes: 14 additions & 2 deletions wemake_python_styleguide/options/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@
"""

from typing import ClassVar, FrozenSet, Mapping, Optional, Sequence, Union
from typing import (
ClassVar,
Dict,
FrozenSet,
Mapping,
Optional,
Sequence,
Union,
)

import attr
from flake8.options.manager import OptionManager
Expand Down Expand Up @@ -149,6 +157,10 @@ def __attrs_post_init__(self):
self, 'help', ' '.join((self.help, 'Defaults to: %default')),
)

def asdict_no_none(self) -> Dict[str, ConfigValuesTypes]:
dct = attr.asdict(self)
return {key: opt for key, opt in dct.items() if opt is not None}


@final
class Configuration(object):
Expand Down Expand Up @@ -317,4 +329,4 @@ class Configuration(object):
def register_options(self, parser: OptionManager) -> None:
"""Registers options for our plugin."""
for option in self._options:
parser.add_option(**attr.asdict(option))
parser.add_option(**option.asdict_no_none())

0 comments on commit 5aacfbf

Please sign in to comment.