pyclean.compat.ExtendAction.__call__()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# SPDX-FileCopyrightText: 2019 Peter Bittner <[email protected]>
2
#
3
# SPDX-License-Identifier: GPL-3.0-or-later
4
5
"""
6
Cross-Python version compatibility.
7
"""
8
9
from argparse import _AppendAction as AppendAction
10
11
12
class ExtendAction(AppendAction):  # pragma: no-cover-gt-py37
13
    """
14
    Argparse "extend" action for Python < 3.8.
15
    A simplified backport from the Python standard library.
16
    """
17
18
    def __call__(self, parser, namespace, values, option_string=None):  # noqa: ARG002
19
        items = getattr(namespace, self.dest, None)
20
        items = [] if items is None else items[:]
21
        items.extend(values)
22
        setattr(namespace, self.dest, items)
23