py2dataclasses 3.14.112__py2-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ from __future__ import absolute_import
2
+ from .abc_utils import ABC
3
+ __all__ = ['dataclass',
4
+ 'field',
5
+ '_Field',
6
+ 'Field',
7
+ 'of',
8
+ 'FrozenInstanceError',
9
+ 'InitVar',
10
+ 'KW_ONLY',
11
+ 'MISSING',
12
+
13
+ # Helper functions.
14
+ 'fields',
15
+ 'asdict',
16
+ 'astuple',
17
+ 'make_dataclass',
18
+ 'replace',
19
+ 'is_dataclass',
20
+ #'_oneshot',
21
+ 'ABC',
22
+ '_dataclass_getstate',
23
+ '_dataclass_setstate',
24
+ # 'of_factory',
25
+ # 'of_typed',
26
+ # 'ann',
27
+ # 'IntField',
28
+ # 'typed'
29
+ ]
30
+
31
+
32
+ from .dataclasses import dataclass, field, _Field, FrozenInstanceError, InitVar, KW_ONLY, MISSING, fields, asdict, \
33
+ astuple, make_dataclass, replace, is_dataclass, of, \
34
+ _dataclass_getstate, _dataclass_setstate, Field # of_factory, of_typed, ann, IntField, typed
@@ -0,0 +1,45 @@
1
+ from abc import ABCMeta
2
+
3
+ import six
4
+
5
+
6
+ @six.add_metaclass(ABCMeta)
7
+ class ABC(object): pass
8
+
9
+
10
+ def update_abstractmethods(cls):
11
+ """Recalculate the set of abstract methods of an abstract class.
12
+
13
+ If a class has had one of its abstract methods implemented after the
14
+ class was created, the method will not be considered implemented until
15
+ this function is called. Alternatively, if a new abstract method has been
16
+ added to the class, it will only be considered an abstract method of the
17
+ class after this function is called.
18
+
19
+ This function should be called before any use is made of the class,
20
+ usually in class decorators that add methods to the subject class.
21
+
22
+ Returns cls, to allow usage as a class decorator.
23
+
24
+ If cls is not an instance of ABCMeta, does nothing.
25
+ """
26
+ if not hasattr(cls, '__abstractmethods__'):
27
+ # We check for __abstractmethods__ here because cls might by a C
28
+ # implementation or a python implementation (especially during
29
+ # testing), and we want to handle both cases.
30
+ return cls
31
+
32
+ abstracts = set()
33
+ # Check the existing abstract methods of the parents, keep only the ones
34
+ # that are not implemented.
35
+ for scls in cls.__bases__:
36
+ for name in getattr(scls, '__abstractmethods__', ()):
37
+ value = getattr(cls, name, None)
38
+ if getattr(value, "__isabstractmethod__", False):
39
+ abstracts.add(name)
40
+ # Also add any other newly added abstract methods.
41
+ for name, value in cls.__dict__.items():
42
+ if getattr(value, "__isabstractmethod__", False):
43
+ abstracts.add(name)
44
+ cls.__abstractmethods__ = frozenset(abstracts)
45
+ return cls
@@ -0,0 +1,57 @@
1
+
2
+
3
+ def is_descriptor(obj):
4
+ """Returns True if obj is a descriptor, False otherwise."""
5
+ return (
6
+ hasattr(obj, '__get__') or
7
+ hasattr(obj, '__set__') or
8
+ hasattr(obj, '__delete__'))
9
+
10
+ def type_qualname(o):
11
+ klass = o.__class__
12
+ return qualname(klass)
13
+
14
+ def qualname(o):
15
+ #return compute_qualname(o)
16
+ existing = getattr(o, "__qualname__", None)
17
+ if existing:
18
+ return existing
19
+
20
+ return _qualname(o)
21
+ def _qualname(o):
22
+ klass = o
23
+ module = klass.__module__
24
+ if module == '__builtin__':
25
+ return klass.__name__ # avoid outputs like '__builtin__.str'
26
+ return module + '.' + klass.__name__
27
+
28
+ import inspect
29
+
30
+ def compute_qualname(cls):
31
+ if hasattr(cls, "__qualname__"):
32
+ return cls.__qualname__
33
+
34
+ name = cls.__name__
35
+
36
+ frame = inspect.currentframe()
37
+ try:
38
+ frame = frame.f_back
39
+ parts = []
40
+
41
+ while frame:
42
+ code_name = frame.f_code.co_name
43
+ if code_name == '<module>':
44
+ break
45
+
46
+ if 'self' in frame.f_locals:
47
+ parts.append(frame.f_locals['self'].__class__.__name__)
48
+
49
+ parts.append(code_name)
50
+ parts.append('<locals>')
51
+ frame = frame.f_back
52
+
53
+ parts.reverse()
54
+ parts.append(name)
55
+ return ".".join(parts)
56
+ finally:
57
+ del frame