VA

Size: a a a
VA

т
R
VA
R
т
т
R
VA
т
VA
VA
VA
VA
decos = {
'id': lambda x: x,
}
@decos['id']
def f(): pass
# SyntaxError: invalid syntaxdecos = {
'id': lambda x: x,
}
@decos['id']
def f(): pass
f
# <function f at ...>class D:
f = None
def __init__(self, name):
self.name = name
def __call__(self, *args, **kwargs):
# on the first call save the function
if self.f is None:
self.f = args[0]
return self
# on all the next calls call the function
print(f'hello from {self.name}!')
return self.f(*args, **kwargs)
# matrix multiplication logic
def __matmul__(self, other):
return lambda f: self(other(f))
# the second `@` is actually the matrix multiplication
@D('a') @D('b')
def f(): pass
f()
# hello from a!
# hello from b!
_ = lambda x: x
@_(D('a') @ D('b'))
def f(): pass
VA
VA
VA
# before 3.9:
from typing import List, Type
lst: List[int] = [1, 2, 3]
t: Type[int] = float
# from python 3.9:
lst: list[int] = [1, 2, 3]
t: type[int] = float
from typing import will become much shorter! Hooray! The next step would be to support int & str instead of Union[int, str].list[str]({1, 2, 3})
# [1, 2, 3]
isinstance([1, 2, 3], list[str])
# TypeError: isinstance() arg 2 cannot be a parameterized genericVA
list, tuple, int, str доступны и так, а вот расширенные типы (List[], Tuple[], Iterator[], ) не доступныт
VA