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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions scripts/pyupgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# install helper packages

uv pip install pyupgrade
uv pip install autoflake

# run py-upgrade recursively to all nested .py files

find src -name '*.py' -print0 | xargs -0 -n1 python -m pyupgrade --py310-plus
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can also run it on the tests and examples directories (or any other python files in the repo)?


# run autoflake to remove dangling imports

autoflake --remove-all-unused-imports --in-place --recursive src

# run ruff check to verify imports are fixed

ruff check core --select F401
28 changes: 11 additions & 17 deletions src/zenml/actions/base_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Base implementation of actions."""

from abc import ABC, abstractmethod
from typing import Any, ClassVar, Dict, Optional, Type
from typing import Any, ClassVar

from zenml.enums import PluginType
from zenml.event_hub.base_event_hub import BaseEventHub
Expand Down Expand Up @@ -56,10 +56,10 @@ class BaseActionFlavor(BasePluginFlavor, ABC):
TYPE: ClassVar[PluginType] = PluginType.ACTION

# Action specific
ACTION_CONFIG_CLASS: ClassVar[Type[ActionConfig]]
ACTION_CONFIG_CLASS: ClassVar[type[ActionConfig]]

@classmethod
def get_action_config_schema(cls) -> Dict[str, Any]:
def get_action_config_schema(cls) -> dict[str, Any]:
"""The config schema for a flavor.

Returns:
Expand Down Expand Up @@ -97,9 +97,9 @@ def get_flavor_response_model(cls, hydrate: bool) -> ActionFlavorResponse:
class BaseActionHandler(BasePlugin, ABC):
"""Implementation for an action handler."""

_event_hub: Optional[BaseEventHub] = None
_event_hub: BaseEventHub | None = None

def __init__(self, event_hub: Optional[BaseEventHub] = None) -> None:
def __init__(self, event_hub: BaseEventHub | None = None) -> None:
"""Event source handler initialization.

Args:
Expand All @@ -122,7 +122,7 @@ def __init__(self, event_hub: Optional[BaseEventHub] = None) -> None:

@property
@abstractmethod
def config_class(self) -> Type[ActionConfig]:
def config_class(self) -> type[ActionConfig]:
"""Returns the `BasePluginConfig` config.

Returns:
Expand All @@ -131,7 +131,7 @@ def config_class(self) -> Type[ActionConfig]:

@property
@abstractmethod
def flavor_class(self) -> Type[BaseActionFlavor]:
def flavor_class(self) -> type[BaseActionFlavor]:
"""Returns the flavor class of the plugin.

Returns:
Expand Down Expand Up @@ -173,7 +173,7 @@ def set_event_hub(self, event_hub: BaseEventHub) -> None:

def event_hub_callback(
self,
config: Dict[str, Any],
config: dict[str, Any],
trigger_execution: TriggerExecutionResponse,
auth_context: AuthContext,
) -> None:
Expand Down Expand Up @@ -442,7 +442,7 @@ def get_action(
return action

def validate_action_configuration(
self, action_config: Dict[str, Any]
self, action_config: dict[str, Any]
) -> ActionConfig:
"""Validate and return the action configuration.

Expand All @@ -464,7 +464,7 @@ def extract_resources(
self,
action_config: ActionConfig,
hydrate: bool = False,
) -> Dict[ResourceType, BaseResponse[Any, Any, Any]]:
) -> dict[ResourceType, BaseResponse[Any, Any, Any]]:
"""Extract related resources for this action.

Args:
Expand Down Expand Up @@ -504,7 +504,6 @@ def _validate_action_request(
action: Action request.
config: Action configuration instantiated from the request.
"""
pass

