Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent mutable default arguments #2443

Merged
merged 8 commits into from
Jun 6, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.2
rev: v0.4.7
hooks:
# Run the linter.
- id: ruff
Expand Down
1 change: 1 addition & 0 deletions flytekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
SourceCode
"""

import os
import sys
from typing import Generator
Expand Down
6 changes: 2 additions & 4 deletions flytekit/clients/auth/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class ClientConfigStore(object):
"""

@abstractmethod
def get_client_config(self) -> ClientConfig:
...
def get_client_config(self) -> ClientConfig: ...


class StaticClientConfigStore(ClientConfigStore):
Expand Down Expand Up @@ -81,8 +80,7 @@ def fetch_grpc_call_auth_metadata(self) -> typing.Optional[typing.Tuple[str, str
return None

@abstractmethod
def refresh_credentials(self):
...
def refresh_credentials(self): ...


class PKCEAuthenticator(Authenticator):
Expand Down
1 change: 1 addition & 0 deletions flytekit/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
~DataConfig
"""

from __future__ import annotations

import base64
Expand Down
1 change: 1 addition & 0 deletions flytekit/configuration/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
my_plugin = "my_module:MyCustomPlugin"
```
"""

from typing import Optional, Protocol, runtime_checkable

from click import Group
Expand Down
9 changes: 3 additions & 6 deletions flytekit/core/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,11 @@ class ArtifactSerializationHandler(typing.Protocol):
This protocol defines the interface for serializing artifact-related entities down to Flyte IDL.
"""

def partitions_to_idl(self, p: Optional[Partitions], **kwargs) -> Optional[art_id.Partitions]:
...
def partitions_to_idl(self, p: Optional[Partitions], **kwargs) -> Optional[art_id.Partitions]: ...

def time_partition_to_idl(self, tp: Optional[TimePartition], **kwargs) -> Optional[art_id.TimePartition]:
...
def time_partition_to_idl(self, tp: Optional[TimePartition], **kwargs) -> Optional[art_id.TimePartition]: ...

def artifact_query_to_idl(self, aq: ArtifactQuery, **kwargs) -> art_id.ArtifactQuery:
...
def artifact_query_to_idl(self, aq: ArtifactQuery, **kwargs) -> art_id.ArtifactQuery: ...


class DefaultArtifactSerializationHandler(ArtifactSerializationHandler):
Expand Down
3 changes: 1 addition & 2 deletions flytekit/core/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ class SerializableToString(typing.Protocol):
and then added to a literal's metadata.
"""

def serialize_to_string(self, ctx: FlyteContext, variable_name: str) -> typing.Tuple[str, str]:
...
def serialize_to_string(self, ctx: FlyteContext, variable_name: str) -> typing.Tuple[str, str]: ...


@dataclass
Expand Down
1 change: 1 addition & 0 deletions flytekit/core/data_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
FileAccessProvider

"""

import io
import os
import pathlib
Expand Down
1 change: 1 addition & 0 deletions flytekit/core/dynamic_workflow_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
dynamic workflows to under fifty tasks. For large-scale identical runs, we recommend the upcoming map task.
"""

import functools

from flytekit.core import task
Expand Down
3 changes: 1 addition & 2 deletions flytekit/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def runs_before(self, *args, **kwargs):
where runs_before is manually called.
"""

def __rshift__(self, *args, **kwargs):
... # See runs_before
def __rshift__(self, *args, **kwargs): ... # See runs_before

self._output_tuple_class = Output
self._docstring = docstring
Expand Down
1 change: 1 addition & 0 deletions flytekit/core/legacy_map_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Flytekit map tasks specify how to run a single task across a list of inputs. Map tasks themselves are constructed with
a reference task as well as run-time parameters that limit execution concurrency and failure tolerations.
"""

import functools
import hashlib
import logging
Expand Down
1 change: 1 addition & 0 deletions flytekit/core/local_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
FlyteLocalFileSystem
"""

import os

from fsspec.implementations.local import LocalFileSystem
Expand Down
1 change: 1 addition & 0 deletions flytekit/core/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.. autoclass:: flytekit.core.notification.Notification
"""

from typing import List

from flytekit.models import common as _common_model
Expand Down
24 changes: 8 additions & 16 deletions flytekit/core/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,28 +891,22 @@ def with_attr(self, key) -> NodeOutput:

class SupportsNodeCreation(Protocol):
@property
def name(self) -> str:
...
def name(self) -> str: ...

@property
def python_interface(self) -> flyte_interface.Interface:
...
def python_interface(self) -> flyte_interface.Interface: ...

def construct_node_metadata(self) -> _workflow_model.NodeMetadata:
...
def construct_node_metadata(self) -> _workflow_model.NodeMetadata: ...


class HasFlyteInterface(Protocol):
@property
def name(self) -> str:
...
def name(self) -> str: ...

@property
def interface(self) -> _interface_models.TypedInterface:
...
def interface(self) -> _interface_models.TypedInterface: ...

def construct_node_metadata(self) -> _workflow_model.NodeMetadata:
...
def construct_node_metadata(self) -> _workflow_model.NodeMetadata: ...


def extract_obj_name(name: str) -> str:
Expand Down Expand Up @@ -1139,11 +1133,9 @@ def create_and_link_node(


class LocallyExecutable(Protocol):
def local_execute(self, ctx: FlyteContext, **kwargs) -> Union[Tuple[Promise], Promise, VoidPromise, None]:
...
def local_execute(self, ctx: FlyteContext, **kwargs) -> Union[Tuple[Promise], Promise, VoidPromise, None]: ...

def local_execution_mode(self) -> ExecutionState.Mode:
...
def local_execution_mode(self) -> ExecutionState.Mode: ...


def flyte_entity_call_handler(
Expand Down
3 changes: 1 addition & 2 deletions flytekit/core/reference_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def id(self) -> _identifier_model.Identifier:

@property
@abstractmethod
def resource_type(self) -> int:
...
def resource_type(self) -> int: ...


@dataclass
Expand Down
3 changes: 1 addition & 2 deletions flytekit/core/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@


class LaunchPlanTriggerBase(Protocol):
def to_flyte_idl(self, *args, **kwargs) -> google_message.Message:
...
def to_flyte_idl(self, *args, **kwargs) -> google_message.Message: ...


# Duplicates flytekit.common.schedules.Schedule to avoid using the ExtendedSdkType metaclass.
Expand Down
6 changes: 2 additions & 4 deletions flytekit/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ def task(
pod_template: Optional["PodTemplate"] = ...,
pod_template_name: Optional[str] = ...,
accelerator: Optional[BaseAccelerator] = ...,
) -> Callable[[Callable[..., FuncOut]], PythonFunctionTask[T]]:
...
) -> Callable[[Callable[..., FuncOut]], PythonFunctionTask[T]]: ...


@overload
Expand Down Expand Up @@ -155,8 +154,7 @@ def task(
pod_template: Optional["PodTemplate"] = ...,
pod_template_name: Optional[str] = ...,
accelerator: Optional[BaseAccelerator] = ...,
) -> Union[PythonFunctionTask[T], Callable[..., FuncOut]]:
...
) -> Union[PythonFunctionTask[T], Callable[..., FuncOut]]: ...


def task(
Expand Down
3 changes: 1 addition & 2 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def modify_literal_uris(lit: Literal):
)


class TypeTransformerFailedError(TypeError, AssertionError, ValueError):
...
class TypeTransformerFailedError(TypeError, AssertionError, ValueError): ...


class TypeTransformer(typing.Generic[T]):
Expand Down
6 changes: 2 additions & 4 deletions flytekit/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,7 @@ def workflow(
interruptible: bool = ...,
on_failure: Optional[Union[WorkflowBase, Task]] = ...,
docs: Optional[Documentation] = ...,
) -> Callable[[Callable[..., FuncOut]], PythonFunctionWorkflow]:
...
) -> Callable[[Callable[..., FuncOut]], PythonFunctionWorkflow]: ...


@overload
Expand All @@ -815,8 +814,7 @@ def workflow(
interruptible: bool = ...,
on_failure: Optional[Union[WorkflowBase, Task]] = ...,
docs: Optional[Documentation] = ...,
) -> Union[PythonFunctionWorkflow, Callable[..., FuncOut]]:
...
) -> Union[PythonFunctionWorkflow, Callable[..., FuncOut]]: ...


