Skip to content

Instantly share code, notes, and snippets.

@pranshuj73
Last active July 10, 2020 09:28
Show Gist options
  • Save pranshuj73/05edaab63e093a2127b7dffc2aa9d782 to your computer and use it in GitHub Desktop.
Save pranshuj73/05edaab63e093a2127b7dffc2aa9d782 to your computer and use it in GitHub Desktop.
import typing
class ArticleField:
"""The `ArticleField` class for the Advanced Requirements."""
def __init__(self, field_type: typing.Type[typing.Any]):
self.field_type = field_type
self.attribute = ''
def type_checking(self,value,type):
if type(value) != type:
raise TypeError
def __get__(self, instance, owner):
return self.attribute
def __set__(self, instance, value):
if not isinstance(type(value), self.field_type):
raise TypeError(self.field_type, type(value)) # although print('error') works fine
self.attribute = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment