Skip to content

Commit

Permalink
chore: use generic typing
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Apr 3, 2024
1 parent 77d5d8d commit 5d1b88d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dlt/pipeline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Sequence, Type, cast, overload
from typing import Sequence, Type, TypeVar, cast, overload

from dlt.common.schema import Schema
from dlt.common.schema.typing import TColumnSchema, TWriteDisposition, TSchemaContract
Expand All @@ -15,6 +15,8 @@
from dlt.pipeline.progress import _from_name as collector_from_name, TCollectorArg, _NULL_COLLECTOR
from dlt.pipeline.warnings import credentials_argument_deprecated

TPipeline = TypeVar("TPipeline", bound=Pipeline)


@overload
def pipeline(
Expand All @@ -29,7 +31,8 @@ def pipeline(
full_refresh: bool = False,
credentials: Any = None,
progress: TCollectorArg = _NULL_COLLECTOR,
) -> Pipeline:
_impl_cls: Type[TPipeline] = Pipeline,
) -> TPipeline:
"""Creates a new instance of `dlt` pipeline, which moves the data from the source ie. a REST API to a destination ie. database or a data lake.
#### Note:
Expand Down Expand Up @@ -97,9 +100,9 @@ def pipeline(
full_refresh: bool = False,
credentials: Any = None,
progress: TCollectorArg = _NULL_COLLECTOR,
_impl_cls: Type[Pipeline] = Pipeline,
_impl_cls: Type[TPipeline] = Pipeline,
**kwargs: Any,
) -> Pipeline:
) -> TPipeline:
ensure_correct_pipeline_kwargs(pipeline, **kwargs)
# call without arguments returns current pipeline
orig_args = get_orig_args(**kwargs) # original (*args, **kwargs)
Expand All @@ -112,7 +115,7 @@ def pipeline(
context = Container()[PipelineContext]
# if pipeline instance is already active then return it, otherwise create a new one
if context.is_active():
return cast(Pipeline, context.pipeline())
return cast(TPipeline, context.pipeline())
else:
pass

Expand Down

0 comments on commit 5d1b88d

Please sign in to comment.