-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: In SQL targets, users can now disable column type alterations w…
…ith the `allow_column_alter` built-in setting
- Loading branch information
1 parent
9e051aa
commit 70be244
Showing
7 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
import typing as t | ||
|
||
T = t.TypeVar("T") | ||
|
||
|
||
class ConfiguredProtocol(t.Protocol): | ||
"""Protocol for objects with a config attribute.""" | ||
|
||
config: dict[str, t.Any] | ||
|
||
|
||
class BuiltinSetting(t.Generic[T]): | ||
"""A descriptor that gets a value from a named key of the config attribute.""" | ||
|
||
def __init__(self, custom_key: str | None = None, *, default: T | None = None): | ||
"""Initialize the descriptor. | ||
Args: | ||
custom_key: The key to get from the config attribute instead of the | ||
attribute name. | ||
default: The default value if the key is not found. | ||
""" | ||
self.key = custom_key | ||
self.default = default | ||
|
||
def __set_name__(self, owner: type[ConfiguredProtocol], name: str) -> None: | ||
"""Set the name of the attribute. | ||
Args: | ||
owner: The class of the object. | ||
name: The name of the attribute. | ||
""" | ||
self.key = self.key or name | ||
|
||
def __get__( | ||
self, | ||
instance: ConfiguredProtocol, | ||
owner: type[ConfiguredProtocol], | ||
) -> T | None: | ||
"""Get the value from the instance's config attribute. | ||
Args: | ||
instance: The instance of the object. | ||
owner: The class of the object. | ||
Returns: | ||
The value from the config attribute. | ||
""" | ||
return instance.config.get(self.key, self.default) # type: ignore[no-any-return] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Test the BuiltinSetting descriptor.""" | ||
|
||
from __future__ import annotations | ||
|
||
from singer_sdk.helpers._builtin_setting import BuiltinSetting | ||
|
||
|
||
def test_builtin_setting_descriptor(): | ||
class ObjWithConfig: | ||
example = BuiltinSetting(default=1) | ||
|
||
def __init__(self): | ||
self.config = {"example": 1} | ||
|
||
obj = ObjWithConfig() | ||
assert obj.example == 1 | ||
|
||
obj.config["example"] = 2 | ||
assert obj.example == 2 | ||
|
||
|
||
def test_builtin_setting_descriptor_custom_key(): | ||
class ObjWithConfig: | ||
my_attr = BuiltinSetting("example", default=1) | ||
|
||
def __init__(self): | ||
self.config = {"example": 1} | ||
|
||
obj = ObjWithConfig() | ||
assert obj.my_attr == 1 | ||
|
||
obj.config["example"] = 2 | ||
assert obj.my_attr == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters