Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in type annotations #86

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tomlkit/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime
from datetime import time
from datetime import timedelta
from typing import Union


from ._compat import decode
Expand Down
24 changes: 14 additions & 10 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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(", "))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tomlkit/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
"""
Expand Down