Игорь Стариков / idle sign
Видео выступления__annotations__
from __future__ import annotations
List
и list
и т.п.ABC
s, NamedTuple
Юкка Лехтосало |
Гвидо ван Россум |
Лукаш Ланга |
Иван Левкивский |
def add_me(arg1):
"""
:param int arg1:
:rtype: int
"""
return arg1 + arg1
def add_me_new(arg1: int) -> int:
return arg1 + arg1
def command(req: str, *, opt1: int = 10, opt2: bool = False):
...
lib.myfunc.argtypes = [c_char_p, c_int]
lib.myfunc.restype = c_char_p
myfunc = lib.myfunc
myfunc('some'.encode('utf-8'), 2019).decode('utf-8')
@lib.function
def myfunc(title: str, year: int) -> str:
...
myfunc('some', 2019)
from __future__ import annotations
from dataclasses import dataclass, field, asdict
@dataclass(frozen=True)
class MyClass:
my_num: int = 42
my_list: List[int] = field(default_factory=list)
my_cls = MyClass(1, my_list=[1, 2, 3])
asdict(my_cls)
import attr
from marshmallow_annotations import AnnotationSchema
@attr.s
class Album:
id: int = attr.ib()
name: str = attr.ib()
class AlbumScheme(AnnotationSchema):
class Meta:
target = Album
register_as_scheme = True
from datetime import datetime
from pydantic.dataclasses import dataclass
@dataclass
class User:
id: int
name: str = 'anonymous'
signup_ts: datetime = None
user = User(id='42', signup_ts='2032-06-21T12:00')
user.json()
user.dict()
* быстрее чем:
marshmallow — 1.9x; django-restful-framework — 16.0x
from auto_init import AutoInitContext
class Point:
x: int
y: int
z: int = None
ctx = AutoInitContext()
p: Point = ctx.get_instance(Point)
assert p.x == 0
assert p.y == 0
assert p.z is None
idlesign
idlesign
Эти слайды можно найти тут — bit.ly/ist_010