comparison env/lib/python3.7/site-packages/ruamel/yaml/scalarfloat.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 # coding: utf-8
2
3 from __future__ import print_function, absolute_import, division, unicode_literals
4
5 import sys
6 from .compat import no_limit_int # NOQA
7 from ruamel.yaml.anchor import Anchor
8
9 if False: # MYPY
10 from typing import Text, Any, Dict, List # NOQA
11
12 __all__ = ['ScalarFloat', 'ExponentialFloat', 'ExponentialCapsFloat']
13
14
15 class ScalarFloat(float):
16 def __new__(cls, *args, **kw):
17 # type: (Any, Any, Any) -> Any
18 width = kw.pop('width', None) # type: ignore
19 prec = kw.pop('prec', None) # type: ignore
20 m_sign = kw.pop('m_sign', None) # type: ignore
21 m_lead0 = kw.pop('m_lead0', 0) # type: ignore
22 exp = kw.pop('exp', None) # type: ignore
23 e_width = kw.pop('e_width', None) # type: ignore
24 e_sign = kw.pop('e_sign', None) # type: ignore
25 underscore = kw.pop('underscore', None) # type: ignore
26 anchor = kw.pop('anchor', None) # type: ignore
27 v = float.__new__(cls, *args, **kw) # type: ignore
28 v._width = width
29 v._prec = prec
30 v._m_sign = m_sign
31 v._m_lead0 = m_lead0
32 v._exp = exp
33 v._e_width = e_width
34 v._e_sign = e_sign
35 v._underscore = underscore
36 if anchor is not None:
37 v.yaml_set_anchor(anchor, always_dump=True)
38 return v
39
40 def __iadd__(self, a): # type: ignore
41 # type: (Any) -> Any
42 return float(self) + a
43 x = type(self)(self + a)
44 x._width = self._width
45 x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
46 return x
47
48 def __ifloordiv__(self, a): # type: ignore
49 # type: (Any) -> Any
50 return float(self) // a
51 x = type(self)(self // a)
52 x._width = self._width
53 x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
54 return x
55
56 def __imul__(self, a): # type: ignore
57 # type: (Any) -> Any
58 return float(self) * a
59 x = type(self)(self * a)
60 x._width = self._width
61 x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
62 x._prec = self._prec # check for others
63 return x
64
65 def __ipow__(self, a): # type: ignore
66 # type: (Any) -> Any
67 return float(self) ** a
68 x = type(self)(self ** a)
69 x._width = self._width
70 x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
71 return x
72
73 def __isub__(self, a): # type: ignore
74 # type: (Any) -> Any
75 return float(self) - a
76 x = type(self)(self - a)
77 x._width = self._width
78 x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
79 return x
80
81 @property
82 def anchor(self):
83 # type: () -> Any
84 if not hasattr(self, Anchor.attrib):
85 setattr(self, Anchor.attrib, Anchor())
86 return getattr(self, Anchor.attrib)
87
88 def yaml_anchor(self, any=False):
89 # type: (bool) -> Any
90 if not hasattr(self, Anchor.attrib):
91 return None
92 if any or self.anchor.always_dump:
93 return self.anchor
94 return None
95
96 def yaml_set_anchor(self, value, always_dump=False):
97 # type: (Any, bool) -> None
98 self.anchor.value = value
99 self.anchor.always_dump = always_dump
100
101 def dump(self, out=sys.stdout):
102 # type: (Any) -> Any
103 out.write(
104 'ScalarFloat({}| w:{}, p:{}, s:{}, lz:{}, _:{}|{}, w:{}, s:{})\n'.format(
105 self,
106 self._width, # type: ignore
107 self._prec, # type: ignore
108 self._m_sign, # type: ignore
109 self._m_lead0, # type: ignore
110 self._underscore, # type: ignore
111 self._exp, # type: ignore
112 self._e_width, # type: ignore
113 self._e_sign, # type: ignore
114 )
115 )
116
117
118 class ExponentialFloat(ScalarFloat):
119 def __new__(cls, value, width=None, underscore=None):
120 # type: (Any, Any, Any) -> Any
121 return ScalarFloat.__new__(cls, value, width=width, underscore=underscore)
122
123
124 class ExponentialCapsFloat(ScalarFloat):
125 def __new__(cls, value, width=None, underscore=None):
126 # type: (Any, Any, Any) -> Any
127 return ScalarFloat.__new__(cls, value, width=width, underscore=underscore)