Skip to content

Commit f0a18cc

Browse files
authored
Improve access of __annotations__ (#239)
## Changes This is a continuation of #216, but with signed, verified commits. ## Tests One test was added (in #216). The last run in #216 passed all tests. - [ ] `make test` run locally - [ ] `make fmt` applied - [ ] relevant integration tests applied
1 parent 2e07e0a commit f0a18cc

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

databricks/sdk/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,14 @@ def attributes(cls) -> Iterable[ConfigAttribute]:
702702
""" Returns a list of Databricks SDK configuration metadata """
703703
if hasattr(cls, '_attributes'):
704704
return cls._attributes
705-
# Python 3.7 compatibility: getting type hints require extra hop, as described in
706-
# "Accessing The Annotations Dict Of An Object In Python 3.9 And Older" section of
707-
# https://docs.python.org/3/howto/annotations.html
708-
anno = cls.__dict__['__annotations__']
705+
if sys.version_info[1] >= 10:
706+
import inspect
707+
anno = inspect.get_annotations(cls)
708+
else:
709+
# Python 3.7 compatibility: getting type hints require extra hop, as described in
710+
# "Accessing The Annotations Dict Of An Object In Python 3.9 And Older" section of
711+
# https://docs.python.org/3/howto/annotations.html
712+
anno = cls.__dict__['__annotations__']
709713
attrs = []
710714
for name, v in cls.__dict__.items():
711715
if type(v) != ConfigAttribute:

tests/test_core.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,14 @@ def test_config_accounts_dod_is_accounts_host(config):
207207
def test_config_workspace_is_not_accounts_host(config):
208208
config.host = "https://westeurope.azuredatabricks.net"
209209
assert not config.is_account_client
210+
211+
212+
def test_config_can_be_subclassed():
213+
214+
class DatabricksConfig(Config):
215+
216+
def __init__(self):
217+
super().__init__()
218+
219+
with pytest.raises(ValueError): # As opposed to `KeyError`.
220+
DatabricksConfig()

0 commit comments

Comments
 (0)