Skip to content

Commit

Permalink
Fix the fallout of the mypy 0.790 release
Browse files Browse the repository at this point in the history
  • Loading branch information
ntninja committed Oct 14, 2020
1 parent 793899e commit ba421f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions ipfshttpclient/filescanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import re
import sys
import types
import typing as ty

from . import utils
Expand Down Expand Up @@ -511,7 +512,7 @@ def __init__(
#
# Note: `os.fwalk` support for binary paths was only added in 3.7+.
directory_str_or_fd = directory_str # type: ty.Union[ty.AnyStr, int]
if HAVE_FWALK and (not isinstance(directory_str, bytes) or HAVE_FWALK_BYTES):
if HAVE_FWALK and (not isinstance(directory_str, bytes) or HAVE_FWALK_BYTES): # type: ignore[unreachable] # noqa: E501
self._close_fd = directory_str_or_fd = os.open(directory_str, os.O_RDONLY | O_DIRECTORY)

self._generator = self._walk(
Expand All @@ -533,10 +534,24 @@ def __exit__(self, *a: ty.Any) -> None:
def send(self, value: ty.Any) -> FSNodeEntry:
return self._generator.send(value)

def throw(self, typ: ty.Type[BaseException], val: ty.Optional[BaseException] = None,
tb: ty.Any = None) -> FSNodeEntry:
@ty.overload
def throw(self, typ: ty.Type[BaseException], # noqa: E704
val: ty.Union[BaseException, object] = ...,
tb: ty.Optional[types.TracebackType] = ...) -> FSNodeEntry: ...

@ty.overload
def throw(self, typ: BaseException, val: None = ..., # noqa: E704
tb: ty.Optional[types.TracebackType] = ...) -> FSNodeEntry: ...

def throw(self, typ: ty.Union[ty.Type[BaseException], BaseException],
val: ty.Union[BaseException, object] = None,
tb: ty.Optional[types.TracebackType] = None) -> FSNodeEntry:
try:
return self._generator.throw(typ, val, tb)
if isinstance(typ, type):
return self._generator.throw(typ, val, tb)
else:
assert val is None
return self._generator.throw(typ, val, tb)
except:
if self._close_fd is not None:
os.close(self._close_fd)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ commands =
[testenv:typeck]
skip_install = true
deps =
mypy ~= 0.782
mypy ~= 0.790
pytest ~= 5.0
{[testenv:py3-httpx]deps-exclusive}
commands =
Expand Down

0 comments on commit ba421f9

Please sign in to comment.