Skip to content

Commit

Permalink
Probable fix for #535 - use union instead of | operator for python 3.…
Browse files Browse the repository at this point in the history
…9 compatibility (#540)

* use union instead of | operator for python 3.9 support

* fix import order to make ruff happy

---------

Co-authored-by: Bouni <bouni@owee.de>
  • Loading branch information
Cocoader and Bouni authored Sep 20, 2024
1 parent 088c804 commit 174107a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lcsc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io
from pathlib import Path
from typing import Union

import requests # pylint: disable=import-error

Expand Down Expand Up @@ -31,7 +32,7 @@ def get_part_data(self, lcsc_number: str) -> dict:
}
return {"success": True, "data": data}

def download_bitmap(self, url: str) -> io.BytesIO | None:
def download_bitmap(self, url: str) -> Union[io.BytesIO, None]:
"""Download a picture of the part from the API."""
content = requests.get(url, headers=self.headers, timeout=10).content
return io.BytesIO(content)
Expand Down
3 changes: 2 additions & 1 deletion store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
from pathlib import Path
import sqlite3
from typing import Union

from .helpers import (
dict_factory,
Expand Down Expand Up @@ -131,7 +132,7 @@ def get_part(self, ref: str) -> dict:
{"reference": ref},
).fetchone()

def set_stock(self, ref: str, stock: int | None):
def set_stock(self, ref: str, stock: Union[int, None]):
"""Set the stock value for a part in the database."""
with contextlib.closing(sqlite3.connect(self.dbfile)) as con, con as cur:
cur.execute(
Expand Down

0 comments on commit 174107a

Please sign in to comment.