def workflow(
Expand Down
4 changes: 2 additions & 2 deletions flytekit/extras/accelerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def my_task() -> None:
A100_80GB
"""

import abc
import copy
from typing import ClassVar, Generic, Optional, Type, TypeVar
Expand All @@ -109,8 +110,7 @@ class BaseAccelerator(abc.ABC, Generic[T]):
"""

@abc.abstractmethod
def to_flyte_idl(self) -> T:
...
def to_flyte_idl(self) -> T: ...


class GPUAccelerator(BaseAccelerator):
Expand Down
1 change: 1 addition & 0 deletions flytekit/extras/pytorch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PyTorchModuleTransformer
PyTorchTensorTransformer
"""

from flytekit.loggers import logger

# TODO: abstract this out so that there's an established pattern for registering plugins
Expand Down
1 change: 1 addition & 0 deletions flytekit/extras/sklearn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SklearnEstimatorTransformer
"""

from flytekit.loggers import logger

# TODO: abstract this out so that there's an established pattern for registering plugins
Expand Down
1 change: 1 addition & 0 deletions flytekit/remote/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module contains shadow entities for all Flyte entities as represented in Flyte Admin / Control Plane.
The goal is to enable easy access, manipulation of these entities.
"""

from __future__ import annotations

from typing import Dict, List, Optional, Tuple, Union
Expand Down
6 changes: 2 additions & 4 deletions flytekit/remote/executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ def inputs(self) -> Optional[LiteralsResolver]:

@property
@abstractmethod
def error(self) -> core_execution_models.ExecutionError:
...
def error(self) -> core_execution_models.ExecutionError: ...

@property
@abstractmethod
def is_done(self) -> bool:
...
def is_done(self) -> bool: ...

@property
def outputs(self) -> Optional[LiteralsResolver]:
Expand Down
1 change: 1 addition & 0 deletions flytekit/remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with a Flyte backend in an interactive and programmatic way. This of this experience as kind of like the web UI
but in Python object form.
"""

from __future__ import annotations

import asyncio
Expand Down
3 changes: 1 addition & 2 deletions flytekit/remote/remote_callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def __init__(self, *args, **kwargs):

@property
@abstractmethod
def name(self) -> str:
...
def name(self) -> str: ...

def construct_node_metadata(self) -> NodeMetadata:
"""
Expand Down
3 changes: 1 addition & 2 deletions flytekit/types/directory/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
PathType = typing.Union[str, os.PathLike]


def noop():
...
def noop(): ...


@dataclass
Expand Down
3 changes: 1 addition & 2 deletions flytekit/types/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from flytekit.types.pickle.pickle import FlytePickleTransformer


def noop():
...
def noop(): ...


T = typing.TypeVar("T")
Expand Down
9 changes: 3 additions & 6 deletions flytekit/types/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ def column_names(self) -> typing.Optional[typing.List[str]]:
return None

@abstractmethod
def iter(self, **kwargs) -> typing.Generator[T, None, None]:
...
def iter(self, **kwargs) -> typing.Generator[T, None, None]: ...

@abstractmethod
def all(self, **kwargs) -> T:
...
def all(self, **kwargs) -> T: ...


class SchemaWriter(typing.Generic[T]):
Expand All @@ -95,8 +93,7 @@ def column_names(self) -> typing.Optional[typing.List[str]]:
return None

@abstractmethod
def write(self, *dfs, **kwargs):
...
def write(self, *dfs, **kwargs): ...


class LocalIOSchemaReader(SchemaReader[T]):
Expand Down
1 change: 0 additions & 1 deletion flytekit/types/structured/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
StructuredDatasetDecoder
"""


from flytekit.deck.renderer import ArrowRenderer, TopFrameRenderer
from flytekit.loggers import logger

Expand Down
Loading
Loading