summaryrefslogtreecommitdiff
path: root/scalarfloat.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2023-05-01 19:13:50 +0200
committerAnthon van der Neut <anthon@mnt.org>2023-05-01 19:13:50 +0200
commit8b731994b1543d7886af85f926d9eea5a22d0732 (patch)
tree3553d4cbc80b541484d7a3f39e00cdcfd8f9d030 /scalarfloat.py
parent45111ba0b67e8619265d89f3202635e62c13cde6 (diff)
downloadruamel.yaml-8b731994b1543d7886af85f926d9eea5a22d0732.tar.gz
retrofitted 0.18 changes
Diffstat (limited to 'scalarfloat.py')
-rw-r--r--scalarfloat.py53
1 files changed, 16 insertions, 37 deletions
diff --git a/scalarfloat.py b/scalarfloat.py
index b9f8bdf..d3fe12e 100644
--- a/scalarfloat.py
+++ b/scalarfloat.py
@@ -3,15 +3,13 @@
import sys
from ruamel.yaml.anchor import Anchor
-if False: # MYPY
- from typing import Text, Any, Dict, List # NOQA
+from typing import Text, Any, Dict, List # NOQA
__all__ = ['ScalarFloat', 'ExponentialFloat', 'ExponentialCapsFloat']
class ScalarFloat(float):
- def __new__(cls, *args, **kw):
- # type: (Any, Any, Any) -> Any
+ def __new__(cls: Any, *args: Any, **kw: Any) -> Any:
width = kw.pop('width', None)
prec = kw.pop('prec', None)
m_sign = kw.pop('m_sign', None)
@@ -34,24 +32,21 @@ class ScalarFloat(float):
v.yaml_set_anchor(anchor, always_dump=True)
return v
- def __iadd__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __iadd__(self, a: Any) -> Any: # type: ignore
return float(self) + a
x = type(self)(self + a)
x._width = self._width
x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
return x
- def __ifloordiv__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __ifloordiv__(self, a: Any) -> Any: # type: ignore
return float(self) // a
x = type(self)(self // a)
x._width = self._width
x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
return x
- def __imul__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __imul__(self, a: Any) -> Any: # type: ignore
return float(self) * a
x = type(self)(self * a)
x._width = self._width
@@ -59,16 +54,14 @@ class ScalarFloat(float):
x._prec = self._prec # check for others
return x
- def __ipow__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __ipow__(self, a: Any) -> Any: # type: ignore
return float(self) ** a
x = type(self)(self ** a)
x._width = self._width
x._underscore = self._underscore[:] if self._underscore is not None else None # NOQA
return x
- def __isub__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __isub__(self, a: Any) -> Any: # type: ignore
return float(self) - a
x = type(self)(self - a)
x._width = self._width
@@ -76,49 +69,35 @@ class ScalarFloat(float):
return x
@property
- def anchor(self):
- # type: () -> Any
+ def anchor(self) -> Any:
if not hasattr(self, Anchor.attrib):
setattr(self, Anchor.attrib, Anchor())
return getattr(self, Anchor.attrib)
- def yaml_anchor(self, any=False):
- # type: (bool) -> Any
+ def yaml_anchor(self, any: bool = False) -> Any:
if not hasattr(self, Anchor.attrib):
return None
if any or self.anchor.always_dump:
return self.anchor
return None
- def yaml_set_anchor(self, value, always_dump=False):
- # type: (Any, bool) -> None
+ def yaml_set_anchor(self, value: Any, always_dump: bool = False) -> None:
self.anchor.value = value
self.anchor.always_dump = always_dump
- def dump(self, out=sys.stdout):
- # type: (Any) -> Any
+ def dump(self, out: Any = sys.stdout) -> None:
out.write(
- 'ScalarFloat({}| w:{}, p:{}, s:{}, lz:{}, _:{}|{}, w:{}, s:{})\n'.format(
- self,
- self._width, # type: ignore
- self._prec, # type: ignore
- self._m_sign, # type: ignore
- self._m_lead0, # type: ignore
- self._underscore, # type: ignore
- self._exp, # type: ignore
- self._e_width, # type: ignore
- self._e_sign, # type: ignore
- )
+ f'ScalarFloat({self}| w:{self._width}, p:{self._prec}, ' # type: ignore
+ f's:{self._m_sign}, lz:{self._m_lead0}, _:{self._underscore}|{self._exp}'
+ f', w:{self._e_width}, s:{self._e_sign})\n'
)
class ExponentialFloat(ScalarFloat):
- def __new__(cls, value, width=None, underscore=None):
- # type: (Any, Any, Any) -> Any
+ def __new__(cls, value: Any, width: Any = None, underscore: Any = None) -> Any:
return ScalarFloat.__new__(cls, value, width=width, underscore=underscore)
class ExponentialCapsFloat(ScalarFloat):
- def __new__(cls, value, width=None, underscore=None):
- # type: (Any, Any, Any) -> Any
+ def __new__(cls, value: Any, width: Any = None, underscore: Any = None) -> Any:
return ScalarFloat.__new__(cls, value, width=width, underscore=underscore)