Skip to content

Commit 10ab650

Browse files
committed
Removing support for Python 3.8
1 parent 596a82e commit 10ab650

File tree

6 files changed

+12
-63
lines changed

6 files changed

+12
-63
lines changed

.github/workflows/main.yml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
strategy:
1616
matrix:
1717
python:
18-
- "3.8"
1918
- "3.9"
2019
- "3.10"
2120
- "3.11"

argparse_dataclass.py

+4-53
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,17 @@
225225
"""
226226

227227
import argparse
228+
from argparse import BooleanOptionalAction
228229
from typing import (
229230
TypeVar,
230231
Optional,
231232
Sequence,
232233
Type,
233234
Tuple,
234-
List,
235235
get_origin,
236236
Literal,
237237
get_args,
238238
Union,
239-
Dict,
240239
Any,
241240
Generic,
242241
)
@@ -249,54 +248,6 @@
249248
)
250249
from importlib.metadata import version
251250

252-
if hasattr(argparse, "BooleanOptionalAction"):
253-
# BooleanOptionalAction was added in Python 3.9
254-
BooleanOptionalAction = argparse.BooleanOptionalAction
255-
else:
256-
# backport of argparse.BooleanOptionalAction.
257-
class BooleanOptionalAction(argparse.Action):
258-
def __init__(
259-
self,
260-
option_strings,
261-
dest,
262-
default=None,
263-
type=None,
264-
choices=None,
265-
required=False,
266-
help=None,
267-
metavar=None,
268-
):
269-
_option_strings = []
270-
for option_string in option_strings:
271-
_option_strings.append(option_string)
272-
273-
if option_string.startswith("--"):
274-
option_string = "--no-" + option_string[2:]
275-
_option_strings.append(option_string)
276-
277-
if help is not None and default is not None:
278-
help += f" (default: {default})"
279-
280-
super().__init__(
281-
option_strings=_option_strings,
282-
dest=dest,
283-
nargs=0,
284-
default=default,
285-
type=type,
286-
choices=choices,
287-
required=required,
288-
help=help,
289-
metavar=metavar,
290-
)
291-
292-
def __call__(self, parser, namespace, values, option_string=None):
293-
if option_string in self.option_strings:
294-
setattr(namespace, self.dest, not option_string.startswith("--no-"))
295-
296-
def format_usage(self):
297-
return " | ".join(self.option_strings)
298-
299-
300251
# In Python 3.10, we can use types.NoneType
301252
NoneType = type(None)
302253

@@ -316,7 +267,7 @@ def parse_args(options_class: Type[OptionsType], args: ArgsType = None) -> Optio
316267

317268
def parse_known_args(
318269
options_class: Type[OptionsType], args: ArgsType = None
319-
) -> Tuple[OptionsType, List[str]]:
270+
) -> Tuple[OptionsType, list[str]]:
320271
"""Parse known arguments and return tuple containing dataclass type
321272
and list of remaining arguments.
322273
"""
@@ -424,7 +375,7 @@ def _add_dataclass_options(
424375
parser.add_argument(*args, **kwargs)
425376

426377

427-
def _get_kwargs(namespace: argparse.Namespace) -> Dict[str, Any]:
378+
def _get_kwargs(namespace: argparse.Namespace) -> dict[str, Any]:
428379
"""Converts a Namespace to a dictionary containing the items that
429380
to be used as keyword arguments to the Options class.
430381
"""
@@ -511,7 +462,7 @@ def parse_args(self, args: ArgsType = None, namespace=None) -> OptionsType:
511462

512463
def parse_known_args(
513464
self, args: ArgsType = None, namespace=None
514-
) -> Tuple[OptionsType, List[str]]:
465+
) -> Tuple[OptionsType, list[str]]:
515466
"""Parse known arguments and return tuple containing dataclass type
516467
and list of remaining arguments.
517468
"""

pyproject.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "argparse_dataclass"
33
version = "2.1.0"
4-
requires-python = ">=3.8"
4+
requires-python = ">=3.9"
55
description = "Declarative CLIs with argparse and dataclasses"
66
license = {file = "LICENSE"}
77
authors = [
@@ -12,7 +12,6 @@ classifiers = [
1212
"License :: OSI Approved :: MIT License",
1313
"Operating System :: OS Independent",
1414
"Programming Language :: Python :: 3",
15-
"Programming Language :: Python :: 3.8",
1615
"Programming Language :: Python :: 3.9",
1716
"Programming Language :: Python :: 3.10",
1817
"Programming Language :: Python :: 3.11",

tests/test_argumentparser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime as dt
44
from dataclasses import dataclass, field
55

6-
from typing import List, Optional, Union, Literal
6+
from typing import Optional, Union, Literal
77
from argparse_dataclass import ArgumentParser
88

99

@@ -76,7 +76,7 @@ def test_nargs(self):
7676
@dataclass
7777
class Args:
7878
name: str
79-
friends: List[str] = field(metadata=dict(nargs=2))
79+
friends: list[str] = field(metadata=dict(nargs=2))
8080

8181
args = ["--name", "Sam", "--friends", "pippin", "Frodo"]
8282
params = ArgumentParser(Args).parse_args(args)
@@ -87,7 +87,7 @@ def test_nargs_plus(self):
8787
@dataclass
8888
class Args:
8989
name: str
90-
friends: List[str] = field(metadata=dict(nargs="+"))
90+
friends: list[str] = field(metadata=dict(nargs="+"))
9191

9292
args = ["--name", "Sam", "--friends", "pippin", "Frodo"]
9393
params = ArgumentParser(Args).parse_args(args)

tests/test_functional.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime as dt
44
from dataclasses import dataclass, field
55

6-
from typing import List, Optional, Union
6+
from typing import Optional, Union
77

88
from argparse_dataclass import parse_args, parse_known_args
99

@@ -166,7 +166,7 @@ def test_nargs(self):
166166
@dataclass
167167
class Args:
168168
name: str
169-
friends: List[str] = field(metadata=dict(nargs=2))
169+
friends: list[str] = field(metadata=dict(nargs=2))
170170

171171
args = ["--name", "Sam", "--friends", "pippin", "Frodo"]
172172
params = parse_args(Args, args)
@@ -177,7 +177,7 @@ def test_nargs_plus(self):
177177
@dataclass
178178
class Args:
179179
name: str
180-
friends: List[str] = field(metadata=dict(nargs="+"))
180+
friends: list[str] = field(metadata=dict(nargs="+"))
181181

182182
args = ["--name", "Sam", "--friends", "pippin", "Frodo"]
183183
params = parse_args(Args, args)

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22

3-
envlist = py38, py39, py310, py311
3+
envlist = py39, py310, py311
44
# isolated_build = True
55

66
[testenv]

0 commit comments

Comments
 (0)