3737)
3838
3939import pandas as pd
40+ from typing_extensions import Self
4041
4142from hamilton import common , graph_types , htypes
4243from hamilton .caching .adapter import HamiltonCacheAdapter
@@ -1777,7 +1778,7 @@ def _require_field_set(self, field: str, message: str, unset_value: Any = None):
17771778 if getattr (self , field ) == unset_value :
17781779 raise ValueError (message )
17791780
1780- def enable_dynamic_execution (self , * , allow_experimental_mode : bool = False ) -> "Builder" :
1781+ def enable_dynamic_execution (self , * , allow_experimental_mode : bool = False ) -> Self :
17811782 """Enables the Parallelizable[] type, which in turn enables:
17821783 1. Grouped execution into tasks
17831784 2. Parallel execution
@@ -1791,7 +1792,7 @@ def enable_dynamic_execution(self, *, allow_experimental_mode: bool = False) ->
17911792 self .v2_executor = True
17921793 return self
17931794
1794- def with_config (self , config : dict [str , Any ]) -> "Builder" :
1795+ def with_config (self , config : dict [str , Any ]) -> Self :
17951796 """Adds the specified configuration to the config.
17961797 This can be called multilple times -- later calls will take precedence.
17971798
@@ -1801,7 +1802,7 @@ def with_config(self, config: dict[str, Any]) -> "Builder":
18011802 self .config .update (config )
18021803 return self
18031804
1804- def with_modules (self , * modules : ModuleType ) -> "Builder" :
1805+ def with_modules (self , * modules : ModuleType ) -> Self :
18051806 """Adds the specified modules to the modules list.
18061807 This can be called multiple times.
18071808
@@ -1811,7 +1812,7 @@ def with_modules(self, *modules: ModuleType) -> "Builder":
18111812 self .modules .extend (modules )
18121813 return self
18131814
1814- def with_adapter (self , adapter : base .HamiltonGraphAdapter ) -> "Builder" :
1815+ def with_adapter (self , adapter : base .HamiltonGraphAdapter ) -> Self :
18151816 """Sets the adapter to use.
18161817
18171818 :param adapter: Adapter to use.
@@ -1821,7 +1822,7 @@ def with_adapter(self, adapter: base.HamiltonGraphAdapter) -> "Builder":
18211822 self .legacy_graph_adapter = adapter
18221823 return self
18231824
1824- def with_adapters (self , * adapters : lifecycle_base .LifecycleAdapter ) -> "Builder" :
1825+ def with_adapters (self , * adapters : lifecycle_base .LifecycleAdapter ) -> Self :
18251826 """Sets the adapter to use.
18261827
18271828 :param adapter: Adapter to use.
@@ -1837,7 +1838,7 @@ def with_adapters(self, *adapters: lifecycle_base.LifecycleAdapter) -> "Builder"
18371838
18381839 def with_materializers (
18391840 self , * materializers : ExtractorFactory | MaterializerFactory
1840- ) -> "Builder" :
1841+ ) -> Self :
18411842 """Add materializer nodes to the `Driver`
18421843 The generated nodes can be referenced by name in `.execute()`
18431844
@@ -1872,7 +1873,7 @@ def with_cache(
18721873 default_loader_behavior : Literal ["default" , "recompute" , "disable" , "ignore" ] = "default" ,
18731874 default_saver_behavior : Literal ["default" , "recompute" , "disable" , "ignore" ] = "default" ,
18741875 log_to_file : bool = False ,
1875- ) -> "Builder" :
1876+ ) -> Self :
18761877 """Add the caching adapter to the `Driver`
18771878
18781879 :param path: path where the cache metadata and results will be stored
@@ -1942,7 +1943,7 @@ def cache(self) -> HamiltonCacheAdapter | None:
19421943 if isinstance (adapter , HamiltonCacheAdapter ):
19431944 return adapter
19441945
1945- def with_execution_manager (self , execution_manager : executors .ExecutionManager ) -> "Builder" :
1946+ def with_execution_manager (self , execution_manager : executors .ExecutionManager ) -> Self :
19461947 """Sets the execution manager to use. Note that this cannot be used if local_executor
19471948 or remote_executor are also set
19481949
@@ -1959,7 +1960,7 @@ def with_execution_manager(self, execution_manager: executors.ExecutionManager)
19591960 self .execution_manager = execution_manager
19601961 return self
19611962
1962- def with_remote_executor (self , remote_executor : executors .TaskExecutor ) -> "Builder" :
1963+ def with_remote_executor (self , remote_executor : executors .TaskExecutor ) -> Self :
19631964 """Sets the execution manager to use. Note that this cannot be used if local_executor
19641965 or remote_executor are also set
19651966
@@ -1975,7 +1976,7 @@ def with_remote_executor(self, remote_executor: executors.TaskExecutor) -> "Buil
19751976 self .remote_executor = remote_executor
19761977 return self
19771978
1978- def with_local_executor (self , local_executor : executors .TaskExecutor ) -> "Builder" :
1979+ def with_local_executor (self , local_executor : executors .TaskExecutor ) -> Self :
19791980 """Sets the execution manager to use. Note that this cannot be used if local_executor
19801981 or remote_executor are also set
19811982
@@ -1991,7 +1992,7 @@ def with_local_executor(self, local_executor: executors.TaskExecutor) -> "Builde
19911992 self .local_executor = local_executor
19921993 return self
19931994
1994- def with_grouping_strategy (self , grouping_strategy : grouping .GroupingStrategy ) -> "Builder" :
1995+ def with_grouping_strategy (self , grouping_strategy : grouping .GroupingStrategy ) -> Self :
19951996 """Sets a node grouper, which tells the driver how to group nodes into tasks for execution.
19961997
19971998 :param node_grouper: Node grouper to use.
@@ -2002,7 +2003,7 @@ def with_grouping_strategy(self, grouping_strategy: grouping.GroupingStrategy) -
20022003 self .grouping_strategy = grouping_strategy
20032004 return self
20042005
2005- def allow_module_overrides (self ) -> "Builder" :
2006+ def allow_module_overrides (self ) -> Self :
20062007 """Same named functions in different modules get overwritten.
20072008 If multiple modules have same named functions, the later module overrides the previous one(s).
20082009 The order of listing the modules is important, since later ones will overwrite the previous ones. This is a global call affecting all imported modules.
0 commit comments