aboutsummaryrefslogtreecommitdiff
path: root/discord/file.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-06 08:15:51 -0400
committerRapptz <[email protected]>2021-05-06 08:15:51 -0400
commit2e12f6de9cd99a82faea370158689d79d23a9738 (patch)
tree28e5672049115aba0d6ea8064cd2529645c1c4cd /discord/file.py
parentFix various reference issues in documentation (diff)
downloaddiscord.py-2e12f6de9cd99a82faea370158689d79d23a9738.tar.xz
discord.py-2e12f6de9cd99a82faea370158689d79d23a9738.zip
Typehint File
Diffstat (limited to 'discord/file.py')
-rw-r--r--discord/file.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/discord/file.py b/discord/file.py
index 38c165d0..e6717ed2 100644
--- a/discord/file.py
+++ b/discord/file.py
@@ -22,13 +22,17 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
-import os.path
+from __future__ import annotations
+from typing import Optional, TYPE_CHECKING, Union
+
+import os
import io
__all__ = (
'File',
)
+
class File:
r"""A parameter object used for :meth:`abc.Messageable.send`
for sending file objects.
@@ -40,7 +44,7 @@ class File:
Attributes
-----------
- fp: Union[:class:`str`, :class:`io.BufferedIOBase`]
+ fp: Union[:class:`os.PathLike`, :class:`io.BufferedIOBase`]
A file-like object opened in binary mode and read mode
or a filename representing a file in the hard drive to
open.
@@ -62,9 +66,18 @@ class File:
__slots__ = ('fp', 'filename', 'spoiler', '_original_pos', '_owner', '_closer')
- def __init__(self, fp, filename=None, *, spoiler=False):
- self.fp = fp
-
+ if TYPE_CHECKING:
+ fp: io.BufferedIOBase
+ filename: Optional[str]
+ spoiler: bool
+
+ def __init__(
+ self,
+ fp: Union[str, bytes, os.PathLike, io.BufferedIOBase],
+ filename: Optional[str] = None,
+ *,
+ spoiler: bool = False,
+ ):
if isinstance(fp, io.IOBase):
if not (fp.seekable() and fp.readable()):
raise ValueError(f'File buffer {fp!r} must be seekable and readable')
@@ -96,7 +109,7 @@ class File:
self.spoiler = spoiler or (self.filename is not None and self.filename.startswith('SPOILER_'))
- def reset(self, *, seek=True):
+ def reset(self, *, seek: bool = True) -> None:
# The `seek` parameter is needed because
# the retry-loop is iterated over multiple times
# starting from 0, as an implementation quirk
@@ -108,7 +121,7 @@ class File:
if seek:
self.fp.seek(self._original_pos)
- def close(self):
+ def close(self) -> None:
self.fp.close = self._closer
if self._owner:
self._closer()