From 1e94fe210166e1206f3a4e9843ac47ba9e736ba6 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Sat, 25 Aug 2018 20:10:37 +0200 Subject: mypy update --- constructor.py | 20 ++++++++++---------- main.py | 18 +++++++++--------- scalarstring.py | 4 ++-- tokens.py | 19 +++++++++++-------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/constructor.py b/constructor.py index a7abaf3..008018a 100644 --- a/constructor.py +++ b/constructor.py @@ -1031,24 +1031,24 @@ class RoundTripConstructor(SafeConstructor): ) if node.style == '|' and isinstance(node.value, text_type): - pss = LiteralScalarString(node.value) + lss = LiteralScalarString(node.value) if node.comment and node.comment[1]: - pss.comment = node.comment[1][0] # type: ignore - return pss + lss.comment = node.comment[1][0] # type: ignore + return lss if node.style == '>' and isinstance(node.value, text_type): - fold_positions = [] - idx = None + fold_positions = [] # type: List[int] + idx = -1 while True: - idx = node.value.find('\a', None if idx is None else idx + 1) + idx = node.value.find('\a', idx + 1) if idx < 0: break fold_positions.append(idx - len(fold_positions)) - pss = FoldedScalarString(node.value.replace('\a', '')) + fss = FoldedScalarString(node.value.replace('\a', '')) if node.comment and node.comment[1]: - pss.comment = node.comment[1][0] # type: ignore + fss.comment = node.comment[1][0] # type: ignore if fold_positions: - pss.fold_pos = fold_positions - return pss + fss.fold_pos = fold_positions # type: ignore + return fss elif bool(self._preserve_quotes) and isinstance(node.value, text_type): if node.style == "'": return SingleQuotedScalarString(node.value) diff --git a/main.py b/main.py index 20d5f07..653ee1c 100644 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ from ruamel.yaml.nodes import * # NOQA from ruamel.yaml.loader import BaseLoader, SafeLoader, Loader, RoundTripLoader # NOQA from ruamel.yaml.dumper import BaseDumper, SafeDumper, Dumper, RoundTripDumper # NOQA -from ruamel.yaml.compat import StringIO, BytesIO, with_metaclass, PY3 +from ruamel.yaml.compat import StringIO, BytesIO, with_metaclass, PY3, nprint from ruamel.yaml.resolver import VersionedResolver, Resolver # NOQA from ruamel.yaml.representer import ( BaseRepresenter, @@ -163,7 +163,7 @@ class YAML(object): def reader(self): # type: () -> Any try: - return self._reader + return self._reader # type: ignore except AttributeError: self._reader = self.Reader(None, loader=self) return self._reader @@ -172,7 +172,7 @@ class YAML(object): def scanner(self): # type: () -> Any try: - return self._scanner + return self._scanner # type: ignore except AttributeError: self._scanner = self.Scanner(loader=self) return self._scanner @@ -323,11 +323,11 @@ class YAML(object): finally: parser.dispose() try: - self._reader.reset_reader() # type: ignore + self._reader.reset_reader() except AttributeError: pass try: - self._scanner.reset_scanner() # type: ignore + self._scanner.reset_scanner() except AttributeError: pass @@ -355,11 +355,11 @@ class YAML(object): finally: parser.dispose() try: - self._reader.reset_reader() # type: ignore + self._reader.reset_reader() except AttributeError: pass try: - self._scanner.reset_scanner() # type: ignore + self._scanner.reset_scanner() except AttributeError: pass @@ -653,11 +653,11 @@ class YAML(object): finally: parser.dispose() try: - self._reader.reset_reader() # type: ignore + self._reader.reset_reader() except AttributeError: pass try: - self._scanner.reset_scanner() # type: ignore + self._scanner.reset_scanner() except AttributeError: pass diff --git a/scalarstring.py b/scalarstring.py index 18dcc15..03db72d 100644 --- a/scalarstring.py +++ b/scalarstring.py @@ -13,9 +13,9 @@ __all__ = [ 'FoldedScalarString', 'SingleQuotedScalarString', 'DoubleQuotedScalarString', - # PreservedScalarString is the old name, as it was the first to be preserved on rt, + # PreservedScalarString is the old name, as it was the first to be preserved on rt, # use LiteralScalarString instead - 'PreservedScalarString', + 'PreservedScalarString', ] diff --git a/tokens.py b/tokens.py index 5176520..4dd0c1d 100644 --- a/tokens.py +++ b/tokens.py @@ -1,8 +1,11 @@ # # header # coding: utf-8 +from __future__ import unicode_literals + if False: # MYPY - from typing import Any, Dict, Optional, List # NOQA + from typing import Text, Any, Dict, Optional, List # NOQA + from .error import StreamMark # NOQA SHOWLINES = True @@ -11,7 +14,7 @@ class Token(object): __slots__ = 'start_mark', 'end_mark', '_comment' def __init__(self, start_mark, end_mark): - # type: (Any, Any) -> None + # type: (StreamMark, StreamMark) -> None self.start_mark = start_mark self.end_mark = end_mark @@ -21,17 +24,17 @@ class Token(object): # hasattr('self', key)] attributes = [key for key in self.__slots__ if not key.endswith('_mark')] attributes.sort() - arguments = u', '.join([u'%s=%r' % (key, getattr(self, key)) for key in attributes]) + arguments = ', '.join(['%s=%r' % (key, getattr(self, key)) for key in attributes]) if SHOWLINES: try: - arguments += u', line: ' + str(self.start_mark.line) + arguments += ', line: ' + str(self.start_mark.line) except: # NOQA pass try: - arguments += u', comment: ' + str(self._comment) + arguments += ', comment: ' + str(self._comment) except: # NOQA pass - return u'{}({})'.format(self.__class__.__name__, arguments) + return '{}({})'.format(self.__class__.__name__, arguments) def add_post_comment(self, comment): # type: (Any) -> None @@ -259,10 +262,10 @@ class CommentToken(Token): def __repr__(self): # type: () -> Any - v = u'{!r}'.format(self.value) + v = '{!r}'.format(self.value) if SHOWLINES: try: - v += u', line: ' + str(self.start_mark.line) + v += ', line: ' + str(self.start_mark.line) except: # NOQA pass return 'CommentToken({})'.format(v) -- cgit v1.2.1