Skip to content

Commit

Permalink
uuid7 typing stub
Browse files Browse the repository at this point in the history
  • Loading branch information
katsujukou committed Nov 14, 2024
1 parent c8b5ff6 commit 1ce63b4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions backend/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
mypy_path = stubs
7 changes: 2 additions & 5 deletions backend/oqtopus_cloud/user/routers/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from sqlalchemy.orm import (
Session,
)

# from uuid_extensions import uuid7
from uuid_v7.base import uuid7
from uuid_extensions import uuid7
from zoneinfo import ZoneInfo

from oqtopus_cloud.common.models.device import Device
Expand Down Expand Up @@ -122,8 +120,7 @@ def submit_jobs(
description = validate_description(request)

job = Job(
# id=uuid7(as_type="str"),
id=str(uuid7()),
id=uuid7(as_type="str"),
owner=owner,
name=name,
description=description,
Expand Down
3 changes: 3 additions & 0 deletions backend/stubs/uuid_extensions/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__version__ = "0.1.0"

from .uuid7 import *
30 changes: 30 additions & 0 deletions backend/stubs/uuid_extensions/uuid7.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
__all__ = (
"uuid7",
"uuid7str",
"time_ns",
"check_timing_precision",
"uuid_to_datetime",
)

import datetime
import time
import uuid
from typing import Callable, Optional, Union

time_ns = time.time_ns

def uuid7(
ns: Optional[int] = None,
as_type: Optional[str] = None,
time_func: Callable[[], int] = time_ns,
_last=[0, 0, 0, 0],
_last_as_of=[0, 0, 0, 0],
) -> Union[uuid.UUID, str, int, bytes]: ...
def uuid7str(ns: Optional[int] = None) -> str: ...
def check_timing_precision(
timing_func: Optional[Callable[[], int]] = None,
) -> str: ...
def uuid_to_datetime(
s: Union[str, uuid.UUID, int],
suppress_error=True,
) -> Optional[datetime.datetime]: ...
6 changes: 5 additions & 1 deletion backend/tests/oqtopus_cloud/user/routers/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ def test_job_sortedness(test_db):
def mk_job(n: int) -> SubmitJobRequest:
return SubmitJobRequest(
name=f"test-job-{n}",
device_id="1",
device_id="Kawasaki",
status=JobStatus.submitted,
job_info=JobInfoSampling(job_type="sampling", code="code"),
simulator_info="{}",
transpiler_info="{}",
mitigation_info="{}",
shots=1000,
)

Expand All @@ -86,6 +89,7 @@ def is_sorted(xs: list[str]) -> bool:
job_ids: list[str] = []
for n in range(1, 10):
submit_resp = client.post("/jobs", content=mk_job(n).model_dump_json())
print(f"submit_resp={submit_resp.json()}")
job_id = SubmitJobResponse.model_validate(submit_resp.json()).job_id
job_ids.append(job_id)

Expand Down

0 comments on commit 1ce63b4

Please sign in to comment.