def _process_action_request(
self, action: ActionResponse, config: ActionConfig
Expand All @@ -529,7 +528,6 @@ def _process_action_request(
action: Newly created action
config: Action configuration instantiated from the response.
"""
pass

def _validate_action_update(
self,
Expand Down Expand Up @@ -566,7 +564,6 @@ def _validate_action_update(
config_update: Action configuration instantiated from the
updated action.
"""
pass

def _process_action_update(
self,
Expand Down Expand Up @@ -599,13 +596,12 @@ def _process_action_update(
previous_config: Action configuration instantiated from the
original action.
"""
pass

def _process_action_delete(
self,
action: ActionResponse,
config: ActionConfig,
force: Optional[bool] = False,
force: bool | None = False,
) -> None:
"""Process an action before it is deleted from the database.

Expand All @@ -625,7 +621,6 @@ def _process_action_delete(
config: Action configuration before the deletion.
force: Whether to force deprovision the action.
"""
pass

def _process_action_response(
self, action: ActionResponse, config: ActionConfig
Expand All @@ -650,7 +645,6 @@ def _process_action_response(
action: Action response.
config: Action configuration instantiated from the response.
"""
pass

def _populate_action_response_resources(
self,
Expand Down
16 changes: 8 additions & 8 deletions src/zenml/actions/pipeline_run/pipeline_run_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# permissions and limitations under the License.
"""Example file of what an action Plugin could look like."""

from typing import Any, ClassVar, Dict, Optional, Type
from typing import Any, ClassVar
from uuid import UUID

from zenml.actions.base_action import (
Expand Down Expand Up @@ -47,7 +47,7 @@ class PipelineRunActionConfiguration(ActionConfig):
"""Configuration class to configure a pipeline run action."""

snapshot_id: UUID
run_config: Optional[PipelineRunConfiguration] = None
run_config: PipelineRunConfiguration | None = None


# -------------------- Pipeline Run Plugin -----------------------------------
Expand All @@ -57,7 +57,7 @@ class PipelineRunActionHandler(BaseActionHandler):
"""Action handler for running pipelines."""

@property
def config_class(self) -> Type[PipelineRunActionConfiguration]:
def config_class(self) -> type[PipelineRunActionConfiguration]:
"""Returns the `BasePluginConfig` config.

Returns:
Expand All @@ -66,7 +66,7 @@ def config_class(self) -> Type[PipelineRunActionConfiguration]:
return PipelineRunActionConfiguration

@property
def flavor_class(self) -> Type[BaseActionFlavor]:
def flavor_class(self) -> type[BaseActionFlavor]:
"""Returns the flavor class of the plugin.

Returns:
Expand Down Expand Up @@ -169,7 +169,7 @@ def extract_resources(
self,
action_config: ActionConfig,
hydrate: bool = False,
) -> Dict[ResourceType, BaseResponse[Any, Any, Any]]:
) -> dict[ResourceType, BaseResponse[Any, Any, Any]]:
"""Extract related resources for this action.

Args:
Expand All @@ -196,7 +196,7 @@ def extract_resources(
f"No snapshot found with id {action_config.snapshot_id}."
)

resources: Dict[ResourceType, BaseResponse[Any, Any, Any]] = {
resources: dict[ResourceType, BaseResponse[Any, Any, Any]] = {
ResourceType.PIPELINE_SNAPSHOT: snapshot
}

Expand All @@ -217,11 +217,11 @@ class PipelineRunActionFlavor(BaseActionFlavor):

FLAVOR: ClassVar[str] = "builtin"
SUBTYPE: ClassVar[PluginSubType] = PluginSubType.PIPELINE_RUN
PLUGIN_CLASS: ClassVar[Type[PipelineRunActionHandler]] = (
PLUGIN_CLASS: ClassVar[type[PipelineRunActionHandler]] = (
PipelineRunActionHandler
)

# EventPlugin specific
ACTION_CONFIG_CLASS: ClassVar[Type[PipelineRunActionConfiguration]] = (
ACTION_CONFIG_CLASS: ClassVar[type[PipelineRunActionConfiguration]] = (
PipelineRunActionConfiguration
)
10 changes: 5 additions & 5 deletions src/zenml/alerter/base_alerter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Base class for all ZenML alerters."""

from abc import ABC
from typing import Optional, Type, cast
from typing import cast

from pydantic import BaseModel

Expand Down Expand Up @@ -44,7 +44,7 @@ def config(self) -> BaseAlerterConfig:
return cast(BaseAlerterConfig, self._config)

def post(
self, message: str, params: Optional[BaseAlerterStepParameters] = None
self, message: str, params: BaseAlerterStepParameters | None = None
) -> bool:
"""Post a message to a chat service.

Expand All @@ -58,7 +58,7 @@ def post(
return True

def ask(
self, question: str, params: Optional[BaseAlerterStepParameters] = None
self, question: str, params: BaseAlerterStepParameters | None = None
) -> bool:
"""Post a message to a chat service and wait for approval.

Expand Down Expand Up @@ -88,7 +88,7 @@ def type(self) -> StackComponentType:
return StackComponentType.ALERTER

@property
def config_class(self) -> Type[BaseAlerterConfig]:
def config_class(self) -> type[BaseAlerterConfig]:
"""Returns BaseAlerterConfig class.

Returns:
Expand All @@ -97,7 +97,7 @@ def config_class(self) -> Type[BaseAlerterConfig]:
return BaseAlerterConfig

@property
def implementation_class(self) -> Type[BaseAlerter]:
def implementation_class(self) -> type[BaseAlerter]:
"""Implementation class.

Returns:
Expand Down
8 changes: 4 additions & 4 deletions src/zenml/analytics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# permissions and limitations under the License.
"""The 'analytics' module of ZenML."""
from contextvars import ContextVar
from typing import Any, Dict, Optional, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
from uuid import UUID

from zenml.enums import SourceContextTypes
Expand All @@ -27,7 +27,7 @@


def identify( # type: ignore[return]
metadata: Optional[Dict[str, Any]] = None
metadata: dict[str, Any] | None = None
) -> bool:
"""Attach metadata to user directly.

Expand Down Expand Up @@ -64,7 +64,7 @@ def alias(user_id: UUID, previous_id: UUID) -> bool: # type: ignore[return]

def group( # type: ignore[return]
group_id: UUID,
group_metadata: Optional[Dict[str, Any]] = None,
group_metadata: dict[str, Any] | None = None,
) -> bool:
"""Attach metadata to a segment group.

Expand All @@ -83,7 +83,7 @@ def group( # type: ignore[return]

def track( # type: ignore[return]
event: "AnalyticsEvent",
metadata: Optional[Dict[str, Any]] = None,
metadata: dict[str, Any] | None = None,
) -> bool:
"""Track segment event if user opted-in.

Expand Down
20 changes: 10 additions & 10 deletions src/zenml/analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import json
import logging
from typing import Any, Dict, Optional, Tuple
from typing import Any
from uuid import UUID

from zenml.analytics.enums import AnalyticsEvent
Expand All @@ -26,7 +26,7 @@
logger = logging.getLogger(__name__)


class Client(object):
class Client:
"""The client class for ZenML analytics."""

def __init__(self, send: bool = True, timeout: int = 15) -> None:
Expand All @@ -40,8 +40,8 @@ def __init__(self, send: bool = True, timeout: int = 15) -> None:
self.timeout = timeout

def identify(
self, user_id: UUID, traits: Optional[Dict[Any, Any]]
) -> Tuple[bool, str]:
self, user_id: UUID, traits: dict[Any, Any] | None
) -> tuple[bool, str]:
"""Method to identify a user with given traits.

Args:
Expand All @@ -59,7 +59,7 @@ def identify(
}
return self._enqueue(json.dumps(msg, cls=AnalyticsEncoder))

def alias(self, user_id: UUID, previous_id: UUID) -> Tuple[bool, str]:
def alias(self, user_id: UUID, previous_id: UUID) -> tuple[bool, str]:
"""Method to alias user IDs.

Args:
Expand All @@ -81,8 +81,8 @@ def track(
self,
user_id: UUID,
event: "AnalyticsEvent",
properties: Optional[Dict[Any, Any]],
) -> Tuple[bool, str]:
properties: dict[Any, Any] | None,
) -> tuple[bool, str]:
"""Method to track events.

Args:
Expand All @@ -103,8 +103,8 @@ def track(
return self._enqueue(json.dumps(msg, cls=AnalyticsEncoder))

def group(
self, user_id: UUID, group_id: UUID, traits: Optional[Dict[Any, Any]]
) -> Tuple[bool, str]:
self, user_id: UUID, group_id: UUID, traits: dict[Any, Any] | None
) -> tuple[bool, str]:
"""Method to group users.

Args:
Expand All @@ -124,7 +124,7 @@ def group(
}
return self._enqueue(json.dumps(msg, cls=AnalyticsEncoder))

def _enqueue(self, msg: str) -> Tuple[bool, str]:
def _enqueue(self, msg: str) -> tuple[bool, str]:
"""Method to queue messages to be sent.

Args:
Expand Down
Loading
Loading