Skip to content

Commit

Permalink
work around issue 6112 in mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
AvdN committed Dec 28, 2018
1 parent 38f2586 commit 289b916
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
14 changes: 7 additions & 7 deletions comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def __len__(self):
return count


class CommentedMapKeysView(CommentedMapView, Set):
class CommentedMapKeysView(CommentedMapView, Set): # type: ignore
__slots__ = ()

@classmethod
Expand All @@ -589,7 +589,7 @@ def __iter__(self):
yield x


class CommentedMapItemsView(CommentedMapView, Set):
class CommentedMapItemsView(CommentedMapView, Set): # type: ignore
__slots__ = ()

@classmethod
Expand Down Expand Up @@ -629,14 +629,14 @@ def __iter__(self):
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
Expand Down Expand Up @@ -823,7 +823,7 @@ def _keys(self):

def __len__(self):
# type: () -> int
return ordereddict.__len__(self) # type: ignore
return ordereddict.__len__(self)

def __eq__(self, other):
# type: (Any) -> bool
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def to_unicode(s):

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]]
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 10 additions & 10 deletions constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ def construct_object(self, node, deep=False):
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:
Expand Down Expand Up @@ -1109,7 +1109,7 @@ def construct_yaml_int(self, node):
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,
Expand Down Expand Up @@ -1141,7 +1141,7 @@ def construct_yaml_int(self, node):
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,
Expand All @@ -1163,17 +1163,17 @@ def construct_yaml_int(self, node):
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:
Expand Down Expand Up @@ -1233,7 +1233,7 @@ def leading_zeros(v):
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,
Expand All @@ -1247,7 +1247,7 @@ def leading_zeros(v):
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,
Expand Down
2 changes: 1 addition & 1 deletion cyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(
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
)
Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def Xdump_all(self, documents, stream, _kw=enforce, transform=None):
"""
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(
Expand Down Expand Up @@ -501,7 +501,7 @@ def Xdump_all(self, documents, stream, _kw=enforce, transform=None):
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:
Expand Down Expand Up @@ -723,7 +723,7 @@ def compact(self, seq_seq=None, seq_map=None):

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
Expand Down
4 changes: 2 additions & 2 deletions reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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']

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 289b916

Please sign in to comment.