Skip to content

Commit 1c4f155

Browse files
committed
Replace pipe operator to Union, to support py3.9
Bump deps Signed-off-by: andrew000 <11490628+andrew000@users.noreply.github.com>
1 parent e1a6fc7 commit 1c4f155

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: "check-json"
2222

2323
- repo: https://github.com/charliermarsh/ruff-pre-commit
24-
rev: v0.7.3
24+
rev: v0.8.2
2525
hooks:
2626
- id: ruff
2727
args: [ "--fix" ]

oqs/oqs.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import time
2121
import warnings
2222
from pathlib import Path
23-
from typing import TYPE_CHECKING, Any, ClassVar, Final, TypeVar, cast
23+
from typing import TYPE_CHECKING, Any, ClassVar, Final, TypeVar, Union, cast
2424

2525
if TYPE_CHECKING:
2626
from collections.abc import Sequence
@@ -32,7 +32,7 @@
3232
logger = logging.getLogger(__name__)
3333

3434

35-
def oqs_python_version() -> str | None:
35+
def oqs_python_version() -> Union[str, None]:
3636
"""liboqs-python version string."""
3737
try:
3838
result = importlib.metadata.version("liboqs-python")
@@ -57,7 +57,7 @@ def _countdown(seconds: int) -> None:
5757

5858
def _load_shared_obj(
5959
name: str,
60-
additional_searching_paths: Sequence[Path] | None = None,
60+
additional_searching_paths: Union[Sequence[Path], None] = None,
6161
) -> ct.CDLL:
6262
"""Attempt to load shared library."""
6363
paths: list[Path] = []
@@ -99,7 +99,10 @@ def _load_shared_obj(
9999
raise RuntimeError(msg)
100100

101101

102-
def _install_liboqs(target_directory: Path, oqs_version_to_install: str | None = None) -> None:
102+
def _install_liboqs(
103+
target_directory: Path,
104+
oqs_version_to_install: Union[str, None] = None,
105+
) -> None:
103106
"""Install liboqs version oqs_version (if None, installs latest at HEAD) in the target_directory.""" # noqa: E501
104107
with tempfile.TemporaryDirectory() as tmpdirname:
105108
oqs_install_cmd = [
@@ -265,7 +268,7 @@ class KeyEncapsulation(ct.Structure):
265268
("decaps_cb", ct.c_void_p),
266269
]
267270

268-
def __init__(self, alg_name: str, secret_key: int | bytes | None = None) -> None:
271+
def __init__(self, alg_name: str, secret_key: Union[int, bytes, None] = None) -> None:
269272
"""
270273
Create new KeyEncapsulation with the given algorithm.
271274
@@ -305,13 +308,13 @@ def __enter__(self: TKeyEncapsulation) -> TKeyEncapsulation:
305308

306309
def __exit__(
307310
self,
308-
ctx_type: type[BaseException] | None,
309-
ctx_value: BaseException | None,
310-
ctx_traceback: TracebackType | None,
311+
ctx_type: Union[type[BaseException], None],
312+
ctx_value: Union[BaseException, None],
313+
ctx_traceback: Union[TracebackType, None],
311314
) -> None:
312315
self.free()
313316

314-
def generate_keypair(self) -> bytes | int:
317+
def generate_keypair(self) -> Union[bytes, int]:
315318
"""
316319
Generate a new keypair and returns the public key.
317320
@@ -330,7 +333,7 @@ def export_secret_key(self) -> bytes:
330333
"""Export the secret key."""
331334
return bytes(self.secret_key)
332335

333-
def encap_secret(self, public_key: int | bytes) -> tuple[bytes, bytes | int]:
336+
def encap_secret(self, public_key: Union[int, bytes]) -> tuple[bytes, Union[bytes, int]]:
334337
"""
335338
Generate and encapsulates a secret using the provided public key.
336339
@@ -354,15 +357,15 @@ def encap_secret(self, public_key: int | bytes) -> tuple[bytes, bytes | int]:
354357
)
355358

356359
# TODO: What should it return?
357-
# 1. tuple[bytes | int, bytes | int]
358-
# 2. tuple[bytes, bytes | int]
359-
# 3. tuple[bytes, bytes] | int
360+
# 1. tuple[Union[bytes, int], Union[bytes, int]]
361+
# 2. tuple[bytes, Union[bytes, int]]
362+
# 3. Union[tuple[bytes, bytes], int]
360363
return (
361364
bytes(cast(bytes, ciphertext)),
362365
bytes(cast(bytes, shared_secret)) if rv == OQS_SUCCESS else 0,
363366
)
364367

365-
def decap_secret(self, ciphertext: int | bytes) -> bytes | int:
368+
def decap_secret(self, ciphertext: Union[int, bytes]) -> Union[bytes, int]:
366369
"""
367370
Decapsulate the ciphertext and returns the secret.
368371
@@ -451,7 +454,7 @@ class Signature(ct.Structure):
451454
("verify_cb", ct.c_void_p),
452455
]
453456

454-
def __init__(self, alg_name: str, secret_key: int | bytes | None = None) -> None:
457+
def __init__(self, alg_name: str, secret_key: Union[int, bytes, None] = None) -> None:
455458
"""
456459
Create new Signature with the given algorithm.
457460
@@ -488,13 +491,13 @@ def __enter__(self: TSignature) -> TSignature:
488491

489492
def __exit__(
490493
self,
491-
ctx_type: type[BaseException] | None,
492-
ctx_value: BaseException | None,
493-
ctx_traceback: TracebackType | None,
494+
ctx_type: Union[type[BaseException], None],
495+
ctx_value: Union[BaseException, None],
496+
ctx_traceback: Union[TracebackType, None],
494497
) -> None:
495498
self.free()
496499

497-
def generate_keypair(self) -> bytes | int:
500+
def generate_keypair(self) -> Union[bytes, int]:
498501
"""
499502
Generate a new keypair and returns the public key.
500503
@@ -515,7 +518,7 @@ def export_secret_key(self) -> bytes:
515518
"""Export the secret key."""
516519
return bytes(self.secret_key)
517520

518-
def sign(self, message: bytes) -> bytes | int:
521+
def sign(self, message: bytes) -> Union[bytes, int]:
519522
"""
520523
Signs the provided message and returns the signature.
521524

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ package = true
1717
dev = [
1818
"isort==5.13.2",
1919
"pre-commit==4.0.1",
20-
"ruff==0.7.3",
21-
"bandit==1.7.10",
20+
"ruff==0.8.2",
21+
"bandit==1.8.0",
2222
"nose2==0.15.1",
2323
]
2424
lint = [
@@ -81,7 +81,8 @@ ignore = [
8181
"PLR0911", "PLR0912", "PLR0913", "PLR0915", "PLR5501",
8282
"PLW0120",
8383
"RUF001",
84-
"TD002", "TD003"
84+
"TD002", "TD003",
85+
"U007",
8586
]
8687

8788
[tool.ruff.format]

0 commit comments

Comments
 (0)