-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from pcattori/dataclasses
POC for dataclasses
- Loading branch information
Showing
9 changed files
with
72 additions
and
127 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# TODO(pcattori) Delete this file once RTD fully supports poetry | ||
recommonmark==0.6.0 | ||
Sphinx==2.1.0 | ||
sphinx_rtd_theme==0.4.3 | ||
sphinx-autodoc-typehints==1.8.0 | ||
Sphinx==2.1.0 | ||
toml==0.10.0 | ||
. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,43 +1,45 @@ | ||
from copy import deepcopy | ||
from dataclasses import dataclass, field | ||
from typing import Any, Dict, Optional | ||
|
||
from tamr_unify_client.attribute.type import AttributeType | ||
|
||
SubAttributeJson = Dict[str, Any] | ||
|
||
|
||
@dataclass(frozen=True) | ||
class SubAttribute: | ||
""" | ||
An attribute which is itself a property of another attribute. | ||
"""An attribute which is itself a property of another attribute. | ||
See https://docs.tamr.com/reference#attribute-types | ||
:param data: JSON data representing this attribute | ||
:type data: :py:class:`dict` | ||
Args: | ||
name: Name of sub-attribute | ||
description: Description of sub-attribute | ||
type: See https://docs.tamr.com/reference#attribute-types | ||
is_nullable: If this sub-attribute can be null | ||
""" | ||
|
||
def __init__(self, data): | ||
self._data = data | ||
|
||
@property | ||
def name(self): | ||
""":type: str""" | ||
return self._data.get("name") | ||
|
||
@property | ||
def description(self): | ||
""":type: str""" | ||
return self._data.get("description") | ||
|
||
@property | ||
def type(self): | ||
""":type: :class:`~tamr_unify_client.attribute.type.AttributeType`""" | ||
# import locally to avoid circular dependency | ||
from tamr_unify_client.attribute.type import AttributeType | ||
|
||
type_json = self._data.get("type") | ||
return AttributeType(type_json) | ||
|
||
@property | ||
def is_nullable(self): | ||
""":type: bool""" | ||
return self._data.get("isNullable") | ||
|
||
def __repr__(self): | ||
return ( | ||
f"{self.__class__.__module__}." | ||
f"{self.__class__.__qualname__}(" | ||
f"name={self.name!r})" | ||
) | ||
name: str | ||
type: AttributeType | ||
is_nullable: bool | ||
_json: SubAttributeJson = field(repr=False) | ||
description: Optional[str] = None | ||
|
||
@staticmethod | ||
def from_json(data: SubAttributeJson) -> "SubAttribute": | ||
"""Create a SubAttribute from JSON data. | ||
Args: | ||
data: JSON data received from Tamr server. | ||
""" | ||
_json = deepcopy(data) | ||
|
||
dc = deepcopy(data) | ||
dc["is_nullable"] = dc.pop("isNullable") | ||
|
||
type_json = dc.pop("type") | ||
# TODO implement AttributeType.from_json and use that instead | ||
type = AttributeType(type_json) | ||
|
||
return SubAttribute(**dc, type=type, _json=_json) |
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