From 0e10906a28f9f77cec0a22244158b3c929373fc5 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Mon, 2 Mar 2020 01:25:43 +0100 Subject: [PATCH 1/2] Fix errors in type annotations --- tomlkit/items.py | 24 ++++++++++++++---------- tomlkit/source.py | 4 +++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tomlkit/items.py b/tomlkit/items.py index 8399d0c3..dc4b93de 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__( @@ -792,7 +796,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(", ")) @@ -869,7 +873,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 @@ -1250,7 +1254,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..1f1bf675 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 @@ -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. """ From 1a8df01f4669440a14804af4affc45bd51df09e0 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Mon, 2 Mar 2020 01:42:22 +0100 Subject: [PATCH 2/2] Fix more type annotations --- tomlkit/_utils.py | 1 + tomlkit/source.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tomlkit/_utils.py b/tomlkit/_utils.py index 0a68be9f..494b9ab6 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/source.py b/tomlkit/source.py index 1f1bf675..cff2a578 100644 --- a/tomlkit/source.py +++ b/tomlkit/source.py @@ -118,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.