summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-12-28 10:50:40 +0100
committerAnthon van der Neut <anthon@mnt.org>2018-12-28 10:50:40 +0100
commit96cf5fdbbfec1902fcaeeb3ba6c75ccf92f1f2f7 (patch)
tree1f8f741f303b47ef8f3cc1b340c9af7d635d046d
parent25b7008eb7721763fe0ea10cc23abeed2c1ef780 (diff)
downloadruamel.yaml-96cf5fdbbfec1902fcaeeb3ba6c75ccf92f1f2f7.tar.gz
work around issue 6112 in mypy
-rw-r--r--comments.py14
-rw-r--r--compat.py5
-rw-r--r--constructor.py20
-rw-r--r--cyaml.py2
-rw-r--r--main.py6
-rw-r--r--reader.py4
6 files changed, 26 insertions, 25 deletions
diff --git a/comments.py b/comments.py
index 5068d84..b76f909 100644
--- a/comments.py
+++ b/comments.py
@@ -570,7 +570,7 @@ class CommentedMapView(Sized):
return count
-class CommentedMapKeysView(CommentedMapView, Set):
+class CommentedMapKeysView(CommentedMapView, Set): # type: ignore
__slots__ = ()
@classmethod
@@ -589,7 +589,7 @@ class CommentedMapKeysView(CommentedMapView, Set):
yield x
-class CommentedMapItemsView(CommentedMapView, Set):
+class CommentedMapItemsView(CommentedMapView, Set): # type: ignore
__slots__ = ()
@classmethod
@@ -629,14 +629,14 @@ class CommentedMapValuesView(CommentedMapView):
yield self._mapping[key]
-class CommentedMap(MutableMapping, ordereddict, CommentedBase):
+class CommentedMap(ordereddict, CommentedBase):
__slots__ = (Comment.attrib, '_ok', '_ref')
def __init__(self, *args, **kw):
# type: (Any, Any) -> None
self._ok = set() # type: MutableSet[Any] # own keys
self._ref = [] # type: List[CommentedMap]
- ordereddict.__init__(self, *args, **kw) # type: ignore
+ ordereddict.__init__(self, *args, **kw)
def _yaml_add_comment(self, comment, key=NoComment, value=NoComment):
# type: (Any, Optional[Any], Optional[Any]) -> None
@@ -823,7 +823,7 @@ class CommentedMap(MutableMapping, ordereddict, CommentedBase):
def __len__(self):
# type: () -> int
- return ordereddict.__len__(self) # type: ignore
+ return ordereddict.__len__(self)
def __eq__(self, other):
# type: (Any) -> bool
@@ -955,7 +955,7 @@ def raise_immutable(cls, *args, **kwargs):
raise TypeError('{} objects are immutable'.format(cls.__name__))
-class CommentedKeyMap(CommentedBase, Mapping):
+class CommentedKeyMap(CommentedBase, Mapping): # type: ignore
__slots__ = Comment.attrib, '_od'
"""This primarily exists to be able to roundtrip keys that are mappings"""
@@ -1052,7 +1052,7 @@ class CommentedOrderedMap(CommentedMap):
__slots__ = (Comment.attrib,)
-class CommentedSet(MutableSet, CommentedBase): # NOQA
+class CommentedSet(MutableSet, CommentedBase): # type: ignore # NOQA
__slots__ = Comment.attrib, 'odict'
def __init__(self, values=None):
diff --git a/compat.py b/compat.py
index 1786153..7355470 100644
--- a/compat.py
+++ b/compat.py
@@ -117,7 +117,8 @@ else:
if False: # MYPY
# StreamType = Union[BinaryIO, IO[str], IO[unicode], StringIO]
- StreamType = Union[BinaryIO, IO[str], StringIO]
+ # StreamType = Union[BinaryIO, IO[str], StringIO] # type: ignore
+ StreamType = Any
StreamTextType = Union[Text, StreamType]
VersionType = Union[List[int], str, Tuple[int, int]]
@@ -257,7 +258,7 @@ def version_tnf(t1, t2=None):
return False
-class MutableSliceableSequence(MutableSequence):
+class MutableSliceableSequence(MutableSequence): # type: ignore
__slots__ = ()
def __getitem__(self, index):
diff --git a/constructor.py b/constructor.py
index 6aef100..61ac4e9 100644
--- a/constructor.py
+++ b/constructor.py
@@ -155,11 +155,11 @@ class BaseConstructor(object):
elif None in self.yaml_constructors:
constructor = self.yaml_constructors[None]
elif isinstance(node, ScalarNode):
- constructor = self.__class__.construct_scalar # type: ignore
+ constructor = self.__class__.construct_scalar
elif isinstance(node, SequenceNode):
- constructor = self.__class__.construct_sequence # type: ignore
+ constructor = self.__class__.construct_sequence
elif isinstance(node, MappingNode):
- constructor = self.__class__.construct_mapping # type: ignore
+ constructor = self.__class__.construct_mapping
if tag_suffix is None:
data = constructor(self, node)
else:
@@ -1109,7 +1109,7 @@ class RoundTripConstructor(SafeConstructor):
if underscore is not None:
underscore[1] = value_su[2] == '_'
underscore[2] = len(value_su[2:]) > 1 and value_su[-1] == '_'
- return BinaryInt( # type: ignore
+ return BinaryInt(
sign * int(value_s[2:], 2),
width=width,
underscore=underscore,
@@ -1141,7 +1141,7 @@ class RoundTripConstructor(SafeConstructor):
if underscore is not None:
underscore[1] = value_su[2] == '_'
underscore[2] = len(value_su[2:]) > 1 and value_su[-1] == '_'
- return OctalInt( # type: ignore
+ return OctalInt(
sign * int(value_s[2:], 8),
width=width,
underscore=underscore,
@@ -1163,17 +1163,17 @@ class RoundTripConstructor(SafeConstructor):
if underscore is not None:
# cannot have a leading underscore
underscore[2] = len(value_su) > 1 and value_su[-1] == '_'
- return ScalarInt( # type: ignore
+ return ScalarInt(
sign * int(value_s), width=len(value_s), underscore=underscore
)
elif underscore:
# cannot have a leading underscore
underscore[2] = len(value_su) > 1 and value_su[-1] == '_'
- return ScalarInt( # type: ignore
+ return ScalarInt(
sign * int(value_s), width=None, underscore=underscore, anchor=node.anchor
)
elif node.anchor:
- return ScalarInt( # type: ignore
+ return ScalarInt(
sign * int(value_s), width=None, anchor=node.anchor
)
else:
@@ -1233,7 +1233,7 @@ class RoundTripConstructor(SafeConstructor):
e_width = len(exponent)
e_sign = exponent[0] in '+-'
# nprint('sf', width, prec, m_sign, exp, e_width, e_sign)
- return ScalarFloat( # type: ignore
+ return ScalarFloat(
sign * float(value_s),
width=width,
prec=prec,
@@ -1247,7 +1247,7 @@ class RoundTripConstructor(SafeConstructor):
width = len(value_so)
prec = value_so.index('.') # you can use index, this would not be float without dot
lead0 = leading_zeros(value_so)
- return ScalarFloat( # type: ignore
+ return ScalarFloat(
sign * float(value_s),
width=width,
prec=prec,
diff --git a/cyaml.py b/cyaml.py
index 3e013cb..7a808a5 100644
--- a/cyaml.py
+++ b/cyaml.py
@@ -136,7 +136,7 @@ class CSafeDumper(CEmitter, SafeRepresenter, Resolver): # type: ignore
version=version,
tags=tags,
)
- self._emitter = self._serializer = self._representer = self # type: ignore
+ self._emitter = self._serializer = self._representer = self
SafeRepresenter.__init__(
self, default_style=default_style, default_flow_style=default_flow_style
)
diff --git a/main.py b/main.py
index 851ae83..f06c52e 100644
--- a/main.py
+++ b/main.py
@@ -462,7 +462,7 @@ class YAML(object):
"""
if not hasattr(stream, 'write') and hasattr(stream, 'open'):
# pathlib.Path() instance
- with stream.open('w') as fp: # type: ignore
+ with stream.open('w') as fp:
return self.dump_all(documents, fp, _kw, transform=transform)
if _kw is not enforce:
raise TypeError(
@@ -501,7 +501,7 @@ class YAML(object):
delattr(self, '_serializer')
delattr(self, '_emitter')
if transform:
- val = stream.getvalue() # type: ignore
+ val = stream.getvalue()
if self.encoding:
val = val.decode(self.encoding)
if fstream is None:
@@ -723,7 +723,7 @@ class YAML(object):
class YAMLContextManager(object):
def __init__(self, yaml, transform=None):
- # type: (Any, Optional[Callable]) -> None
+ # type: (Any, Any) -> None # used to be: (Any, Optional[Callable]) -> None
self._yaml = yaml
self._output_inited = False
self._output_path = None
diff --git a/reader.py b/reader.py
index 233478b..b056a04 100644
--- a/reader.py
+++ b/reader.py
@@ -29,7 +29,7 @@ from ruamel.yaml.util import RegExp
if False: # MYPY
from typing import Any, Dict, Optional, List, Union, Text, Tuple, Optional # NOQA
- from ruamel.yaml.compat import StreamTextType # NOQA
+# from ruamel.yaml.compat import StreamTextType # NOQA
__all__ = ['Reader', 'ReaderError']
@@ -77,7 +77,7 @@ class Reader(object):
# Yeah, it's ugly and slow.
def __init__(self, stream, loader=None):
- # type: (StreamTextType, Any) -> None
+ # type: (Any, Any) -> None
self.loader = loader
if self.loader is not None and getattr(self.loader, '_reader', None) is None:
self.loader._reader = self