mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-08 14:04:16 +00:00
Merge branch 'master' into 'master'
Add support for optparse's 'float' and 'complex' types. Closes #452 See merge request pycqa/flake8!261
This commit is contained in:
commit
0f3f4ff9b4
2 changed files with 14 additions and 0 deletions
|
|
@ -156,6 +156,10 @@ class Option(object):
|
||||||
value = self.normalize(value)
|
value = self.normalize(value)
|
||||||
if self.type == "int" or self.action == "count":
|
if self.type == "int" or self.action == "count":
|
||||||
return int(value)
|
return int(value)
|
||||||
|
elif self.type == "float":
|
||||||
|
return float(value)
|
||||||
|
elif self.type == "complex":
|
||||||
|
return complex(value)
|
||||||
if self.action in ("store_true", "store_false"):
|
if self.action in ("store_true", "store_false"):
|
||||||
value = str(value).upper()
|
value = str(value).upper()
|
||||||
if value in ("1", "T", "TRUE", "ON"):
|
if value in ("1", "T", "TRUE", "ON"):
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,16 @@ def test_to_optparse():
|
||||||
assert optparse_opt.action == 'count'
|
assert optparse_opt.action == 'count'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('opttype,str_val,expected', [
|
||||||
|
('float', '2', 2.0),
|
||||||
|
('complex', '2', (2 + 0j)),
|
||||||
|
])
|
||||||
|
def test_to_support_optparses_standard_types(opttype, str_val, expected):
|
||||||
|
"""Show that optparse converts float and complex types correctly."""
|
||||||
|
opt = manager.Option('-t', '--test', type=opttype)
|
||||||
|
assert opt.normalize_from_setuptools(str_val) == expected
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('optparse.Option')
|
@mock.patch('optparse.Option')
|
||||||
def test_to_optparse_creates_an_option_as_we_expect(Option): # noqa: N803
|
def test_to_optparse_creates_an_option_as_we_expect(Option): # noqa: N803
|
||||||
"""Show that we pass all keyword args to optparse.Option."""
|
"""Show that we pass all keyword args to optparse.Option."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue