Skip to content

Commit

Permalink
Merge pull request #225 from jaraco/feature/functools-wraps
Browse files Browse the repository at this point in the history
Replace typing overloads with a functools.wraps declaration.
  • Loading branch information
jaraco authored Jul 26, 2024
2 parents 04cdd83 + 638a6b8 commit 00b04b7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 98 deletions.
1 change: 1 addition & 0 deletions newsfragments/225.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replaced 'open' overloads with 'functools.wraps(open)' for simple re-use.
99 changes: 1 addition & 98 deletions path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,8 @@
with contextlib.suppress(ImportError):
import grp

from io import (
BufferedRandom,
BufferedReader,
BufferedWriter,
FileIO,
TextIOWrapper,
)
from typing import (
IO,
TYPE_CHECKING,
Any,
BinaryIO,
Callable,
Iterator,
overload,
Expand All @@ -71,12 +61,8 @@
if TYPE_CHECKING:
from _typeshed import (
OpenBinaryMode,
OpenBinaryModeReading,
OpenBinaryModeUpdating,
OpenBinaryModeWriting,
OpenTextMode,
)
from typing_extensions import Literal

from . import classes, masks, matchers
from .compat.py38 import removeprefix, removesuffix
Expand Down Expand Up @@ -689,90 +675,7 @@ def iglob(self, pattern):
#
# --- Reading or writing an entire file at once.

@overload
def open(
self,
mode: OpenTextMode = ...,
buffering: int = ...,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
closefd: bool = ...,
opener: Callable[[str, int], int] | None = ...,
) -> TextIOWrapper: ...

@overload
def open(
self,
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
closefd: bool = ...,
opener: Callable[[str, int], int] = ...,
) -> FileIO: ...

@overload
def open(
self,
mode: OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = ...,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
closefd: bool = ...,
opener: Callable[[str, int], int] = ...,
) -> BufferedRandom: ...

@overload
def open(
self,
mode: OpenBinaryModeReading,
buffering: Literal[-1, 1] = ...,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
closefd: bool = ...,
opener: Callable[[str, int], int] = ...,
) -> BufferedReader: ...

@overload
def open(
self,
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = ...,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
closefd: bool = ...,
opener: Callable[[str, int], int] = ...,
) -> BufferedWriter: ...

@overload
def open(
self,
mode: OpenBinaryMode,
buffering: int,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
closefd: bool = ...,
opener: Callable[[str, int], int] = ...,
) -> BinaryIO: ...

@overload
def open(
self,
mode: str,
buffering: int = ...,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
closefd: bool = ...,
opener: Callable[[str, int], int] = ...,
) -> IO[Any]: ...

@functools.wraps(open, assigned=())
def open(self, *args, **kwargs):
"""Open this file and return a corresponding file object.
Expand Down

0 comments on commit 00b04b7

Please sign in to comment.