Skip to content

Commit

Permalink
style: fix ruff check errors
Browse files Browse the repository at this point in the history
  • Loading branch information
y-young committed Apr 6, 2024
1 parent 01b5512 commit be992ac
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion nazurin/database/firebase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Optional

import firebase_admin
from firebase_admin import credentials, firestore_async
Expand Down Expand Up @@ -33,7 +34,7 @@ def document(self, key=None):
self._document = self._collection.document(str(key))
return self

async def list(self, page_size: int = None):
async def list(self, page_size: Optional[int] = None):
return self._collection.list_documents(page_size)

async def get(self):
Expand Down
2 changes: 1 addition & 1 deletion nazurin/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def on_pre_process_message(self, message: Message, _data: dict):
allowed_chats = config.ALLOW_ID + config.ALLOW_GROUP + [config.ADMIN_ID]
if (
message.chat.id in allowed_chats
or message.from_user.id in config.ALLOW_ID + [config.ADMIN_ID]
or message.from_user.id in [*config.ALLOW_ID, config.ADMIN_ID]
or message.from_user.username in config.ALLOW_USERNAME
):
return
Expand Down
2 changes: 1 addition & 1 deletion nazurin/models/ugoira.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__( # noqa: PLR0913

@property
def all_files(self):
return [self.video] + self.files
return [self.video, *self.files]

def has_image(self) -> bool:
return self.video is not None
2 changes: 1 addition & 1 deletion nazurin/sites/pixiv/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def get_artwork(self, artwork_id: int):
raise NazurinError("Artwork is private")
return illust

async def view(self, artwork_id: int = None) -> Illust:
async def view(self, artwork_id: int) -> Illust:
illust = await self.get_artwork(artwork_id)
if illust.type == "ugoira":
illust = await self.view_ugoira(illust)
Expand Down
8 changes: 4 additions & 4 deletions nazurin/sites/twitter/api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime, timezone
from http import HTTPStatus
from http.cookies import SimpleCookie
from typing import List
from typing import ClassVar, List

from nazurin.models import Illust, Image
from nazurin.utils.decorators import Cache, network_retry
Expand Down Expand Up @@ -53,15 +53,15 @@ class TweetDetailAPI:

class WebAPI(BaseAPI):
auth_token = AUTH_TOKEN
headers = {
headers: ClassVar[dict[str, str]] = {
"Authorization": AuthorizationToken.GUEST,
"Origin": "https://twitter.com",
"Referer": "https://twitter.com",
Headers.GUEST_TOKEN: "",
"x-twitter-client-language": "en",
"x-twitter-active-user": "yes",
}
variables = {
variables: ClassVar[dict[str, bool]] = {
"with_rux_injections": False,
"includePromotedContent": False,
"withCommunity": True,
Expand All @@ -73,7 +73,7 @@ class WebAPI(BaseAPI):
"withVoice": True,
"withV2Timeline": True,
}
features = {
features: ClassVar[dict[str, bool]] = {
"blue_business_profile_image_shape_enabled": False,
"rweb_lists_timeline_redesign_enabled": True,
"responsive_web_graphql_exclude_directive_enabled": True,
Expand Down
3 changes: 2 additions & 1 deletion nazurin/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import importlib
from typing import ClassVar, List

from nazurin.config import STORAGE
from nazurin.models import Illust
Expand All @@ -11,7 +12,7 @@
class Storage:
"""Storage manager."""

disks = []
disks: ClassVar[List[object]] = []

def load(self):
"""Dynamically load all storage drivers."""
Expand Down
10 changes: 5 additions & 5 deletions nazurin/storage/googledrive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import json
from pathlib import PurePath
from typing import Awaitable, Callable, List
from typing import Awaitable, Callable, List, Optional

from oauth2client.service_account import ServiceAccountCredentials
from pydrive2.auth import GoogleAuth
Expand Down Expand Up @@ -57,7 +57,7 @@ def auth():
GoogleDrive.drive.auth = gauth

@staticmethod
async def upload(file: File, folders: dict = None):
async def upload(file: File, folders: Optional[dict] = None):
# Compute relative path to STORAGE_DIR, which is GD_FOLDER
path = file.destination.relative_to(STORAGE_DIR).as_posix()
parent = folders[path] if folders else await GoogleDrive.create_folders(path)
Expand Down Expand Up @@ -86,7 +86,7 @@ async def store(self, files: List[File]):
@staticmethod
@Cache.lru()
@async_wrap
def find_folder(name: str, parent: str = None) -> str:
def find_folder(name: str, parent: Optional[str] = None) -> str:
query = {
"q": f"mimeType='{FOLDER_MIME}' and "
f"title='{name}' and "
Expand All @@ -99,7 +99,7 @@ def find_folder(name: str, parent: str = None) -> str:
return result[0].get("id")

@staticmethod
async def create_folder(name: str, parent: str = None) -> str:
async def create_folder(name: str, parent: Optional[str] = None) -> str:
metadata = {
"title": name,
"mimeType": FOLDER_MIME,
Expand All @@ -110,7 +110,7 @@ async def create_folder(name: str, parent: str = None) -> str:
return folder.get("id")

@staticmethod
async def create_folders(path: str, parent: str = None) -> str:
async def create_folders(path: str, parent: Optional[str] = None) -> str:
"""
Create folders recursively.
Expand Down
10 changes: 8 additions & 2 deletions nazurin/storage/mega.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import List
from typing import List, Optional

from mega import Mega as MegaBase
from mega.errors import RequestError
Expand Down Expand Up @@ -62,7 +62,13 @@ async def require_auth(self):
await self.login(initialize=True)

@network_retry
async def upload(self, file: File, folders: dict = None, *, retry: bool = False):
async def upload(
self,
file: File,
folders: Optional[dict] = None,
*,
retry: bool = False,
):
path = file.destination.as_posix()
try:
destination = (
Expand Down
2 changes: 1 addition & 1 deletion nazurin/storage/onedrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async def upload_chunk(url: str, chunk: bytes):
)
logger.info("[File {}] Upload completed", file.name)

def with_credentials(self, headers: dict = None) -> dict:
def with_credentials(self, headers: Optional[dict] = None) -> dict:
"""
Add credentials to the request header.
"""
Expand Down
3 changes: 2 additions & 1 deletion nazurin/utils/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import functools
from functools import partial, wraps
from typing import Callable, ClassVar, List

import tenacity
from aiogram.types import ChatActions, Message
Expand Down Expand Up @@ -90,7 +91,7 @@ async def decorator(*args, **kwargs):


class Cache:
cached_functions = []
cached_functions: ClassVar[List[Callable]] = []

@staticmethod
def lru(*args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extend-select = [
"PERF", # perflint
"PL", # pylint
"RSE102", # unnecessary-paren-on-raise-exception
"RUF", # ruff
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
Expand Down

0 comments on commit be992ac

Please sign in to comment.