Skip to content

Commit

Permalink
Use protocols for shutils.copyfileobj() (#2291)
Browse files Browse the repository at this point in the history
See python/typing#564 for background.
  • Loading branch information
srittau authored and JelleZijlstra committed Jun 28, 2018
1 parent 7ebd609 commit 187aaac
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions stdlib/2and3/shutil.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sys

from typing import (
List, Iterable, Callable, Any, Tuple, Sequence, NamedTuple, IO,
AnyStr, Optional, Union, Set, TypeVar, overload, Type
AnyStr, Optional, Union, Set, TypeVar, overload, Type, Protocol
)

if sys.version_info >= (3, 6):
Expand Down Expand Up @@ -40,7 +40,16 @@ else:
class SpecialFileError(EnvironmentError): ...
class ExecError(EnvironmentError): ...

def copyfileobj(fsrc: IO[AnyStr], fdst: IO[AnyStr],
_S_co = TypeVar("_S_co", covariant=True)
_S_contra = TypeVar("_S_contra", contravariant=True)

class _Reader(Protocol[_S_co]):
def read(self, length: int) -> _S_co: ...

class _Writer(Protocol[_S_contra]):
def write(self, data: _S_contra) -> Any: ...

def copyfileobj(fsrc: _Reader[AnyStr], fdst: _Writer[AnyStr],
length: int = ...) -> None: ...

if sys.version_info >= (3,):
Expand Down

0 comments on commit 187aaac

Please sign in to comment.