Commit 8801445c authored by Julian Andres Klode's avatar Julian Andres Klode
Browse files

Merge branch 'pu/tag-types' into 'master'

Improve type annotations for apt_pkg.TagFile and apt_pkg.TagSection

See merge request apt-team/python-apt!44
parents bf255700 e6f08afe
......@@ -68,7 +68,7 @@ class DebPackage(object):
self._debfile = cast(apt_inst.DebFile, None)
self.pkgname = ""
self.filename = None # type: Optional[str]
self._sections = {} # type: Union[Dict[str, str], apt_pkg.TagSection]
self._sections = {} # type: Union[Dict[str, str], apt_pkg.TagSection[str]] # noqa
self._need_pkgs = [] # type: List[str]
self._check_was_run = False
self._failure_string = ""
......@@ -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(): # type: ignore
for tag in sec.keys():
if tag in sec:
self._sections[tag] = sec[tag]
finally:
......
......@@ -422,7 +422,7 @@ class Record(Mapping[Any, Any]):
def __iter__(self):
# type: () -> Iterator[str]
return iter(self._rec.keys()) # type: ignore
return iter(self._rec.keys())
def iteritems(self):
# type: () -> Iterable[Tuple[object, str]]
......@@ -431,7 +431,7 @@ class Record(Mapping[Any, Any]):
yield key, self._rec[key]
def get(self, key, default=None):
# type: (object, object) -> object
# type: (str, object) -> object
"""Return record[key] if key in record, else *default*.
The parameter *default* must be either a string or None.
......
......@@ -140,15 +140,27 @@ class PackageFile:
size: int
version: str
class TagFile(Iterator[TagSection]):
def __init__(self, file: object, bytes: bool=False) -> None: ...
def __iter__(self) -> Iterator[TagSection]: ...
def __next__(self) -> TagSection: ...
class TagSection(Mapping[object, object]):
def __init__(self, str: Union[bytes, str]) -> None: ...
def __getitem__(self, key: object) -> str: ...
def get(self, key: object, default: Optional[object] = None) -> str: ...
class TagFile(Iterator[TagSection[AnyStr]]):
@overload
def __new__(cls, file: object) -> TagFile[str]: ...
@overload
def __new__(cls, file: object, bytes: Literal[True]) -> TagFile[bytes]: ...
@overload
def __new__(cls, file: object, bytes: Literal[False]) -> TagFile[str]: ...
def __iter__(self) -> Iterator[TagSection[AnyStr]]: ...
def __next__(self) -> TagSection[AnyStr]: ...
class TagSection(Mapping[str, AnyStr]):
@overload
def __new__(cls, str: Union[str, bytes]) -> TagSection[str]: ...
@overload
def __new__(cls, str: Union[str, bytes], bytes: Literal[True]) -> TagSection[bytes]: ...
@overload
def __new__(cls, str: Union[str, bytes], bytes: Literal[False]) -> TagSection[str]: ...
def __getitem__(self, key: str) -> AnyStr: ...
def get(self, key: str, default: Optional[object] = None) -> AnyStr: ...
def find(self, key: str, default: Optional[object] = None) -> AnyStr: ...
def find_raw(self, key: str, default: Optional[object] = None) -> AnyStr: ...
def __contains__(self, key: object) -> bool: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[str]: ...
......
Supports Markdown
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