diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 9c4b28e..450c9aa 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -12,11 +12,11 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8, 3.9, pypy-3.8, pypy-3.9, pypy-3.10, '3.10', '3.11' , '3.12.0'] + python-version: [pypy-3.10, '3.10', '3.11' , '3.12', '3.13'] os: [ ubuntu-latest, windows-latest, - macos-13, + macos-latest, ] steps: @@ -25,6 +25,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + allow-prereleases: true - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/json2xml/__init__.py b/json2xml/__init__.py index c201b91..4d4eb35 100644 --- a/json2xml/__init__.py +++ b/json2xml/__init__.py @@ -2,4 +2,4 @@ __author__ = """Vinit Kumar""" __email__ = "mail@vinitkumar.me" -__version__ = "4.1.0" +__version__ = "5.0.0" diff --git a/json2xml/dicttoxml.py b/json2xml/dicttoxml.py index 6062cb1..cb529c9 100644 --- a/json2xml/dicttoxml.py +++ b/json2xml/dicttoxml.py @@ -59,11 +59,11 @@ def get_unique_id(element: str) -> str: float, bool, numbers.Number, - Sequence, + Sequence[str], datetime.datetime, datetime.date, None, - Dict[str, Any], + dict[str, Any], ] diff --git a/json2xml/json2xml.py b/json2xml/json2xml.py index 002e5f6..dd996c4 100644 --- a/json2xml/json2xml.py +++ b/json2xml/json2xml.py @@ -14,7 +14,7 @@ class Json2xml: """ def __init__( self, - data: Optional[Dict[str, Any]] = None, + data: dict[str, Any] | None = None, wrapper: str = "all", root: bool = True, pretty: bool = True, @@ -28,7 +28,7 @@ def __init__( self.root = root self.item_wrap = item_wrap - def to_xml(self) -> Optional[Any]: + def to_xml(self) -> Any | None: """ Convert to xml using dicttoxml.dicttoxml and then pretty print it. """ diff --git a/json2xml/utils.py b/json2xml/utils.py index 5880aaa..bbcf43e 100644 --- a/json2xml/utils.py +++ b/json2xml/utils.py @@ -25,7 +25,7 @@ class StringReadError(Exception): pass -def readfromjson(filename: str) -> Dict[str, str]: +def readfromjson(filename: str) -> dict[str, str]: """Reads a JSON file and returns a dictionary.""" try: with open(filename, encoding="utf-8") as jsondata: @@ -36,7 +36,7 @@ def readfromjson(filename: str) -> Dict[str, str]: raise JSONReadError("Invalid JSON File") -def readfromurl(url: str, params: Optional[Dict[str, str]] = None) -> Dict[str, str]: +def readfromurl(url: str, params: dict[str, str] | None = None) -> dict[str, str]: """Loads JSON data from a URL and returns a dictionary.""" http = urllib3.PoolManager() response = http.request("GET", url, fields=params) @@ -45,7 +45,7 @@ def readfromurl(url: str, params: Optional[Dict[str, str]] = None) -> Dict[str, raise URLReadError("URL is not returning correct response") -def readfromstring(jsondata: str) -> Dict[str, str]: +def readfromstring(jsondata: str) -> dict[str, str]: """Loads JSON data from a string and returns a dictionary.""" if not isinstance(jsondata, str): raise StringReadError("Input is not a proper JSON string") diff --git a/tests/test_json2xml.py b/tests/test_json2xml.py index d4bc3e4..c3a81f9 100644 --- a/tests/test_json2xml.py +++ b/tests/test_json2xml.py @@ -50,15 +50,6 @@ def test_read_from_invalid_json2(self): readfromjson("examples/wrongjson.json") assert pytest_wrapped_e.type == JSONReadError - def test_read_from_url(self): - data = readfromurl("https://api.publicapis.org/entries") - assert isinstance(data, dict) - - def test_read_from_wrong_url(self): - with pytest.raises(URLReadError) as pytest_wrapped_e: - readfromurl("https://api.publicapis.org/entriesi") - assert pytest_wrapped_e.type == URLReadError - def test_read_from_jsonstring(self): data = readfromstring( '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'