June 2019
Beginner to intermediate
770 pages
19h 24m
English
For class hinting, we'll provide three pieces of information. We'll include a __class__ key that names the target class. The __args__ key will provide a sequence of positional argument values. A __kw__ key will provide a dictionary of keyword argument values. (We will not use the __jsonclass__ key; it's too long and doesn't seem Pythonic.) This will cover all the options of __init__().
Here's an encoder that follows this design:
def blog_encode(object: Any) -> Dict[str, Any]: if isinstance(object, datetime.datetime): return dict( __class__="datetime.datetime", __args__=[], __kw__=dict( year=object.year, month=object.month, day=object.day, hour=object.hour, minute=object.minute, second=object.second, ), ) elif isinstance ...
Read now
Unlock full access