Skip to content

Commit

Permalink
BUG: fix an incoming incompatibility with argparse (address a depreca…
Browse files Browse the repository at this point in the history
…tion warning in CPython 3.14)
  • Loading branch information
neutrinoceros committed Dec 31, 2024
1 parent 5a430c4 commit 6b3b58b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

- BUG: fix an incoming incompatibility with argparse (address a deprecation
warning in CPython 3.14)

## [6.0.1] - 2024-12-15

- DEP: require inifix 5.1.0 or newer, fix newly detected type-checking errors
Expand Down
24 changes: 14 additions & 10 deletions src/idefix_cli/_commands/write.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""write an Idefix inifile from a json string"""

from __future__ import annotations

import argparse
import json
import sys
from contextlib import ExitStack
from io import TextIOBase
from pathlib import Path

import inifix
Expand All @@ -17,7 +16,6 @@ def add_arguments(parser) -> None:
parser.add_argument(
"source",
nargs="?",
type=argparse.FileType("r"),
default=sys.stdin,
help="json input",
)
Expand All @@ -29,12 +27,18 @@ def add_arguments(parser) -> None:
)


def command(dest: str, source, force: bool = False) -> int:
try:
data = json.load(source)
except json.decoder.JSONDecodeError:
print_error("input is not valid json.")
return 1
def command(dest: str, source: str | TextIOBase, force: bool = False) -> int:
with ExitStack() as stack:
if isinstance(source, TextIOBase):
stream = source
else:
stream = stack.enter_context(open(source))

try:
data = json.load(stream)
except json.decoder.JSONDecodeError:
print_error("input is not valid json.")
return 1

try:
inifix.validate_inifile_schema(data, sections="require")
Expand Down

0 comments on commit 6b3b58b

Please sign in to comment.