Commit 79368c02 authored by Julian Andres Klode's avatar Julian Andres Klode

Adjust typing for mypy 0.660

parent 6b86569a
......@@ -806,7 +806,7 @@ class DscSrcPackage(DebPackage):
if 'Binary' in sec:
self.binaries = [b.strip() for b in
sec['Binary'].split(',')]
for tag in sec.keys():
for tag in sec.keys(): # type: ignore
if tag in sec:
self._sections[tag] = sec[tag]
finally:
......
......@@ -38,11 +38,10 @@ except ImportError:
from httplib import BadStatusLine # type: ignore
from urllib2 import HTTPError, urlopen # type: ignore
from collections import Mapping, Sequence
try:
from typing import (Any, Iterable, Iterator, List, Optional, Set,
Tuple, Union, no_type_check, overload)
Tuple, Union, no_type_check, overload, Mapping,
Sequence)
Any # pyflakes
Iterable # pyflakes
Iterator # pyflakes
......@@ -52,7 +51,25 @@ try:
Tuple # pyflakes
Union # pyflakes
overload # pyflakes
Sequence # pyflakes
except ImportError:
import collections
class GenericWrapper(object):
"""Takes a non-generic type and adds __getitem__"""
def __init__(self, value):
# type: (type) -> None
self.value = value
def __getitem__(self, key):
# type: (type) -> type
return self.value
List = GenericWrapper(list) # type: ignore
Mapping = GenericWrapper(collections.Mapping) # type: ignore
Sequence = GenericWrapper(collections.Sequence) # type: ignore
Any = None
def no_type_check(arg):
# type: (Any) -> Any
return arg
......@@ -239,7 +256,7 @@ class BaseDependency(object):
return self._dep.dep_type_untranslated == 'PreDepends'
class Dependency(list):
class Dependency(List[BaseDependency]):
"""Represent an Or-group of dependencies.
Attributes defined here:
......@@ -359,7 +376,7 @@ class Origin(object):
self.site, self.trusted)
class Record(Mapping):
class Record(Mapping[Any, Any]):
"""Record in a Packages file
Represent a record as stored in a Packages file. You can use this like
......@@ -401,10 +418,10 @@ class Record(Mapping):
def __iter__(self):
# type: () -> Iterator[str]
return iter(self._rec.keys())
return iter(self._rec.keys()) # type: ignore
def iteritems(self):
# type: () -> Iterable
# type: () -> Iterable[Tuple[object, str]]
"""An iterator over the (key, value) items of the record."""
for key in self._rec.keys():
yield key, self._rec[key]
......@@ -921,7 +938,7 @@ class Version(object):
return os.path.abspath(dsc)
class VersionList(Sequence):
class VersionList(Sequence[Version]):
"""Provide a mapping & sequence interface to all versions of a package.
This class can be used like a dictionary, where version strings are the
......
......@@ -16,7 +16,7 @@ def gettext(msg: str, domain: str) -> str: ...
@overload
def gettext(msg: str) -> str: ...
class Configuration(dict):
class Configuration(Mapping[str, str]):
def find_file(self, key: str, default: str="") -> str: ...
def find_dir(self, key: str, default: str="") -> str: ...
def dump(self) -> str: ...
......@@ -25,6 +25,9 @@ class Configuration(dict):
def set(self, key: str, value: str) -> None: ...
def value_list(self, key: str) -> List[str]: ...
def clear(self, root: object=None) -> None: ...
def __getitem__(self, key: str) -> str: ...
def __iter__(self) -> Iterator[str]: ...
def __len__(self) -> int: ...
config = Configuration()
......@@ -140,7 +143,7 @@ class TagFile(Iterator[TagSection]):
def __iter__(self) -> Iterator[TagSection]: ...
def __next__(self) -> TagSection: ...
class TagSection(Mapping):
class TagSection(Mapping[object, object]):
def __init__(self, str: Union[bytes, str]) -> None: ...
def __getitem__(self, key: object) -> str: ...
def __contains__(self, key: object) -> bool: ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment