From 66c87fa86f904aaf86415a9ecee2b5377ad2fa3b Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Mon, 31 Dec 2018 21:29:48 -0500 Subject: [PATCH] Remove -> None annotation from __init__ --- src/prefect/client/client.py | 2 +- src/prefect/client/secrets.py | 2 +- src/prefect/core/edge.py | 2 +- src/prefect/core/flow.py | 2 +- src/prefect/core/task.py | 4 ++-- src/prefect/engine/executors/dask.py | 2 +- src/prefect/engine/flow_runner.py | 2 +- src/prefect/engine/runner.py | 4 ++-- src/prefect/engine/signals.py | 2 +- src/prefect/engine/state.py | 20 +++++++++---------- src/prefect/engine/task_runner.py | 2 +- src/prefect/environments.py | 6 ++---- src/prefect/schedules.py | 4 ++-- src/prefect/tasks/control_flow/conditional.py | 2 +- src/prefect/tasks/core/constants.py | 2 +- src/prefect/tasks/core/function.py | 2 +- src/prefect/tasks/database/sqlite.py | 4 ++-- src/prefect/tasks/flow_runner_task.py | 2 +- src/prefect/tasks/notifications/email_task.py | 4 +--- src/prefect/tasks/shell.py | 2 +- src/prefect/tasks/templates/jinja2.py | 2 +- src/prefect/tasks/templates/strings.py | 2 +- src/prefect/utilities/airflow_utils.py | 4 ++-- src/prefect/utilities/collections.py | 16 ++++++++++++++- src/prefect/utilities/context.py | 2 +- src/prefect/utilities/graphql.py | 2 +- src/prefect/utilities/logging.py | 2 +- src/prefect/utilities/serialization.py | 6 +++--- src/prefect/utilities/tasks.py | 2 +- 29 files changed, 59 insertions(+), 51 deletions(-) diff --git a/src/prefect/client/client.py b/src/prefect/client/client.py index 3c5a24374469..b1d9667189e8 100644 --- a/src/prefect/client/client.py +++ b/src/prefect/client/client.py @@ -51,7 +51,7 @@ def _initialize_logger(self) -> None: self.logger.addHandler(handler) self.logger.setLevel(prefect.config.logging.level) - def __init__(self, api_server: str = None, graphql_server: str = None) -> None: + def __init__(self, api_server: str = None, graphql_server: str = None): self._initialize_logger() if not api_server: api_server = prefect.config.cloud.get("api", None) diff --git a/src/prefect/client/secrets.py b/src/prefect/client/secrets.py index 8b3c722ddbc3..67ae7eb38c7b 100644 --- a/src/prefect/client/secrets.py +++ b/src/prefect/client/secrets.py @@ -20,7 +20,7 @@ class Secret: of the `use_local_secrets` flag in your Prefect configuration file. """ - def __init__(self, name: str) -> None: + def __init__(self, name: str): self.name = name def get(self) -> Optional[str]: diff --git a/src/prefect/core/edge.py b/src/prefect/core/edge.py index b5d7036158fd..8742d170ba49 100644 --- a/src/prefect/core/edge.py +++ b/src/prefect/core/edge.py @@ -87,7 +87,7 @@ def __init__( downstream_task: Task, key: str = None, mapped: bool = False, - ) -> None: + ): self.upstream_task = upstream_task self.downstream_task = downstream_task self.mapped = mapped diff --git a/src/prefect/core/flow.py b/src/prefect/core/flow.py index 54aea2cbf87b..b6d2affa0731 100644 --- a/src/prefect/core/flow.py +++ b/src/prefect/core/flow.py @@ -140,7 +140,7 @@ def __init__( state_handlers: Iterable[Callable] = None, validate: bool = None, result_handler: ResultHandler = None, - ) -> None: + ): self._cache = {} # type: dict # set random id diff --git a/src/prefect/core/task.py b/src/prefect/core/task.py index 81ec680d794e..4777bc176570 100644 --- a/src/prefect/core/task.py +++ b/src/prefect/core/task.py @@ -136,7 +136,7 @@ def __init__( cache_for: timedelta = None, cache_validator: Callable = None, state_handlers: Iterable[Callable] = None, - ) -> None: + ): self.name = name or type(self).__name__ self.slug = slug @@ -842,7 +842,7 @@ def __init__( default: Any = None, required: bool = True, tags: Iterable[str] = None, - ) -> None: + ): if default is not None: required = False diff --git a/src/prefect/engine/executors/dask.py b/src/prefect/engine/executors/dask.py index 7168d765fe04..6361cba18d0c 100644 --- a/src/prefect/engine/executors/dask.py +++ b/src/prefect/engine/executors/dask.py @@ -47,7 +47,7 @@ def __init__( processes: bool = False, debug: bool = config.debug, **kwargs: Any - ) -> None: + ): self.address = address self.processes = processes self.debug = debug diff --git a/src/prefect/engine/flow_runner.py b/src/prefect/engine/flow_runner.py index f943c0af54bf..911f34777897 100644 --- a/src/prefect/engine/flow_runner.py +++ b/src/prefect/engine/flow_runner.py @@ -76,7 +76,7 @@ def __init__( flow: Flow, task_runner_cls: type = None, state_handlers: Iterable[Callable] = None, - ) -> None: + ): self.flow = flow self.task_runner_cls = task_runner_cls or TaskRunner self.client = Client() diff --git a/src/prefect/engine/runner.py b/src/prefect/engine/runner.py index c5972dcdb3f9..1d36b5058065 100644 --- a/src/prefect/engine/runner.py +++ b/src/prefect/engine/runner.py @@ -14,7 +14,7 @@ class ENDRUN(Exception): stop. The pipeline result should be the state contained in the exception. """ - def __init__(self, state: State) -> None: + def __init__(self, state: State): """ Args - state (State): the state that should be used as the result of the Runner's run @@ -63,7 +63,7 @@ def inner(self: "Runner", state: State, *args: Any, **kwargs: Any) -> State: class Runner: - def __init__(self, state_handlers: Iterable[Callable] = None) -> None: + def __init__(self, state_handlers: Iterable[Callable] = None): if state_handlers is not None and not isinstance( state_handlers, collections.Sequence ): diff --git a/src/prefect/engine/signals.py b/src/prefect/engine/signals.py index 85bcddcc08bc..7360795579cd 100644 --- a/src/prefect/engine/signals.py +++ b/src/prefect/engine/signals.py @@ -23,7 +23,7 @@ class PrefectStateSignal(PrefectError): _state_cls = state.State - def __init__(self, message=None, *args, **kwargs) -> None: # type: ignore + def __init__(self, message: str = None, *args, **kwargs): # type: ignore super().__init__(message) # type: ignore self.state = self._state_cls( # type: ignore result=self, message=message, *args, **kwargs diff --git a/src/prefect/engine/state.py b/src/prefect/engine/state.py index 556467427271..a352207ae4d9 100644 --- a/src/prefect/engine/state.py +++ b/src/prefect/engine/state.py @@ -49,7 +49,7 @@ class State: color = "#000000" - def __init__(self, message: str = None, result: Any = None) -> None: + def __init__(self, message: str = None, result: Any = None): self.message = message self.result = result @@ -202,7 +202,7 @@ def __init__( message: str = None, result: Any = None, cached_inputs: Dict[str, Any] = None, - ) -> None: + ): super().__init__(message=message, result=result) self.cached_inputs = cached_inputs @@ -249,7 +249,7 @@ def __init__( cached_result: Any = None, cached_parameters: Dict[str, Any] = None, cached_result_expiration: datetime.datetime = None, - ) -> None: + ): super().__init__(message=message, result=result, cached_inputs=cached_inputs) self.cached_result = cached_result self.cached_parameters = cached_parameters @@ -279,7 +279,7 @@ def __init__( result: Any = None, start_time: datetime.datetime = None, cached_inputs: Dict[str, Any] = None, - ) -> None: + ): super().__init__(message=message, result=result, cached_inputs=cached_inputs) self.start_time = ensure_tz_aware(start_time or pendulum.now("utc")) @@ -304,9 +304,7 @@ class Submitted(State): """ - def __init__( - self, message: str = None, result: Any = None, state: State = None - ) -> None: + def __init__(self, message: str = None, result: Any = None, state: State = None): super().__init__(message=message, result=result) self.state = state @@ -352,7 +350,7 @@ def __init__( start_time: datetime.datetime = None, cached_inputs: Dict[str, Any] = None, run_count: int = None, - ) -> None: + ): super().__init__( result=result, message=message, @@ -418,7 +416,7 @@ class Success(Finished): def __init__( self, message: str = None, result: Any = None, cached: CachedState = None - ) -> None: + ): super().__init__(message=message, result=result) self.cached = cached @@ -473,7 +471,7 @@ def __init__( message: str = None, result: Any = None, cached_inputs: Dict[str, Any] = None, - ) -> None: + ): super().__init__(message=message, result=result) self.cached_inputs = cached_inputs @@ -504,5 +502,5 @@ class Skipped(Success): color = "#F0FFF0" # note: this does not allow setting "cached" as Success states do - def __init__(self, message: str = None, result: Any = None) -> None: + def __init__(self, message: str = None, result: Any = None): super().__init__(message=message, result=result) diff --git a/src/prefect/engine/task_runner.py b/src/prefect/engine/task_runner.py index 2dce442f4a11..cff5515a6d4a 100644 --- a/src/prefect/engine/task_runner.py +++ b/src/prefect/engine/task_runner.py @@ -78,7 +78,7 @@ def __init__( task: Task, result_handler: ResultHandler = None, state_handlers: Iterable[Callable] = None, - ) -> None: + ): self.task = task self.client = Client() self.result_handler = result_handler diff --git a/src/prefect/environments.py b/src/prefect/environments.py index d506a8080c46..ca820a0439c1 100644 --- a/src/prefect/environments.py +++ b/src/prefect/environments.py @@ -128,9 +128,7 @@ class LocalEnvironment(Environment): - serialized_flow (bytes): a serialized flow. This is usually generated by calling `build()`. """ - def __init__( - self, encryption_key: bytes = None, serialized_flow: bytes = None - ) -> None: + def __init__(self, encryption_key: bytes = None, serialized_flow: bytes = None): if encryption_key is None: encryption_key = Fernet.generate_key() else: @@ -237,7 +235,7 @@ def __init__( image_tag: str = None, env_vars: dict = None, files: dict = None, - ) -> None: + ): self.base_image = base_image self.registry_url = registry_url self.image_name = image_name diff --git a/src/prefect/schedules.py b/src/prefect/schedules.py index bb015d89bb79..2a6a94f49533 100644 --- a/src/prefect/schedules.py +++ b/src/prefect/schedules.py @@ -63,7 +63,7 @@ class IntervalSchedule(Schedule): def __init__( self, start_date: datetime, interval: timedelta, end_date: datetime = None - ) -> None: + ): if not isinstance(start_date, datetime): raise TypeError("`start_date` must be a datetime.") elif interval.total_seconds() < 60: @@ -131,7 +131,7 @@ class CronSchedule(Schedule): def __init__( self, cron: str, start_date: datetime = None, end_date: datetime = None - ) -> None: + ): # build cron object to check the cron string - will raise an error if it's invalid CronTab(cron) self.cron = cron diff --git a/src/prefect/tasks/control_flow/conditional.py b/src/prefect/tasks/control_flow/conditional.py index 24d186c88535..3884fb97b635 100644 --- a/src/prefect/tasks/control_flow/conditional.py +++ b/src/prefect/tasks/control_flow/conditional.py @@ -27,7 +27,7 @@ class Match(Task): - **kwargs: keyword arguments for the Task """ - def __init__(self, match_value: Any, **kwargs) -> None: + def __init__(self, match_value: Any, **kwargs): self.match_value = match_value kwargs.setdefault("name", 'match: "{}"'.format(match_value)) super().__init__(**kwargs) diff --git a/src/prefect/tasks/core/constants.py b/src/prefect/tasks/core/constants.py index 0411ae1b21f6..02c5c930295d 100644 --- a/src/prefect/tasks/core/constants.py +++ b/src/prefect/tasks/core/constants.py @@ -6,7 +6,7 @@ class Constant(prefect.Task): - def __init__(self, value: Any, name: str = None, **kwargs: Any) -> None: + def __init__(self, value: Any, name: str = None, **kwargs: Any): self.value = value diff --git a/src/prefect/tasks/core/function.py b/src/prefect/tasks/core/function.py index 2dbc22b4c348..276ab2809f14 100644 --- a/src/prefect/tasks/core/function.py +++ b/src/prefect/tasks/core/function.py @@ -30,7 +30,7 @@ class FunctionTask(prefect.Task): ``` """ - def __init__(self, fn: Callable, name: str = None, **kwargs: Any) -> None: + def __init__(self, fn: Callable, name: str = None, **kwargs: Any): if not callable(fn): raise TypeError("fn must be callable.") diff --git a/src/prefect/tasks/database/sqlite.py b/src/prefect/tasks/database/sqlite.py index 45e3a33f9929..2f5d6b47abfe 100644 --- a/src/prefect/tasks/database/sqlite.py +++ b/src/prefect/tasks/database/sqlite.py @@ -21,7 +21,7 @@ class SQLiteQueryTask(Task): standard Task initalization """ - def __init__(self, db: str, query: str = None, **kwargs) -> None: + def __init__(self, db: str, query: str = None, **kwargs): self.db = db self.query = query super().__init__(**kwargs) @@ -56,7 +56,7 @@ class SQLiteScriptTask(Task): standard Task initialization """ - def __init__(self, db: str, script: str = None, **kwargs) -> None: + def __init__(self, db: str, script: str = None, **kwargs): self.db = db self.script = script super().__init__(**kwargs) diff --git a/src/prefect/tasks/flow_runner_task.py b/src/prefect/tasks/flow_runner_task.py index f400f3943f65..c5e7773ee28d 100644 --- a/src/prefect/tasks/flow_runner_task.py +++ b/src/prefect/tasks/flow_runner_task.py @@ -10,7 +10,7 @@ class FlowRunnerTask(prefect.Task): def __init__( self, executor: prefect.engine.executors.Executor = None, **kwargs: Any - ) -> None: + ): self.executor = executor super().__init__(**kwargs) diff --git a/src/prefect/tasks/notifications/email_task.py b/src/prefect/tasks/notifications/email_task.py index 80f8d8b004b6..1bc1c5002f1b 100644 --- a/src/prefect/tasks/notifications/email_task.py +++ b/src/prefect/tasks/notifications/email_task.py @@ -19,9 +19,7 @@ class EmailTask(prefect.Task): This task sends an email. """ - def __init__( - self, username: str = None, password: str = None, **kwargs: Any - ) -> None: + def __init__(self, username: str = None, password: str = None, **kwargs: Any): self.username = username self.password = password diff --git a/src/prefect/tasks/shell.py b/src/prefect/tasks/shell.py index 578bfff1d8b7..0a75a1b38e52 100644 --- a/src/prefect/tasks/shell.py +++ b/src/prefect/tasks/shell.py @@ -32,7 +32,7 @@ class ShellTask(prefect.Task): def __init__( self, shell: str = "bash", cd: str = None, command: str = None, **kwargs: Any - ) -> None: + ): self.shell = shell self.cd = cd self.command = command diff --git a/src/prefect/tasks/templates/jinja2.py b/src/prefect/tasks/templates/jinja2.py index 8341cdcd05eb..49da19d5d42a 100644 --- a/src/prefect/tasks/templates/jinja2.py +++ b/src/prefect/tasks/templates/jinja2.py @@ -21,7 +21,7 @@ class JinjaTemplateTask(Task): standard Task constructor """ - def __init__(self, template: str = None, **kwargs: Any) -> None: + def __init__(self, template: str = None, **kwargs: Any): self.template = Template(template or "") super().__init__(**kwargs) diff --git a/src/prefect/tasks/templates/strings.py b/src/prefect/tasks/templates/strings.py index 305e8de024fa..212699653f79 100644 --- a/src/prefect/tasks/templates/strings.py +++ b/src/prefect/tasks/templates/strings.py @@ -20,7 +20,7 @@ class StringFormatterTask(Task): standard Task constructor """ - def __init__(self, template: str = None, **kwargs: Any) -> None: + def __init__(self, template: str = None, **kwargs: Any): self.template = template or "" super().__init__(**kwargs) diff --git a/src/prefect/utilities/airflow_utils.py b/src/prefect/utilities/airflow_utils.py index 007751402bda..a0c85e53e8ef 100644 --- a/src/prefect/utilities/airflow_utils.py +++ b/src/prefect/utilities/airflow_utils.py @@ -48,7 +48,7 @@ def custom_query(db: str, query: str) -> List: class AirTask(prefect.tasks.shell.ShellTask): - def __init__(self, task: "airflow.models.BaseOperator", **kwargs: Any) -> None: + def __init__(self, task: "airflow.models.BaseOperator", **kwargs: Any): name = task.task_id dag_id = task.dag_id trigger = trigger_mapping[task.trigger_rule] @@ -164,7 +164,7 @@ def __init__( db_file: str = None, dag_folder: str = None, **kwargs: Any - ) -> None: + ): self.dag = airflow.models.DagBag(dag_folder=dag_folder).dags[dag_id] super().__init__(*args, **kwargs) self._populate_tasks() diff --git a/src/prefect/utilities/collections.py b/src/prefect/utilities/collections.py index dadd5f7ddbdb..12fb794ef8ac 100644 --- a/src/prefect/utilities/collections.py +++ b/src/prefect/utilities/collections.py @@ -56,11 +56,25 @@ class DotDict(MutableMapping): __protect_critical_keys__ = True - def __init__(self, init_dict: DictLike = None, **kwargs: Any) -> None: + def __init__(self, init_dict: DictLike = None, **kwargs: Any): if init_dict: self.update(init_dict) self.update(kwargs) + def get(self, key: str, default: Any = None) -> Any: + """ + This method is defined for MyPy, which otherwise tries to type + the inherited `.get()` method incorrectly. + + Args: + - key (str): the key to retrieve + - default (Any): a default value to return if the key is not found + + Returns: + - Any: the value of the key, or the default value if the key is not found + """ + return super().get(key, default) + def __getitem__(self, key: str) -> Any: return self.__dict__[key] # __dict__ expects string keys diff --git a/src/prefect/utilities/context.py b/src/prefect/utilities/context.py index f21c2416de4c..51c6491d4550 100644 --- a/src/prefect/utilities/context.py +++ b/src/prefect/utilities/context.py @@ -29,7 +29,7 @@ class Context(DotDict, threading.local): A thread safe context store for Prefect data. """ - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) if "context" in config: self.update(config.context) diff --git a/src/prefect/utilities/graphql.py b/src/prefect/utilities/graphql.py index a6f415380905..d37e6db15571 100644 --- a/src/prefect/utilities/graphql.py +++ b/src/prefect/utilities/graphql.py @@ -31,7 +31,7 @@ class EnumValue: as enum values, without quotation marks. """ - def __init__(self, value: str) -> None: + def __init__(self, value: str): self.value = value def __str__(self) -> str: diff --git a/src/prefect/utilities/logging.py b/src/prefect/utilities/logging.py index 9f4363d7beff..a5f497c03c3b 100644 --- a/src/prefect/utilities/logging.py +++ b/src/prefect/utilities/logging.py @@ -9,7 +9,7 @@ class RemoteHandler(logging.StreamHandler): - def __init__(self): + def __init__(self) -> None: super().__init__() self.logger_server = config.cloud.log self.client = None diff --git a/src/prefect/utilities/serialization.py b/src/prefect/utilities/serialization.py index 12eeac2895c8..6d663b4d0a76 100644 --- a/src/prefect/utilities/serialization.py +++ b/src/prefect/utilities/serialization.py @@ -97,7 +97,7 @@ def get_versioned_schema(schema: "VersionedSchema", version: str) -> "VersionedS class VersionedSchemaOptions(SchemaOpts): - def __init__(self, meta, **kwargs): + def __init__(self, meta, **kwargs) -> None: super().__init__(meta, **kwargs) self.object_class = getattr(meta, "object_class", None) self.object_class_exclude = getattr(meta, "object_class_exclude", None) or [] @@ -208,7 +208,7 @@ class Nested(fields.Nested): object. """ - def __init__(self, nested: type, value_selection_fn: Callable, **kwargs) -> None: + def __init__(self, nested: type, value_selection_fn: Callable, **kwargs): super().__init__(nested=nested, **kwargs) self.value_selection_fn = value_selection_fn @@ -275,7 +275,7 @@ class FunctionReference(fields.Field): """ - def __init__(self, valid_functions, reject_invalid=True, **kwargs): + def __init__(self, valid_functions: list, reject_invalid: bool = True, **kwargs): self.valid_functions = {to_qualified_name(f): f for f in valid_functions} self.reject_invalid = reject_invalid super().__init__(**kwargs) diff --git a/src/prefect/utilities/tasks.py b/src/prefect/utilities/tasks.py index a09bf3b8b765..ffb3f3ff1c8c 100644 --- a/src/prefect/utilities/tasks.py +++ b/src/prefect/utilities/tasks.py @@ -193,5 +193,5 @@ def run(self): ``` """ - def __init__(self, task: "prefect.Task") -> None: + def __init__(self, task: "prefect.Task"): self.task = as_task(task)