From ed345dfb9f26ad2ae9e468334793de28978ba088 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Wed, 15 Apr 2020 13:22:43 +0200 Subject: [PATCH] Fix errors in type annotations (#86) * Fix errors in type annotations * Fix more type annotations --- tomlkit/_utils.py | 1 + tomlkit/items.py | 24 ++++++++++++++---------- tomlkit/source.py | 6 ++++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tomlkit/_utils.py b/tomlkit/_utils.py index 2fde721f..cb630c98 100644 --- a/tomlkit/_utils.py +++ b/tomlkit/_utils.py @@ -4,6 +4,7 @@ from datetime import datetime from datetime import time from datetime import timedelta +from typing import Union from ._compat import decode diff --git a/tomlkit/items.py b/tomlkit/items.py index 999da2f1..42809f73 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -201,7 +201,9 @@ class Key: A key value. """ - def __init__(self, k, t=None, sep=None, dotted=False): # type: (str) -> None + def __init__( + self, k, t=None, sep=None, dotted=False + ): # type: (str, Optional[KeyType], Optional[str], bool) -> None if t is None: if any( [c not in string.ascii_letters + string.digits + "-" + "_" for c in k] @@ -545,7 +547,7 @@ def __new__( trivia, raw, **kwargs - ): # type: (int, int, int, int, int, int, int, ..., Trivia, ...) -> datetime + ): # type: (int, int, int, int, int, int, int, Optional[datetime.tzinfo], Trivia, str, Any) -> datetime return datetime.__new__( cls, year, @@ -561,7 +563,7 @@ def __new__( def __init__( self, year, month, day, hour, minute, second, microsecond, tzinfo, trivia, raw - ): # type: (int, int, int, int, int, int, int, ..., Trivia) -> None + ): # type: (int, int, int, int, int, int, int, Optional[datetime.tzinfo], Trivia, str) -> None super(DateTime, self).__init__(trivia) self._raw = raw @@ -650,7 +652,7 @@ class Date(Item, date): A date literal. """ - def __new__(cls, year, month, day, *_): # type: (int, int, int, ...) -> date + def __new__(cls, year, month, day, *_): # type: (int, int, int, Any) -> date return date.__new__(cls, year, month, day) def __init__( @@ -706,12 +708,12 @@ class Time(Item, time): def __new__( cls, hour, minute, second, microsecond, tzinfo, *_ - ): # type: (int, int, int, int, ...) -> time + ): # type: (int, int, int, int, Optional[datetime.tzinfo], Any) -> time return time.__new__(cls, hour, minute, second, microsecond, tzinfo) def __init__( self, hour, minute, second, microsecond, tzinfo, trivia, raw - ): # type: (int, int, int, int, Trivia, str) -> None + ): # type: (int, int, int, int, Optional[datetime.tzinfo], Trivia, str) -> None super(Time, self).__init__(trivia) self._raw = raw @@ -744,7 +746,9 @@ class Array(Item, list): An array literal """ - def __init__(self, value, trivia, multiline=False): # type: (list, Trivia) -> None + def __init__( + self, value, trivia, multiline=False + ): # type: (list, Trivia, bool) -> None super(Array, self).__init__(trivia) list.__init__( @@ -780,7 +784,7 @@ def as_string(self): # type: () -> str return s - def append(self, _item): # type: () -> None + def append(self, _item): # type: (Any) -> None if self._value: self._value.append(Whitespace(", ")) @@ -854,7 +858,7 @@ def __init__( is_super_table=False, name=None, display_name=None, - ): # type: (tomlkit.container.Container, Trivia, bool, ...) -> None + ): # type: (tomlkit.container.Container, Trivia, bool, bool, Optional[str], Optional[str]) -> None super(Table, self).__init__(trivia) self.name = name @@ -1235,7 +1239,7 @@ class AoT(Item, list): def __init__( self, body, name=None, parsed=False - ): # type: (List[Table], Optional[str]) -> None + ): # type: (List[Table], Optional[str], bool) -> None self.name = name self._body = [] self._parsed = parsed diff --git a/tomlkit/source.py b/tomlkit/source.py index 37c39797..cff2a578 100644 --- a/tomlkit/source.py +++ b/tomlkit/source.py @@ -4,8 +4,10 @@ import itertools from copy import copy +from typing import Any from typing import Optional from typing import Tuple +from typing import Type from ._compat import PY2 from ._compat import unicode @@ -116,7 +118,7 @@ def extract(self): # type: () -> unicode """ return self[self._marker : self._idx] - def inc(self, exception=None): # type: (Optional[ParseError.__class__]) -> bool + def inc(self, exception=None): # type: (Optional[Type[ParseError]]) -> bool """ Increments the parser if the end of the input has not been reached. Returns whether or not it was able to advance. @@ -172,7 +174,7 @@ def mark(self): # type: () -> None def parse_error( self, exception=ParseError, *args - ): # type: (ParseError.__class__, ...) -> ParseError + ): # type: (Type[ParseError], Any) -> ParseError """ Creates a generic "parse error" at the current position. """