Skip to content

Commit 77b225a

Browse files
committed
patch: Drop support for Python 3.9
Undo the last of 8d15f4a. * Use a match case statement in place of an if block. * Replace Union types with X | Y syntax. Also introduce support for Python 3.14. Closes #16.
1 parent 5d7c9da commit 77b225a

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
22+
version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
2323
steps:
2424

2525
- name: Harden Runner

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[![pre-commit.ci Status](https://results.pre-commit.ci/badge/github/sandialabs/reverse_argparse/master.svg)](https://results.pre-commit.ci/latest/github/sandialabs/reverse_argparse/master)
1818
[![PyPI - Version](https://img.shields.io/pypi/v/reverse-argparse?label=PyPI)](https://pypi.org/project/reverse-argparse/)
1919
![PyPI - Downloads](https://img.shields.io/pypi/dm/reverse-argparse?label=PyPI%20downloads)
20-
![Python Version](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12|3.13-blue.svg)
20+
![Python Version](https://img.shields.io/badge/Python-3.10|3.11|3.12|3.13|3.14-blue.svg)
2121
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
2222

2323
# reverse_argparse

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ classifiers = [
2525
"Operating System :: OS Independent",
2626
"Programming Language :: Python :: 3",
2727
"Programming Language :: Python :: 3 :: Only",
28-
"Programming Language :: Python :: 3.9",
2928
"Programming Language :: Python :: 3.10",
3029
"Programming Language :: Python :: 3.11",
3130
"Programming Language :: Python :: 3.12",
3231
"Programming Language :: Python :: 3.13",
32+
"Programming Language :: Python :: 3.14",
3333
"Topic :: Software Development",
3434
"Topic :: Software Development :: Debuggers",
3535
"Topic :: Software Development :: Documentation",
@@ -44,7 +44,7 @@ Issues = "https://github.com/sandialabs/reverse_argparse/issues"
4444

4545

4646
[tool.poetry.dependencies]
47-
python = ">=3.8"
47+
python = ">=3.10"
4848

4949

5050
[tool.poetry.dev-dependencies]

reverse_argparse/reverse_argparse.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,37 @@ def _unparse_action(self, action: Action) -> None: # noqa: C901, PLR0912
114114
or self._arg_is_default_and_help_is_suppressed(action)
115115
):
116116
return
117-
if action_type == "_AppendAction":
118-
self._unparse_append_action(action)
119-
elif action_type == "_AppendConstAction":
120-
self._unparse_append_const_action(action)
121-
elif action_type == "_CountAction":
122-
self._unparse_count_action(action)
123-
elif action_type == "_ExtendAction":
124-
self._unparse_extend_action(action)
125-
elif action_type == "_HelpAction": # pragma: no cover
126-
return
127-
elif action_type == "_StoreAction":
128-
self._unparse_store_action(action)
129-
elif action_type == "_StoreConstAction":
130-
self._unparse_store_const_action(action)
131-
elif action_type == "_StoreFalseAction":
132-
self._unparse_store_false_action(action)
133-
elif action_type == "_StoreTrueAction":
134-
self._unparse_store_true_action(action)
135-
elif action_type == "_SubParsersAction":
136-
self._unparse_sub_parsers_action(action)
137-
elif action_type == "_VersionAction": # pragma: no cover
138-
return
139-
elif action_type == "BooleanOptionalAction":
140-
self._unparse_boolean_optional_action(action)
141-
else: # pragma: no cover
142-
message = (
143-
f"{self.__class__.__name__} does not yet support the "
144-
f"unparsing of {action_type} objects."
145-
)
146-
raise NotImplementedError(message)
117+
match action_type:
118+
case "_AppendAction":
119+
self._unparse_append_action(action)
120+
case "_AppendConstAction":
121+
self._unparse_append_const_action(action)
122+
case "_CountAction":
123+
self._unparse_count_action(action)
124+
case "_ExtendAction":
125+
self._unparse_extend_action(action)
126+
case "_HelpAction": # pragma: no cover
127+
return
128+
case "_StoreAction":
129+
self._unparse_store_action(action)
130+
case "_StoreConstAction":
131+
self._unparse_store_const_action(action)
132+
case "_StoreFalseAction":
133+
self._unparse_store_false_action(action)
134+
case "_StoreTrueAction":
135+
self._unparse_store_true_action(action)
136+
case "_SubParsersAction":
137+
self._unparse_sub_parsers_action(action)
138+
case "_VersionAction": # pragma: no cover
139+
return
140+
case "BooleanOptionalAction":
141+
self._unparse_boolean_optional_action(action)
142+
case _: # pragma: no cover
143+
message = (
144+
f"{self.__class__.__name__} does not yet support the "
145+
f"unparsing of {action_type} objects."
146+
)
147+
raise NotImplementedError(message)
147148

148149
def _arg_is_default_and_help_is_suppressed(self, action: Action) -> bool:
149150
"""

test/test_reverse_argparse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import shlex
1010
from argparse import SUPPRESS, ArgumentParser, BooleanOptionalAction, Namespace
11-
from typing import Any, Optional
11+
from typing import Any
1212

1313
import pytest
1414

@@ -435,7 +435,7 @@ def test__unparse_store_const_action(
435435
("args", "expected"), [(shlex.split("--foo"), " --foo"), ([], None)]
436436
)
437437
def test__unparse_store_true_action(
438-
args: list[str], expected: Optional[str]
438+
args: list[str], expected: str | None
439439
) -> None:
440440
"""Ensure ``store_true`` actions are handled appropriately."""
441441
parser = ArgumentParser()
@@ -450,7 +450,7 @@ def test__unparse_store_true_action(
450450
("args", "expected"), [(shlex.split("--foo"), " --foo"), ([], None)]
451451
)
452452
def test__unparse_store_false_action(
453-
args: list[str], expected: Optional[str]
453+
args: list[str], expected: str | None
454454
) -> None:
455455
"""Ensure ``store_false`` actions are handled appropriately."""
456456
parser = ArgumentParser()
@@ -497,7 +497,7 @@ def test__unparse_append_action(
497497
("args", "expected"), [("--foo", " --foo"), ("", None)]
498498
)
499499
def test__unparse_append_const_action(
500-
args: str, expected: Optional[str]
500+
args: str, expected: str | None
501501
) -> None:
502502
"""Ensure ``append_const`` actions are handled appropriately."""
503503
parser = ArgumentParser()
@@ -646,9 +646,9 @@ def test__unparse_extend_action() -> None:
646646
],
647647
)
648648
def test__unparse_boolean_optional_action(
649-
default: Optional[bool], # noqa: FBT001
649+
default: bool | None, # noqa: FBT001
650650
args: str,
651-
expected: Optional[str],
651+
expected: str | None,
652652
) -> None:
653653
"""Ensure ``BooleanOptionalAction`` actions are handled appropriately."""
654654
parser = ArgumentParser()

0 commit comments

Comments
 (0)