Last active
July 10, 2020 09:28
-
-
Save pranshuj73/05edaab63e093a2127b7dffc2aa9d782 to your computer and use it in GitHub Desktop.
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
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