Skip to content

Commit 721d32f

Browse files
committed
python: process some review comments
1 parent 6af971f commit 721d32f

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

python/cog/command/ast_openapi_schema.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,17 @@ def find(obj: ast.AST, name: str) -> ast.AST:
310310
return next(node for node in ast.walk(obj) if getattr(node, "name", "") == name)
311311

312312
if typing.TYPE_CHECKING:
313-
AstVal: "typing.TypeAlias" = int | float | complex | str | list["AstVal"] | bytes | None
314-
AstValNoBytes: "typing.TypeAlias" = int | float | str | list["AstValNoBytes"]
315-
JSONObject: "typing.TypeAlias" = int | float | str | list["JSONObject"] | "JSONDict" | None
316-
JSONDict: "typing.TypeAlias" = dict[str, "JSONObject"]
313+
AstVal: "typing.TypeAlias" = "int | float | complex | str | list[AstVal] | bytes | None"
314+
AstValNoBytes: "typing.TypeAlias" = "int | float | str | list[AstValNoBytes]"
315+
JSONObject: "typing.TypeAlias" = "int | float | str | list[JSONObject] | JSONDict | None"
316+
JSONDict: "typing.TypeAlias" = "dict[str, JSONObject]"
317317

318318

319-
def toSerializable(val: "AstVal") -> "JSONObject":
319+
def to_serializable(val: "AstVal") -> "JSONObject":
320320
if isinstance(val, bytes):
321321
return val.decode("utf-8")
322322
elif isinstance(val, list):
323-
return [toSerializable(x) for x in val]
323+
return [to_serializable(x) for x in val]
324324
elif isinstance(val, complex):
325325
msg = "complex inputs are not supported"
326326
raise ValueError(msg)
@@ -379,7 +379,7 @@ def parse_assignment(assignment: ast.AST) -> "None | tuple[str, JSONObject]":
379379
default = {}
380380
if assignment.value:
381381
try:
382-
default = {"default": toSerializable(get_value(assignment.value))}
382+
default = {"default": to_serializable(get_value(assignment.value))}
383383
except UnicodeDecodeError:
384384
pass
385385
return assignment.target.id, {
@@ -389,7 +389,7 @@ def parse_assignment(assignment: ast.AST) -> "None | tuple[str, JSONObject]":
389389
}
390390
if isinstance(assignment, ast.Assign):
391391
if len(assignment.targets) == 1 and isinstance(assignment.targets[0], ast.Name):
392-
value = toSerializable(get_value(assignment.value))
392+
value = to_serializable(get_value(assignment.value))
393393
return assignment.targets[0].id, {
394394
"title": assignment.targets[0].id.replace("_", " ").title(),
395395
"type": OPENAPI_TYPES[type(value).__name__],
@@ -508,9 +508,9 @@ def extract_info(code: str) -> "JSONDict":
508508
if kw.arg is None:
509509
msg = "unknown argument for Input"
510510
raise ValueError(msg)
511-
kws[kw.arg] = toSerializable(get_value(kw.value))
511+
kws[kw.arg] = to_serializable(get_value(kw.value))
512512
elif isinstance(default, (ast.Constant, ast.List, ast.Tuple, ast.Str, ast.Num)):
513-
kws = {"default": toSerializable(get_value(default))} # could be None
513+
kws = {"default": to_serializable(get_value(default))} # could be None
514514
elif default == ...: # no default
515515
kws = {}
516516
else:

python/cog/server/http.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,7 @@ def _signal_set_event(signum: Any, frame: Any) -> None:
380380
if config.get("build", {}).get("gpu", False):
381381
threads = 1
382382
else:
383-
threads = os.cpu_count()
384-
if threads is None:
385-
log.warn("Unable to determine cpu count, defaulting to 1 thread")
386-
threads = 1
383+
threads = max(1, len(os.sched_getaffinity(0)))
387384

388385
shutdown_event = threading.Event()
389386
app = create_app(

0 commit comments

Comments
 (0)