Last active
February 20, 2017 23:52
-
-
Save Stiivi/6d5f9ec1b48baf3e70656ecb4ec3df13 to your computer and use it in GitHub Desktop.
Entigen example
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
from typing import Any, List, cast, Optional | |
class Thing: | |
# Name | |
name: str | |
"""Name of a thing""" | |
# Type | |
type: str | |
"""Type of a thing""" | |
# Tags | |
tags: List[str] | |
"""List of thing categorization tags""" | |
# Attributes | |
attributes: List[Attribute] | |
"""List of attributes of the Thing""" | |
def __init__(self, | |
name: str, | |
type: str, | |
attributes: List[Attribute], | |
tags: Optional[List[str]]=None, | |
) -> None: | |
"""Create Thing""" | |
self.name = name | |
self.type = type | |
if tags is None: | |
self.tags = [] | |
else: | |
self.tags = tags | |
self.attributes = attributes | |
def __eq__(self, other: object) -> bool: | |
if not isinstance(other, Thing): | |
return False | |
# 'typed' other | |
tother = cast(Thing, other) | |
if \ | |
self.name == tother.name \ | |
and self.type == tother.type \ | |
and self.tags == tother.tags \ | |
and self.attributes == tother.attributes: | |
return True | |
else: | |
return False | |
class Attribute: | |
# Name | |
name: str | |
"""Attribute name""" | |
# Type | |
raw_type: str | |
"""Attribute type""" | |
def __init__(self, | |
name: str, | |
raw_type: str, | |
) -> None: | |
"""Create Attribute""" | |
self.name = name | |
self.raw_type = raw_type | |
def __eq__(self, other: object) -> bool: | |
if not isinstance(other, Attribute): | |
return False | |
# 'typed' other | |
tother = cast(Attribute, other) | |
if \ | |
self.name == tother.name \ | |
and self.raw_type == tother.raw_type: | |
return True | |
else: | |
return False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment