mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-07-25 15:37:45 +00:00
'Refactored by Sourcery'
This commit is contained in:
parent
72df282684
commit
e0032900a6
5 changed files with 24 additions and 26 deletions
|
@ -130,11 +130,11 @@ class GHClient:
|
|||
if not self.has_started:
|
||||
raise exceptions.NotStarted
|
||||
if not as_dict:
|
||||
output: List[str] = []
|
||||
for key, value in self.http.session._rates._asdict().items(): # type: ignore
|
||||
output.append(f"{key} : {value}")
|
||||
return [
|
||||
f"{key} : {value}"
|
||||
for key, value in self.http.session._rates._asdict().items()
|
||||
]
|
||||
|
||||
return output
|
||||
|
||||
return self.http.session._rates # type: ignore
|
||||
|
||||
|
@ -188,16 +188,14 @@ class GHClient:
|
|||
@functools.wraps(func)
|
||||
async def wrapped(self: Self, *args: P.args, **kwargs: P.kwargs) -> Optional[Union[T, User, Repository]]:
|
||||
if type == 'user':
|
||||
obj = self._user_cache.get(kwargs.get('user'))
|
||||
if obj:
|
||||
if obj := self._user_cache.get(kwargs.get('user')):
|
||||
return obj
|
||||
|
||||
user: User = await func(self, *args, **kwargs) # type: ignore
|
||||
self._user_cache[kwargs.get("user")] = user
|
||||
return user
|
||||
if type == 'repo':
|
||||
obj = self._repo_cache.get(kwargs.get('repo'))
|
||||
if obj:
|
||||
if obj := self._repo_cache.get(kwargs.get('repo')):
|
||||
return obj
|
||||
|
||||
repo: Repository = await func(self, *args, **kwargs) # type: ignore
|
||||
|
|
|
@ -270,16 +270,13 @@ class http:
|
|||
async def create_gist(
|
||||
self, *, files: List['File'] = [], description: str = 'Default description', public: bool = False
|
||||
) -> Dict[str, Union[str, int]]:
|
||||
data = {}
|
||||
data['description'] = description
|
||||
data['public'] = public
|
||||
data['files'] = {}
|
||||
data = {'description': description, 'public': public, 'files': {}}
|
||||
for file in files:
|
||||
data['files'][file.filename] = {'filename': file.filename, 'content': file.read()} # helps editing the file
|
||||
data = json.dumps(data)
|
||||
_headers = dict(self.session.headers)
|
||||
result = await self.session.post(CREATE_GIST_URL, data=data, headers=_headers)
|
||||
if 201 == result.status:
|
||||
if result.status == 201:
|
||||
return await result.json()
|
||||
raise InvalidToken
|
||||
|
||||
|
|
|
@ -128,10 +128,10 @@ class User(_BaseUser):
|
|||
for key, value in keys.items():
|
||||
if '_at' in key and value is not None:
|
||||
setattr(self, key, dt_formatter(value))
|
||||
continue
|
||||
else:
|
||||
setattr(self, key, value)
|
||||
continue
|
||||
|
||||
continue
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'<{self.__class__.__name__} login: {self.login!r}, id: {self.id}, created_at: {self.created_at}>'
|
||||
|
@ -336,11 +336,10 @@ class Issue(APIObject):
|
|||
|
||||
if key == 'closed_by':
|
||||
setattr(self, key, User(value, self._http))
|
||||
continue
|
||||
|
||||
else:
|
||||
setattr(self, key, value)
|
||||
continue
|
||||
|
||||
continue
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
|
@ -511,11 +510,10 @@ class Organization(APIObject):
|
|||
continue
|
||||
if '_at' in key and value is not None:
|
||||
setattr(self, key, dt_formatter(value))
|
||||
continue
|
||||
|
||||
else:
|
||||
setattr(self, key, value)
|
||||
continue
|
||||
|
||||
continue
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue