Skip to content

Commit

Permalink
Add Python 3.13 support (#201)
Browse files Browse the repository at this point in the history
* feat:try python3.13

* fix: mypy errors

* fix: trigger python3.11 release

* fix:broken test due to broken endpoint

* fix: make code modern

* fix: latest build

* fix: bye bye py 3.9 👋🏻

* fix: new major release

* fix: add python3.12
  • Loading branch information
vinitkumar authored May 10, 2024
1 parent 0531aff commit 28ffcff
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion json2xml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Vinit Kumar"""
__email__ = "mail@vinitkumar.me"
__version__ = "4.1.0"
__version__ = "5.0.0"
4 changes: 2 additions & 2 deletions json2xml/dicttoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]


Expand Down
4 changes: 2 additions & 2 deletions json2xml/json2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
"""
Expand Down
6 changes: 3 additions & 3 deletions json2xml/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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")
Expand Down
9 changes: 0 additions & 9 deletions tests/test_json2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}'
Expand Down

0 comments on commit 28ffcff

Please sign in to comment.