Skip to content

Commit

Permalink
short term fix super call implementations in boxsdk classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jheld committed Jan 30, 2024
1 parent 8678846 commit 16e85c0
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions diycrate/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from io import BufferedWriter
import threading
from typing import Iterable, List, Optional, Tuple
import typing

from boxsdk import OAuth2
from boxsdk.object.file_version import FileVersion
Expand All @@ -22,7 +23,8 @@ class User(boxsdk.object.user.User):
space_amount: float

def get(self, fields: Optional[List[str]] = None) -> "User":
...
ret = typing.cast("User", super().get(fields=fields)) # type: ignore
return ret


class Item(boxsdk.object.item.Item):
Expand All @@ -34,7 +36,8 @@ class Item(boxsdk.object.item.Item):
def get(
self, fields: Optional[List[str]] = None, etag: Optional[str] = None
) -> "Item":
...
ret = typing.cast("Item", super().get(fields=fields, etag=etag)) # type: ignore
return ret


class Folder(boxsdk.object.folder.Folder):
Expand All @@ -44,20 +47,25 @@ class Folder(boxsdk.object.folder.Folder):
object_id: str

def create_subfolder(self, folder_name: str) -> "Folder":
...
ret = typing.cast("Folder", super().create_subfolder(folder_name)) # type: ignore
return ret

def get(
self, fields: Optional[List[str]] = None, etag: Optional[str] = None
) -> "Folder":
...
ret = typing.cast(Folder, super().get(fields=fields, etag=etag)) # type: ignore
return ret

def get_items(
self, offset: Optional[int] = None, limit: Optional[int] = None
) -> Iterable[Item]:
...
items_kwargs = dict(offset=offset, limit=limit)
ret = typing.cast(Iterable[Item], super().get_items(**items_kwargs)) # type: ignore
return ret

def delete(self) -> bool:
...
ret = typing.cast(bool, super().delete()) # type: ignore
return ret


class File(boxsdk.object.file.File):
Expand All @@ -70,33 +78,46 @@ class File(boxsdk.object.file.File):
def get(
self, fields: Optional[List[str]] = None, etag: Optional[str] = None
) -> "File":
...
ret = typing.cast(File, super().get(fields=fields, etag=etag)) # type: ignore
return ret

def download_to(
self,
writeable_stream: BufferedWriter,
file_version: Optional[FileVersion] = None,
byte_range: Optional[Tuple[int, int]] = None,
) -> None:
...
func_kwargs = dict(
writeable_stream=writeable_stream,
file_version=file_version,
byte_range=byte_range,
)
ret = typing.cast(None, super().download_to(**func_kwargs)) # type: ignore
return ret

def delete(self) -> bool:
...
ret = typing.cast(bool, super().delete()) # type: ignore
return ret

def update_contents(self, **kwargs):
...
ret = typing.cast(None, super().update_contents(**kwargs)) # type: ignore
return ret


class Client(boxsdk.Client):
def user(self) -> User:
...
ret = typing.cast(User, super().user())
return ret

def folder(self, folder_id: str) -> Folder:
...
ret = typing.cast(Folder, super().folder(folder_id))
return ret

def file(self, file_id: str) -> File:
...
ret = typing.cast(File, super().folder(file_id))
return ret

@property
def auth(self) -> OAuth2:
...
ret = typing.cast(OAuth2, super().auth)
return ret

0 comments on commit 16e85c0

Please sign in to comment.