1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-31 04:58:12 +00:00

'Refactored by Sourcery'

This commit is contained in:
Sourcery AI 2022-06-25 10:51:16 +00:00
parent 72df282684
commit e0032900a6
5 changed files with 24 additions and 26 deletions

View file

@ -79,7 +79,10 @@ copyright = '2022 - Present, VarMonke & sudosnok'
version = ''
with open('../github/__init__.py') as f:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1) # type: ignore
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE
)[1]
# The full version, including alpha/beta/rc tags.
release = version
@ -165,9 +168,10 @@ resource_links = {
'discord': 'https://discord.gg/W2SDTtMrZA',
'issues': 'https://github.com/VarMonke/Github-Api-Wrapper/issues',
'discussions': 'https://github.com/VarMonke/Github-Api-Wrapper/discussions',
'examples': f'https://github.com/VarMonke/Github-Api-Wrapper/examples',
'examples': 'https://github.com/VarMonke/Github-Api-Wrapper/examples',
}
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.

View file

@ -27,9 +27,10 @@ class DPYStandaloneHTMLBuilder(StandaloneHTMLBuilder):
# the total count of lines for each index letter, used to distribute
# the entries into two columns
genindex = IndexEntries(self.env).create_index(self, group_entries=False) # type: ignore
indexcounts = []
for _k, entries in genindex:
indexcounts.append(sum(1 + len(subitems) for _, (_, subitems, _) in entries))
indexcounts = [
sum(1 + len(subitems) for _, (_, subitems, _) in entries)
for _k, entries in genindex
]
genindexcontext = {
'genindexentries': genindex,

View file

@ -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

View file

@ -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

View file

@ -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 (