Skip to content

Commit

Permalink
change resolved partial method to dedicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Mar 7, 2024
1 parent f488210 commit 4d2563b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dlt/common/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .specs.base_configuration import configspec, is_valid_hint, is_secret_hint, resolve_type
from .specs import known_sections
from .resolve import resolve_configuration, inject_section
from .inject import with_config, last_config, get_fun_spec
from .inject import with_config, last_config, get_fun_spec, create_resolved_partial

from .exceptions import (
ConfigFieldMissingException,
Expand Down
10 changes: 9 additions & 1 deletion dlt/common/configuration/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dlt.common.configuration.resolve import resolve_configuration, inject_section
from dlt.common.configuration.specs.base_configuration import BaseConfiguration
from dlt.common.configuration.specs.config_section_context import ConfigSectionContext

from dlt.common.reflection.spec import spec_from_signature


Expand Down Expand Up @@ -215,7 +216,7 @@ def _wrap(*args: Any, **kwargs: Any) -> Any:
_FUNC_SPECS[id(_wrap)] = SPEC

# add a method to create a pre-resolved partial
_wrap.create_resolved_partial = create_resolved_partial
_wrap.__RESOLVED_PARTIAL_FUNC__ = create_resolved_partial

return _wrap # type: ignore

Expand All @@ -241,3 +242,10 @@ def last_config(**kwargs: Any) -> Any:

def get_orig_args(**kwargs: Any) -> Tuple[Tuple[Any], DictStrAny]:
return kwargs[_ORIGINAL_ARGS] # type: ignore


def create_resolved_partial(f: AnyFun) -> AnyFun:
"""Create a pre-resolved partial of the decorated function"""
if hasattr(f, "__RESOLVED_PARTIAL_FUNC__"):
return f.__RESOLVED_PARTIAL_FUNC__(lock=True)
return f
5 changes: 2 additions & 3 deletions dlt/destinations/impl/destination/sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
destination_state,
commit_load_package_state,
)
from dlt.common.configuration import create_resolved_partial

from dlt.common.schema import Schema, TTableSchema, TSchemaTables
from dlt.common.schema.typing import TTableSchema
Expand Down Expand Up @@ -129,9 +130,7 @@ def __init__(self, schema: Schema, config: SinkClientConfiguration) -> None:
self.config: SinkClientConfiguration = config

# we create pre_resolved callable here
self.destination_callable = self.config.destination_callable.create_resolved_partial(
lock=True
)
self.destination_callable = create_resolved_partial(self.config.destination_callable)

def initialize_storage(self, truncate_tables: Iterable[str] = None) -> None:
pass
Expand Down

0 comments on commit 4d2563b

Please sign in to comment.