Майстер Михаил (Севастополь) MetaPosition 17206
Санников Тимофей Владимирович 321 MetaPosition 16971
t1from inspect import get_annotationst1from inspect import get_annotations
22
3def fancy_print(self):3def fancy_print(self):
4    ans = []4    ans = []
5    for el in get_annotations(self.__class__).keys():5    for el in get_annotations(self.__class__).keys():
6        try:6        try:
7            ans.append(el + '=' + str(getattr(self, str(el))))7            ans.append(el + '=' + str(getattr(self, str(el))))
8        except Exception as e:8        except Exception as e:
9            pass9            pass
10    return ' '.join(ans)10    return ' '.join(ans)
1111
12class positioned(type):12class positioned(type):
1313
14    def __new__(cls, name, bases, dct):14    def __new__(cls, name, bases, dct):
1515
16        def __init__(self, *args, **kwargs):16        def __init__(self, *args, **kwargs):
17            self.__class__.__match_args__ = tuple([*get_annotations(self.__class__).keys()])17            self.__class__.__match_args__ = tuple([*get_annotations(self.__class__).keys()])
18            anotat = [*get_annotations(self.__class__).keys()]18            anotat = [*get_annotations(self.__class__).keys()]
19            for item in kwargs.items():19            for item in kwargs.items():
20                if item[0] in anotat:20                if item[0] in anotat:
21                    setattr(self, item[0], item[1])21                    setattr(self, item[0], item[1])
22            k = 022            k = 0
23            for i, el in enumerate(args):23            for i, el in enumerate(args):
24                while anotat[k] in kwargs.keys():24                while anotat[k] in kwargs.keys():
25                    k += 125                    k += 1
26                    if k == len(anotat):26                    if k == len(anotat):
27                        break27                        break
28                if k == len(anotat):28                if k == len(anotat):
29                    break29                    break
30                setattr(self, anotat[k], el)30                setattr(self, anotat[k], el)
31                k += 131                k += 1
32                if k == len(anotat):32                if k == len(anotat):
33                    break33                    break
34        dct['__str__'] = lambda self: fancy_print(self)34        dct['__str__'] = lambda self: fancy_print(self)
35        dct['__init__'] = __init__35        dct['__init__'] = __init__
36        return super().__new__(cls, name, bases, dct)36        return super().__new__(cls, name, bases, dct)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op