<jupyter_start><jupyter_text>Initialize an `Item` object with correct values<jupyter_code>item = Item(sku="item-sku", quantity=1)
logging.info("item: %s", item)<jupyter_output>INFO:root:item: Item(sku='item-sku', quantity=1)<jupyter_text>Pass an invalid `sku`<jupyter_code>logging.info(vars(Item)["sku"].validate("asdf"))
Item(sku="sku", quantity=1)<jupyter_output><empty_output><jupyter_text>Pass an invalid `quantity`<jupyter_code>Item(sku="item-sku", quantity=-1)<jupyter_output><empty_output><jupyter_text>Now we have a class that validates its inputs and can be easily serialized to a dict.<jupyter_code>item = Item(sku="item-sku", quantity=2)
logging.info(asdict(item))
class DataDescriptor:
    def __get__(self, obj: Any, objtype=None) -> str:
        """Attribute access method.
        
        :param Any obj: Instance of attribute being accessed.
        :param Any objtype: Class of instance being accessed.
        :return: Value stored in private attribute.
        """
        return getattr(obj, '_data')
    
    def __set__(self, obj: Any, value: str) -> None:
        """Attribute assign method.
        
        :param Any obj: Instance of attribute being assigned.
        :param str value: Value being assigned to attribute.
        """
        setattr(obj, '_data', value)

class NonDataDescriptor:
    def __get__(self, obj: Any, objtype=None) -> str:
        """Attribute access method.
        
        :param Any obj: Instance of attribute being accessed.
        :param Any objtype: Class of instance being accessed.
        :return: Value stored in private attribute.
        """
        return "An on demand value"

class User:
    name: str = DataDescriptor()
    email: str = NonDataDescriptor()
    
    
    def __init__(self):
        # non-data descriptor is overriden
        self.email = "<EMAIL>"
        # data descriptor is called
        self.name = '<NAME>'
user = User()
user.name<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11713554987212277, 'fraction_numerical': 0.0025575447570332483, 'mean_word_length': 3.356347438752784, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '222464', 'license': 'MIT', 'n_tokens_mistral': 598, 'n_tokens_neox': 596, 'n_words': 170, 'path': 'dataclasses/dataclasses_and_descriptors.ipynb', 'repo_name': 'rmcomplexity/sample-notebooks', 'size': '1964'}