From c5a686751a8c41b921f8c40b3b020484a40e3352 Mon Sep 17 00:00:00 2001 From: Spece Date: Tue, 18 Jul 2023 11:08:02 -0400 Subject: [PATCH 1/2] #215 Improve access of __annotations__. --- databricks/sdk/core.py | 12 ++++++++---- tests/test_core.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/databricks/sdk/core.py b/databricks/sdk/core.py index 0c58d44c..42d329c2 100644 --- a/databricks/sdk/core.py +++ b/databricks/sdk/core.py @@ -702,10 +702,14 @@ def attributes(cls) -> Iterable[ConfigAttribute]: """ Returns a list of Databricks SDK configuration metadata """ if hasattr(cls, '_attributes'): return cls._attributes - # Python 3.7 compatibility: getting type hints require extra hop, as described in - # "Accessing The Annotations Dict Of An Object In Python 3.9 And Older" section of - # https://docs.python.org/3/howto/annotations.html - anno = cls.__dict__['__annotations__'] + if sys.version_info[1] >= 10: + import inspect + anno = inspect.get_annotations(cls) + else: + # Python 3.7 compatibility: getting type hints require extra hop, as described in + # "Accessing The Annotations Dict Of An Object In Python 3.9 And Older" section of + # https://docs.python.org/3/howto/annotations.html + anno = cls.__dict__['__annotations__'] attrs = [] for name, v in cls.__dict__.items(): if type(v) != ConfigAttribute: diff --git a/tests/test_core.py b/tests/test_core.py index f00c0b74..946ed9ea 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -207,3 +207,19 @@ def test_config_accounts_dod_is_accounts_host(config): def test_config_workspace_is_not_accounts_host(config): config.host = "https://westeurope.azuredatabricks.net" assert not config.is_account_client + + +def test_config_can_be_subclassed(): + + class DatabricksConfig(Config): + + def __init__(self): + super().__init__() + + with pytest.raises(ValueError): # As opposed to `KeyError`. + DatabricksConfig() + + +if __name__ == "__main__": + import conftest + test_config_accounts_dod_is_accounts_host(conftest.config.__pytest_wrapped__.obj()) From 8fda3380654e87c8ae090d41883e9a56508adf57 Mon Sep 17 00:00:00 2001 From: Spece Date: Tue, 18 Jul 2023 16:13:03 -0400 Subject: [PATCH 2/2] #239 Rm manual debugging. --- tests/test_core.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 946ed9ea..4402ff1d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -218,8 +218,3 @@ def __init__(self): with pytest.raises(ValueError): # As opposed to `KeyError`. DatabricksConfig() - - -if __name__ == "__main__": - import conftest - test_config_accounts_dod_is_accounts_host(conftest.config.__pytest_wrapped__.obj())