Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ dev = [
"yamlfix>=1.16.0",
"coverage[toml]>=5.5,<6.0.0",
"pytest>=7.4.0,<8.0.0",
"mypy==1.7.1",
"mypy==1.18.1",
"pre-commit",
"pyment>=0.3.3,<0.4.0",
"tox>=3.24.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ def get_model_server_info(
)

predictions_apis_urls = ""
if service_instance.prediction_apis_urls is not None: # type: ignore
if service_instance.prediction_apis_urls is not None:
predictions_apis_urls = ", ".join(
[
api
for api in service_instance.prediction_apis_urls # type: ignore
for api in service_instance.prediction_apis_urls
if api is not None
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def run(self) -> None:
wheel_package = self.entrypoint_args[WHEEL_PACKAGE_OPTION]

dist = distribution(wheel_package)
project_root = os.path.join(dist.locate_file("."), wheel_package)
project_root = os.path.join(
str(dist.locate_file(".")), str(wheel_package)
)

if project_root not in sys.path:
sys.path.insert(0, project_root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ def _reconstruct_nodes(
)
for job in job_list.items:
annotations = job.metadata.annotations or {}
if step_name := annotations.get(STEP_NAME_ANNOTATION_KEY, None):
node = nodes[step_name]
if step_name_annotation_key := annotations.get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of this is not a key, but a value. It's the value step_name, which is what the variable was (and should be) IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable step_name is already used at this point, which leads to:

src/zenml/integrations/kubernetes/orchestrators/kubernetes_orchestrator_entrypoint.py:161: error: Incompatible types in assignment (expression has type "Any | None", variable has type "str")

You are right though, it is not a key. I have changed it now to step_name_annotation, would it be ok for you?

STEP_NAME_ANNOTATION_KEY, None
):
node = nodes[str(step_name_annotation_key)]
node.metadata["job_name"] = job.metadata.name

if node.status == NodeStatus.NOT_READY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SeldonDeploymentConfig(ServiceConfig):
model_metadata: Dict[str, Any] = Field(default_factory=dict)
extra_args: Dict[str, Any] = Field(default_factory=dict)
is_custom_deployment: Optional[bool] = False
spec: Optional[Dict[Any, Any]] = Field(default_factory=dict) # type: ignore[arg-type]
spec: Optional[Dict[Any, Any]] = Field(default_factory=dict)
serviceAccountName: Optional[str] = None

def get_seldon_deployment_labels(self) -> Dict[str, str]:
Expand Down
4 changes: 2 additions & 2 deletions src/zenml/models/v2/base/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def _handle_numeric_comparison(self, column: Any) -> Any:
),
}

return operations[self.operation](numeric_column, self.value) # type: ignore[no-untyped-call]
return operations[self.operation](numeric_column, self.value)
except Exception as e:
raise ValueError(
f"Failed to compare the column '{column}' to the "
Expand Down Expand Up @@ -990,7 +990,7 @@ def apply_sorting(
column, operand = self.sorting_params

if operand == SorterOps.DESCENDING:
sort_clause = desc(getattr(table, column)) # type: ignore[var-annotated]
sort_clause = desc(getattr(table, column))
else:
sort_clause = asc(getattr(table, column))

Expand Down
4 changes: 2 additions & 2 deletions src/zenml/utils/function_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _cli_wrapped_function(func: F) -> F:
)
invalid_types = {}
for arg_name, arg_type, arg_default in input_args_dict:
if _is_valid_optional_arg(arg_type):
if arg_type is not None and _is_valid_optional_arg(arg_type):
arg_type = arg_type.__args__[0]
arg_name = _cli_arg_name(arg_name)
if arg_type is bool:
Expand All @@ -156,7 +156,7 @@ def _cli_wrapped_function(func: F) -> F:
required=False,
)
)
elif _is_valid_collection_arg(arg_type):
elif arg_type is not None and _is_valid_collection_arg(arg_type):
member_type = arg_type.__args__[0]
options.append(
click.option(
Expand Down
2 changes: 1 addition & 1 deletion src/zenml/utils/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def pydantic_encoder(obj: Any) -> Any:

if isinstance(obj, BaseModel):
return obj.model_dump(mode="json")
elif is_dataclass(obj):
elif is_dataclass(obj) and not isinstance(obj, type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this necessary? This seems like not just a linting adjustment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_dataclass returns True if obj is a dataclass itself or if it's an instance of a dataclass. However, the asdict in the next line only accepts instances and mypy raises:

src/zenml/utils/json_utils.py:118: error: Argument 1 to "asdict" has incompatible type "DataclassInstance | type[DataclassInstance]"; expected "DataclassInstance" [arg-type]

Even in python 3.11, providing a type would lead to an error, so I doubt this changes the functionality. WDYT?

return asdict(obj)

# Check the class type and its superclasses for a matching encoder
Expand Down
2 changes: 1 addition & 1 deletion src/zenml/utils/proxy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ def _inner_decorator(_cls: C) -> C:
if method_name not in interface.__abstractmethods__
)

return cast(C, _cls)
return cast(C, _cls) # type: ignore[redundant-cast]

return _inner_decorator
2 changes: 1 addition & 1 deletion src/zenml/utils/string_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def substitute_string(value: V, substitution_func: Callable[[str], str]) -> V:

model_values[k] = new_value

return cast(V, type(value).model_validate(model_values))
return cast(V, type(value).model_validate(model_values)) # type: ignore[redundant-cast]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming we can't get rid of the cast entirely because this doesn't work on all python versions?

Copy link
Contributor Author

@bcdurak bcdurak Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. If that would be the case, it would lead to an unused-ignore error on the other versions.

As for your question, I was a bit hesitant to remove the redundant casts. We used to do a few tricks with the way we handled pydantic objects and I thought removing the cast might mess up

elif isinstance(value, Dict):
return cast(
V, {substitute_(k): substitute_(v) for k, v in value.items()}
Expand Down
2 changes: 1 addition & 1 deletion src/zenml/utils/typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _generic_get_args(tp: Type[Any]) -> Tuple[Any, ...]:
# Special case for `tuple[()]`, which used to return ((),) with
# `typing.Tuple in python 3.10- but now returns () for `tuple` and `Tuple`.
try:
if tp == Tuple[()] or sys.version_info >= (3, 9) and tp == tuple[()]:
if tp == Tuple[()] or tp == tuple[()]: # type: ignore[comparison-overlap]
return ((),)
# there is a TypeError when compiled with cython
except TypeError: # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions src/zenml/zen_server/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def dispatch(
class RestrictFileUploadsMiddleware(BaseHTTPMiddleware):
"""Restrict file uploads to certain paths."""

def __init__(self, app: FastAPI, allowed_paths: Set[str]):
def __init__(self, app: ASGIApp, allowed_paths: Set[str]):
"""Restrict file uploads to certain paths.

Args:
Expand Down Expand Up @@ -404,7 +404,7 @@ def add_middlewares(app: FastAPI) -> None:

app.add_middleware(
CORSMiddleware,
allow_origins=server_config().cors_allow_origins,
allow_origins=server_config().cors_allow_origins or [],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
8 changes: 5 additions & 3 deletions src/zenml/zen_stores/sql_zen_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10718,7 +10718,7 @@ def _get_resource_references(
for resource_attr in resource_attrs:
# Extract the target schema from the annotation
annotation = UserSchema.__annotations__[resource_attr]
if get_origin(annotation) == Mapped:
if get_origin(annotation) == Mapped: # type: ignore[comparison-overlap]
annotation = annotation.__args__[0]

# The annotation must be of the form
Expand All @@ -10736,8 +10736,10 @@ def _get_resource_references(
vars(zenml_schemas), {}, recursive_guard=frozenset()
)
else:
target_schema = schema_ref._evaluate(
vars(zenml_schemas), {}, frozenset()
target_schema = schema_ref._evaluate( # type: ignore[unused-ignore, call-arg, call-overload]
vars(zenml_schemas),
{},
frozenset(), # type: ignore[unused-ignore, arg-type]
)
assert target_schema is not None
assert issubclass(target_schema, SQLModel)
Expand Down
4 changes: 2 additions & 2 deletions src/zenml/zen_stores/template_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def generate_config_schema(
]:
continue

if field_info.annotation == Optional[SourceWithValidator]:
if field_info.annotation == Optional[SourceWithValidator]: # type: ignore[comparison-overlap]
generic_step_fields[key] = (Optional[str], field_info)
else:
generic_step_fields[key] = (field_info.annotation, field_info)
Expand Down Expand Up @@ -279,7 +279,7 @@ def generate_config_schema(
if key in ["schedule", "build", "steps", "settings", "parameters"]:
continue

if field_info.annotation == Optional[SourceWithValidator]:
if field_info.annotation == Optional[SourceWithValidator]: # type: ignore[comparison-overlap]
top_level_fields[key] = (Optional[str], field_info)
else:
top_level_fields[key] = (field_info.annotation, field_info)
Expand Down
Loading