mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 23:54:17 +00:00
Make Option#normalize more reusable
This commit is contained in:
parent
e076fec666
commit
b4b59a9627
1 changed files with 7 additions and 8 deletions
|
|
@ -114,19 +114,17 @@ class Option(object):
|
||||||
return self.long_option_name[2:].replace('-', '_')
|
return self.long_option_name[2:].replace('-', '_')
|
||||||
return self.short_option_name[1]
|
return self.short_option_name[1]
|
||||||
|
|
||||||
def normalize(self, options):
|
def normalize(self, value):
|
||||||
dest = self.dest
|
"""Normalize the value based on the option configuration."""
|
||||||
if self.normalize_paths:
|
if self.normalize_paths:
|
||||||
old_value = getattr(options, dest)
|
|
||||||
# Decide whether to parse a list of paths or a single path
|
# Decide whether to parse a list of paths or a single path
|
||||||
normalize = utils.normalize_path
|
normalize = utils.normalize_path
|
||||||
if self.comma_separated_list:
|
if self.comma_separated_list:
|
||||||
normalize = utils.normalize_paths
|
normalize = utils.normalize_paths
|
||||||
setattr(options, dest, normalize(old_value))
|
return normalize(value)
|
||||||
elif self.comma_separated_list:
|
elif self.comma_separated_list:
|
||||||
old_value = getattr(options, dest)
|
return utils.parse_comma_separated_list(value)
|
||||||
setattr(options, dest,
|
return value
|
||||||
utils.parse_comma_separated_list(old_value))
|
|
||||||
|
|
||||||
def to_optparse(self):
|
def to_optparse(self):
|
||||||
"""Convert a Flake8 Option to an optparse Option."""
|
"""Convert a Flake8 Option to an optparse Option."""
|
||||||
|
|
@ -181,6 +179,7 @@ class OptionManager(object):
|
||||||
"""Simple proxy to calling the OptionParser's parse_args method."""
|
"""Simple proxy to calling the OptionParser's parse_args method."""
|
||||||
options, xargs = self.parser.parse_args(args, values)
|
options, xargs = self.parser.parse_args(args, values)
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
option.normalize(options)
|
old_value = getattr(options, option.dest)
|
||||||
|
setattr(options, option.dest, option.normalize(old_value))
|
||||||
|
|
||||||
return options, xargs
|
return options, xargs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue