diff options
| author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2019-01-17 13:50:50 +0000 |
|---|---|---|
| committer | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2019-01-17 13:50:50 +0000 |
| commit | 0f3f4ff9b4e7901695484ee1ea1fbcbc19632149 (patch) | |
| tree | 4d4f8780d1e2e965f5041e6abac04dd705bcdf73 | |
| parent | 97e492755568928d804d2172ba71db578f4a39c4 (diff) | |
| parent | cc20e35058da474bd56eea7cf893a872506926e6 (diff) | |
| download | flake8-0f3f4ff9b4e7901695484ee1ea1fbcbc19632149.tar.gz | |
Merge branch 'master' into 'master'
Add support for optparse's 'float' and 'complex' types.
Closes #452
See merge request pycqa/flake8!261
| -rw-r--r-- | src/flake8/options/manager.py | 4 | ||||
| -rw-r--r-- | tests/unit/test_option.py | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py index 3f4e883..0ded13a 100644 --- a/src/flake8/options/manager.py +++ b/src/flake8/options/manager.py @@ -156,6 +156,10 @@ class Option(object): value = self.normalize(value) if self.type == "int" or self.action == "count": 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"): value = str(value).upper() if value in ("1", "T", "TRUE", "ON"): diff --git a/tests/unit/test_option.py b/tests/unit/test_option.py index 76b4341..eb4f95d 100644 --- a/tests/unit/test_option.py +++ b/tests/unit/test_option.py @@ -23,6 +23,16 @@ def test_to_optparse(): 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') def test_to_optparse_creates_an_option_as_we_expect(Option): # noqa: N803 """Show that we pass all keyword args to optparse.Option.""" |
