Skip to content

Commit a8c3212

Browse files
committed
BUGFIX: pylint argparse_check_range.py
1 parent 8d8cca4 commit a8c3212

File tree

2 files changed

+50
-54
lines changed

2 files changed

+50
-54
lines changed
Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
#!/usr/bin/env python3
22

3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
3+
'''
4+
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator
145
15-
# SPDX-FileCopyrightText: 2024 Dmitriy Kovalev
6+
SPDX-FileCopyrightText: 2024 Dmitriy Kovalev
167
17-
# SPDX-License-Identifier: Apache-2.0
8+
SPDX-License-Identifier: Apache-2.0
189
19-
# https://gist.github.com/dmitriykovalev/2ab1aa33a8099ef2d514925d84aa89e7
10+
https://gist.github.com/dmitriykovalev/2ab1aa33a8099ef2d514925d84aa89e7
11+
'''
2012

2113
from argparse import Action
2214
from argparse import ArgumentError
@@ -27,42 +19,45 @@
2719

2820

2921
class CheckRange(Action):
30-
ops = {'inf': gt,
31-
'min': ge,
32-
'sup': lt,
33-
'max': le}
34-
35-
def __init__(self, *args, **kwargs):
36-
if 'min' in kwargs and 'inf' in kwargs:
37-
raise ValueError('either min or inf, but not both')
38-
if 'max' in kwargs and 'sup' in kwargs:
39-
raise ValueError('either max or sup, but not both')
40-
41-
for name in self.ops:
42-
if name in kwargs:
43-
setattr(self, name, kwargs.pop(name))
44-
45-
super().__init__(*args, **kwargs)
46-
47-
def interval(self):
48-
if hasattr(self, 'min'):
49-
l = f'[{self.min}'
50-
elif hasattr(self, 'inf'):
51-
l = f'({self.inf}'
52-
else:
53-
l = '(-infinity'
54-
55-
if hasattr(self, 'max'):
56-
u = f'{self.max}]'
57-
elif hasattr(self, 'sup'):
58-
u = f'{self.sup})'
59-
else:
60-
u = '+infinity)'
61-
62-
return f'valid range: {l}, {u}'
63-
64-
def __call__(self, parser, namespace, values, option_string=None):
65-
for name, op in self.ops.items():
66-
if hasattr(self, name) and not op(values, getattr(self, name)):
67-
raise ArgumentError(self, self.interval())
68-
setattr(namespace, self.dest, values)
22+
'''
23+
Check if the Argparse argument value is within the specified range
24+
'''
25+
ops = {"inf": gt,
26+
"min": ge,
27+
"sup": lt,
28+
"max": le}
29+
30+
def __init__(self, *args, **kwargs):
31+
if "min" in kwargs and "inf" in kwargs:
32+
raise ValueError("either min or inf, but not both")
33+
if "max" in kwargs and "sup" in kwargs:
34+
raise ValueError("either max or sup, but not both")
35+
36+
for name in self.ops:
37+
if name in kwargs:
38+
setattr(self, name, kwargs.pop(name))
39+
40+
super().__init__(*args, **kwargs)
41+
42+
def interval(self):
43+
if hasattr(self, "min"):
44+
lo = f"[{self.min}"
45+
elif hasattr(self, "inf"):
46+
lo = f"({self.inf}"
47+
else:
48+
lo = "(-infinity"
49+
50+
if hasattr(self, "max"):
51+
up = f"{self.max}]"
52+
elif hasattr(self, "sup"):
53+
up = f"{self.sup})"
54+
else:
55+
up = "+infinity)"
56+
57+
return f"valid range: {lo}, {up}"
58+
59+
def __call__(self, parser, namespace, values, option_string=None):
60+
for name, op in self.ops.items():
61+
if hasattr(self, name) and not op(values, getattr(self, name)):
62+
raise ArgumentError(self, self.interval())
63+
setattr(namespace, self.dest, values)

credits/CREDITS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
77
# Licenses
88

99
We use [REUSE software API](https://api.reuse.software/) in the form of SPDX tags in most of the files to explicitly declare Copyright and License.
10-
However we do not do it for every single file and hence are [![REUSE status](https://api.reuse.software/badge/github.com/ArduPilot/MethodicConfigurator)](https://api.reuse.software/info/github.com/ArduPilot/MethodicConfigurator)
10+
However, we do not do it for every single file and hence are [![REUSE status](https://api.reuse.software/badge/github.com/ArduPilot/MethodicConfigurator)](https://api.reuse.software/info/github.com/ArduPilot/MethodicConfigurator)
1111

1212
This software is licensed under the [GNU General Public License v3.0](../LICENSE.md) and is built on top of (depends on) other open-source software.
1313
We are thankful to the developers of those software packages.
@@ -30,6 +30,7 @@ It directly uses:
3030
| [pyserial](https://pyserial.readthedocs.io/en/latest/pyserial.html) | [BSD License](https://github.com/pyserial/pyserial/blob/master/LICENSE.txt) |
3131
| [Scrollable TK frame](https://gist.github.com/mp035/9f2027c3ef9172264532fcd6262f3b01) by Mark Pointing | [Mozilla Public License, v. 2.0](https://mozilla.org/MPL/2.0/) |
3232
| [Python Tkinter ComboBox](https://dev.to/geraldew/python-tkinter-an-exercise-in-wrapping-the-combobox-ndb) by geraldew | [Mozilla Public License, v. 2.0](https://mozilla.org/MPL/2.0/) |
33+
| [Argparse check limits](https://gist.github.com/dmitriykovalev/2ab1aa33a8099ef2d514925d84aa89e7) by Dmitriy Kovalev | [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0) |
3334

3435
It indirectly uses:
3536

0 commit comments

Comments
 (0)