mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 15:44:17 +00:00
Update compatibility docs
This commit is contained in:
parent
6b7855e102
commit
5a9b7c27ab
1 changed files with 8 additions and 2 deletions
|
|
@ -106,6 +106,8 @@ options with |Flake8| and have it work on |Flake8| 2.x and 3.x.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
import optparse
|
||||||
|
|
||||||
option_args = ('-X', '--example-flag')
|
option_args = ('-X', '--example-flag')
|
||||||
option_kwargs = {
|
option_kwargs = {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
|
|
@ -115,7 +117,7 @@ options with |Flake8| and have it work on |Flake8| 2.x and 3.x.
|
||||||
try:
|
try:
|
||||||
# Flake8 3.x registration
|
# Flake8 3.x registration
|
||||||
parser.add_option(*option_args, **option_kwargs)
|
parser.add_option(*option_args, **option_kwargs)
|
||||||
except TypeError:
|
except (optparse.OptionError, TypeError):
|
||||||
# Flake8 2.x registration
|
# Flake8 2.x registration
|
||||||
parse_from_config = option_kwargs.pop('parse_from_config', False)
|
parse_from_config = option_kwargs.pop('parse_from_config', False)
|
||||||
parser.add_option(*option_args, **option_kwargs)
|
parser.add_option(*option_args, **option_kwargs)
|
||||||
|
|
@ -127,13 +129,17 @@ Or, you can write a tiny helper function:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
import optparse
|
||||||
|
|
||||||
def register_opt(parser, *args, **kwargs):
|
def register_opt(parser, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
# Flake8 3.x registration
|
# Flake8 3.x registration
|
||||||
parser.add_option(*args, **kwargs)
|
parser.add_option(*args, **kwargs)
|
||||||
except TypeError:
|
except (optparse.OptionError, TypeError):
|
||||||
# Flake8 2.x registration
|
# Flake8 2.x registration
|
||||||
parse_from_config = kwargs.pop('parse_from_config', False)
|
parse_from_config = kwargs.pop('parse_from_config', False)
|
||||||
|
kwargs.pop('comma_separated_list', False)
|
||||||
|
kwargs.pop('normalize_paths', False)
|
||||||
parser.add_option(*args, **kwargs)
|
parser.add_option(*args, **kwargs)
|
||||||
if parse_from_config:
|
if parse_from_config:
|
||||||
parser.config_options.append(args[-1].lstrip('-'))
|
parser.config_options.append(args[-1].lstrip('-'))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue