summaryrefslogtreecommitdiff
path: root/scalarint.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 /scalarint.py
parent45111ba0b67e8619265d89f3202635e62c13cde6 (diff)
downloadruamel.yaml-8b731994b1543d7886af85f926d9eea5a22d0732.tar.gz
retrofitted 0.18 changes
Diffstat (limited to 'scalarint.py')
-rw-r--r--scalarint.py55
1 files changed, 25 insertions, 30 deletions
diff --git a/scalarint.py b/scalarint.py
index 1572b0f..3a2603d 100644
--- a/scalarint.py
+++ b/scalarint.py
@@ -2,15 +2,13 @@
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__ = ['ScalarInt', 'BinaryInt', 'OctalInt', 'HexInt', 'HexCapsInt', 'DecimalInt']
class ScalarInt(int):
- def __new__(cls, *args, **kw):
- # type: (Any, Any, Any) -> Any
+ def __new__(cls: Any, *args: Any, **kw: Any) -> Any:
width = kw.pop('width', None)
underscore = kw.pop('underscore', None)
anchor = kw.pop('anchor', None)
@@ -21,8 +19,7 @@ class ScalarInt(int):
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
x = type(self)(self + a)
x._width = self._width # type: ignore
x._underscore = ( # type: ignore
@@ -30,8 +27,7 @@ class ScalarInt(int):
) # NOQA
return x
- def __ifloordiv__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __ifloordiv__(self, a: Any) -> Any: # type: ignore
x = type(self)(self // a)
x._width = self._width # type: ignore
x._underscore = ( # type: ignore
@@ -39,8 +35,7 @@ class ScalarInt(int):
) # NOQA
return x
- def __imul__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __imul__(self, a: Any) -> Any: # type: ignore
x = type(self)(self * a)
x._width = self._width # type: ignore
x._underscore = ( # type: ignore
@@ -48,8 +43,7 @@ class ScalarInt(int):
) # NOQA
return x
- def __ipow__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __ipow__(self, a: Any) -> Any: # type: ignore
x = type(self)(self ** a)
x._width = self._width # type: ignore
x._underscore = ( # type: ignore
@@ -57,8 +51,7 @@ class ScalarInt(int):
) # NOQA
return x
- def __isub__(self, a): # type: ignore
- # type: (Any) -> Any
+ def __isub__(self, a: Any) -> Any: # type: ignore
x = type(self)(self - a)
x._width = self._width # type: ignore
x._underscore = ( # type: ignore
@@ -67,35 +60,34 @@ class ScalarInt(int):
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
class BinaryInt(ScalarInt):
- def __new__(cls, value, width=None, underscore=None, anchor=None):
- # type: (Any, Any, Any, Any) -> Any
+ def __new__(
+ cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None
+ ) -> Any:
return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor)
class OctalInt(ScalarInt):
- def __new__(cls, value, width=None, underscore=None, anchor=None):
- # type: (Any, Any, Any, Any) -> Any
+ def __new__(
+ cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None
+ ) -> Any:
return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor)
@@ -106,22 +98,25 @@ class OctalInt(ScalarInt):
class HexInt(ScalarInt):
"""uses lower case (a-f)"""
- def __new__(cls, value, width=None, underscore=None, anchor=None):
- # type: (Any, Any, Any, Any) -> Any
+ def __new__(
+ cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None
+ ) -> Any:
return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor)
class HexCapsInt(ScalarInt):
"""uses upper case (A-F)"""
- def __new__(cls, value, width=None, underscore=None, anchor=None):
- # type: (Any, Any, Any, Any) -> Any
+ def __new__(
+ cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None
+ ) -> Any:
return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor)
class DecimalInt(ScalarInt):
"""needed if anchor"""
- def __new__(cls, value, width=None, underscore=None, anchor=None):
- # type: (Any, Any, Any, Any) -> Any
+ def __new__(
+ cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None
+ ) -> Any:
return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor)