Skip to content

Commit a59c218

Browse files
committed
Use Optional[T] instead of T | None for old Python compatibility
1 parent 0a60ed4 commit a59c218

File tree

6 files changed

+36
-31
lines changed

6 files changed

+36
-31
lines changed

roboflow/adapters/rfapi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import urllib
4+
from typing import Optional
45

56
import requests
67
from requests_toolbelt.multipart.encoder import MultipartEncoder
@@ -43,8 +44,8 @@ def upload_image(
4344
split: str = "train",
4445
batch_name: str = DEFAULT_BATCH_NAME,
4546
tag_names: list = [],
46-
sequence_number: int | None = None,
47-
sequence_size: int | None = None,
47+
sequence_number: Optional[int] = None,
48+
sequence_size: Optional[int] = None,
4849
**kwargs,
4950
):
5051
"""

roboflow/core/project.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import time
66
import warnings
7+
from typing import Optional
78

89
import requests
910
from PIL import Image, UnidentifiedImageError
@@ -30,7 +31,7 @@ class Project:
3031
A Roboflow Project.
3132
"""
3233

33-
def __init__(self, api_key: str, a_project: dict, model_format: str | None = None):
34+
def __init__(self, api_key: str, a_project: dict, model_format: Optional[str] = None):
3435
"""
3536
Create a Project object that represents a Project associated with a Workspace.
3637
@@ -283,7 +284,7 @@ def train(
283284

284285
return new_model
285286

286-
def version(self, version_number: int, local: str | None = None):
287+
def version(self, version_number: int, local: Optional[str] = None):
287288
"""
288289
Retrieves information about a specific version and returns a Version() object.
289290
@@ -358,12 +359,12 @@ def check_valid_image(self, image_path: str):
358359
def upload(
359360
self,
360361
image_path: str,
361-
annotation_path: str | None = None,
362+
annotation_path: Optional[str] = None,
362363
hosted_image: bool = False,
363-
image_id: str | None = None,
364+
image_id: Optional[str] = None,
364365
split: str = "train",
365366
num_retry_uploads: int = 0,
366-
batch_name: str | None = None,
367+
batch_name: Optional[str] = None,
367368
tag_names: list = [],
368369
is_prediction: bool = False,
369370
**kwargs,
@@ -549,15 +550,15 @@ def _annotation_params(self, annotation_path):
549550

550551
def search(
551552
self,
552-
like_image: str | None = None,
553-
prompt: str | None = None,
553+
like_image: Optional[str] = None,
554+
prompt: Optional[str] = None,
554555
offset: int = 0,
555556
limit: int = 100,
556-
tag: str | None = None,
557-
class_name: str | None = None,
558-
in_dataset: str | None = None,
557+
tag: Optional[str] = None,
558+
class_name: Optional[str] = None,
559+
in_dataset: Optional[str] = None,
559560
batch: bool = False,
560-
batch_id: str | None = None,
561+
batch_id: Optional[str] = None,
561562
fields: list = ["id", "created", "name", "labels"],
562563
):
563564
"""
@@ -627,15 +628,15 @@ def search(
627628

628629
def search_all(
629630
self,
630-
like_image: str | None = None,
631-
prompt: str | None = None,
631+
like_image: Optional[str] = None,
632+
prompt: Optional[str] = None,
632633
offset: int = 0,
633634
limit: int = 100,
634-
tag: str | None = None,
635-
class_name: str | None = None,
636-
in_dataset: str | None = None,
635+
tag: Optional[str] = None,
636+
class_name: Optional[str] = None,
637+
in_dataset: Optional[str] = None,
637638
batch: bool = False,
638-
batch_id: str | None = None,
639+
batch_id: Optional[str] = None,
639640
fields: list = ["id", "created"],
640641
):
641642
"""

roboflow/models/classification.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import urllib
6+
from typing import Optional
67

78
import requests
89
from PIL import Image
@@ -23,11 +24,11 @@ def __init__(
2324
self,
2425
api_key: str,
2526
id: str,
26-
name: str | None = None,
27-
version: int | None = None,
27+
name: Optional[str] = None,
28+
version: Optional[int] = None,
2829
local: bool = False,
29-
colors: dict | None = None,
30-
preprocessing: dict | None = None,
30+
colors: Optional[dict] = None,
31+
preprocessing: Optional[dict] = None,
3132
):
3233
"""
3334
Create a ClassificationModel object through which you can run inference.

roboflow/models/inference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import time
55
import urllib
6-
from typing import List
6+
from typing import Optional
77
from urllib.parse import urljoin
88

99
import requests
@@ -140,7 +140,7 @@ def predict_video(
140140
fps: int = 5,
141141
additional_models: list = [],
142142
prediction_type: str = "batch-video",
143-
) -> tuple[str, str, str | None]:
143+
) -> tuple[str, str, Optional[str]]:
144144
"""
145145
Infers detections based on image from specified model and image path.
146146
@@ -280,7 +280,7 @@ def predict_video(
280280

281281
return job_id, signed_url, signed_url_expires
282282

283-
def poll_for_video_results(self, job_id: str | None = None) -> dict:
283+
def poll_for_video_results(self, job_id: Optional[str] = None) -> dict:
284284
"""
285285
Polls the Roboflow API to check if video inference is complete.
286286

roboflow/models/instance_segmentation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from roboflow.config import INSTANCE_SEGMENTATION_MODEL, INSTANCE_SEGMENTATION_URL
24
from roboflow.models.inference import InferenceModel
35

@@ -12,8 +14,8 @@ def __init__(
1214
self,
1315
api_key: str,
1416
version_id: str,
15-
colors: dict | None = None,
16-
preprocessing: dict | None = None,
17+
colors: Optional[dict] = None,
18+
preprocessing: Optional[dict] = None,
1719
local: bool = None,
1820
):
1921
"""

roboflow/models/video.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import time
3-
from typing import List
3+
from typing import Optional
44
from urllib.parse import urljoin
55

66
import magic
@@ -61,7 +61,7 @@ def predict(
6161
video_path: str,
6262
inference_type: str,
6363
fps: int = 5,
64-
additional_models: list | None = None,
64+
additional_models: Optional[list] = None,
6565
) -> tuple[str, str]:
6666
"""
6767
Infers detections based on image from specified model and image path.
@@ -141,7 +141,7 @@ def predict(
141141

142142
return job_id, signed_url
143143

144-
def poll_for_results(self, job_id: str | None = None) -> dict:
144+
def poll_for_results(self, job_id: Optional[str] = None) -> dict:
145145
"""
146146
Polls the Roboflow API to check if video inference is complete.
147147

0 commit comments

Comments
 (0)