Skip to content

Commit c570d22

Browse files
authored
Merge pull request #385 from roboflow/codex/fix-mutable-default-argument-issue
Fix mutable default arguments
2 parents dd2ccdf + 6ad60ed commit c570d22

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

roboflow/adapters/rfapi.py

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

66
import requests
77
from requests.exceptions import RequestException
@@ -56,7 +56,7 @@ def upload_image(
5656
hosted_image: bool = False,
5757
split: str = "train",
5858
batch_name: str = DEFAULT_BATCH_NAME,
59-
tag_names: list = [],
59+
tag_names: Optional[List[str]] = None,
6060
sequence_number: Optional[int] = None,
6161
sequence_size: Optional[int] = None,
6262
**kwargs,
@@ -71,6 +71,8 @@ def upload_image(
7171
"""
7272

7373
coalesced_batch_name = batch_name or DEFAULT_BATCH_NAME
74+
if tag_names is None:
75+
tag_names = []
7476

7577
# If image is not a hosted image
7678
if not hosted_image:

roboflow/core/project.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,7 @@ def generate_version(self, settings):
256256

257257
def train(
258258
self,
259-
new_version_settings={
260-
"preprocessing": {
261-
"auto-orient": True,
262-
"resize": {"width": 640, "height": 640, "format": "Stretch to"},
263-
},
264-
"augmentation": {},
265-
},
259+
new_version_settings: Optional[Dict] = None,
266260
speed=None,
267261
checkpoint=None,
268262
plot_in_notebook=False,
@@ -294,6 +288,15 @@ def train(
294288
>>> version.train()
295289
""" # noqa: E501 // docs
296290

291+
if new_version_settings is None:
292+
new_version_settings = {
293+
"preprocessing": {
294+
"auto-orient": True,
295+
"resize": {"width": 640, "height": 640, "format": "Stretch to"},
296+
},
297+
"augmentation": {},
298+
}
299+
297300
new_version = self.generate_version(settings=new_version_settings)
298301
new_version = self.version(new_version)
299302
new_model = new_version.train(speed=speed, checkpoint=checkpoint, plot_in_notebook=plot_in_notebook)
@@ -384,7 +387,7 @@ def upload(
384387
split: str = "train",
385388
num_retry_uploads: int = 0,
386389
batch_name: Optional[str] = None,
387-
tag_names: list = [],
390+
tag_names: Optional[List[str]] = None,
388391
is_prediction: bool = False,
389392
**kwargs,
390393
):
@@ -413,6 +416,9 @@ def upload(
413416
>>> project.upload(image_path="YOUR_IMAGE.jpg")
414417
""" # noqa: E501 // docs
415418

419+
if tag_names is None:
420+
tag_names = []
421+
416422
is_hosted = image_path.startswith("http://") or image_path.startswith("https://")
417423

418424
is_file = os.path.isfile(image_path) or is_hosted
@@ -476,13 +482,16 @@ def upload_image(
476482
split="train",
477483
num_retry_uploads=0,
478484
batch_name=None,
479-
tag_names=[],
485+
tag_names: Optional[List[str]] = None,
480486
sequence_number=None,
481487
sequence_size=None,
482488
**kwargs,
483489
):
484490
project_url = self.id.rsplit("/")[1]
485491

492+
if tag_names is None:
493+
tag_names = []
494+
486495
t0 = time.time()
487496
upload_retry_attempts = 0
488497
retry = Retry(num_retry_uploads, ImageUploadError)
@@ -557,13 +566,15 @@ def single_upload(
557566
split="train",
558567
num_retry_uploads=0,
559568
batch_name=None,
560-
tag_names=[],
569+
tag_names: Optional[List[str]] = None,
561570
is_prediction: bool = False,
562571
annotation_overwrite=False,
563572
sequence_number=None,
564573
sequence_size=None,
565574
**kwargs,
566575
):
576+
if tag_names is None:
577+
tag_names = []
567578
if image_path and image_id:
568579
raise Exception("You can't pass both image_id and image_path")
569580
if not (image_path or image_id):
@@ -641,7 +652,7 @@ def search(
641652
in_dataset: Optional[str] = None,
642653
batch: bool = False,
643654
batch_id: Optional[str] = None,
644-
fields: list = ["id", "created", "name", "labels"],
655+
fields: Optional[List[str]] = None,
645656
):
646657
"""
647658
Search for images in a project.
@@ -670,6 +681,9 @@ def search(
670681
671682
>>> results = project.search(query="cat", limit=10)
672683
""" # noqa: E501 // docs
684+
if fields is None:
685+
fields = ["id", "created", "name", "labels"]
686+
673687
payload: Dict[str, Union[str, int, List[str]]] = {}
674688

675689
if like_image is not None:
@@ -719,7 +733,7 @@ def search_all(
719733
in_dataset: Optional[str] = None,
720734
batch: bool = False,
721735
batch_id: Optional[str] = None,
722-
fields: list = ["id", "created"],
736+
fields: Optional[List[str]] = None,
723737
):
724738
"""
725739
Create a paginated list of search results for use in searching the images in a project.
@@ -752,6 +766,9 @@ def search_all(
752766
753767
>>> print(result)
754768
""" # noqa: E501 // docs
769+
if fields is None:
770+
fields = ["id", "created"]
771+
755772
while True:
756773
data = self.search(
757774
like_image=like_image,

roboflow/core/workspace.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
import os
77
import sys
8-
from typing import Any, List
8+
from typing import Any, Dict, List, Optional
99

1010
import requests
1111
from PIL import Image
@@ -433,9 +433,9 @@ def active_learning(
433433
self,
434434
raw_data_location: str = "",
435435
raw_data_extension: str = "",
436-
inference_endpoint: list = [],
436+
inference_endpoint: Optional[List[str]] = None,
437437
upload_destination: str = "",
438-
conditionals: dict = {},
438+
conditionals: Optional[Dict] = None,
439439
use_localhost: bool = False,
440440
local_server="http://localhost:9001/",
441441
) -> Any:
@@ -449,6 +449,11 @@ def active_learning(
449449
use_localhost: (bool) = determines if local http format used or remote endpoint
450450
local_server: (str) = local http address for inference server, use_localhost must be True for this to be used
451451
""" # noqa: E501 // docs
452+
if inference_endpoint is None:
453+
inference_endpoint = []
454+
if conditionals is None:
455+
conditionals = {}
456+
452457
import numpy as np
453458

454459
prediction_results = []

roboflow/models/inference.py

Lines changed: 5 additions & 2 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 Optional, Tuple
6+
from typing import List, Optional, Tuple
77
from urllib.parse import urljoin
88

99
import requests
@@ -137,7 +137,7 @@ def predict_video(
137137
self,
138138
video_path: str,
139139
fps: int = 5,
140-
additional_models: list = [],
140+
additional_models: Optional[List[str]] = None,
141141
prediction_type: str = "batch-video",
142142
) -> Tuple[str, str, Optional[str]]:
143143
"""
@@ -170,6 +170,9 @@ def predict_video(
170170
if fps > 120:
171171
raise Exception("FPS must be less than or equal to 120.")
172172

173+
if additional_models is None:
174+
additional_models = []
175+
173176
for model in additional_models:
174177
if model not in SUPPORTED_ADDITIONAL_MODELS:
175178
raise Exception(f"Model {model} is not supported for video inference.")

0 commit comments

Comments
 (0)