Skip to content

Commit

Permalink
fix typing issues
Browse files Browse the repository at this point in the history
- unfix requirements.txt for now
- add temporary type: ignore with TODO tag
- fix general typing issues
- refactor MessageDisplay to drop unused types
- add lingua stubs since the sources is rust code
  • Loading branch information
AiroPi committed Dec 5, 2023
1 parent a062647 commit 3e172b2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
22 changes: 11 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
wheel==0.41.1
asyncpg==0.28.0
sqlalchemy[asyncio]==2.0.19
typing_extensions==4.7.1
discord.py==2.3.2
click==8.1.6
psutil==5.9.5
alembic==1.11.2
wheel
asyncpg
sqlalchemy[asyncio]
typing_extensions
discord.py
click
psutil
alembic
topggpy==2.0.0a0
lingua-language-detector==1.3.2
aiohttp==3.8.5
python-dateutil==2.8.2
lingua-language-detector
aiohttp
python-dateutil
2 changes: 1 addition & 1 deletion src/cogs/poll/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class AddChoice(Menu["MyBot"], ui.Modal):

def __init__(self, parent: EditChoices) -> None:
ui.Modal.__init__(self, title=_("Add a new choice"))
Menu.__init__(self, parent=parent) # pyright: ignore [reportUnknownMemberType]
Menu.__init__(self, parent=parent) # type: ignore # TODO

async def build(self) -> Self:
self.choice = ui.TextInput[Self](
Expand Down
2 changes: 1 addition & 1 deletion src/cogs/translate/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class SendStrategy(Protocol):
async def __call__(self, *, content: str = Any, embeds: Sequence[Embed] = Any, view: ui.View = MISSING) -> Any:
async def __call__(self, *, content: str = ..., embeds: Sequence[Embed] = ..., view: ui.View = MISSING) -> Any:
...


Expand Down
2 changes: 1 addition & 1 deletion src/core/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Config:
TRANSLATOR_SERVICES: str = "libretranslate"
LOG_WEBHOOK_URL: str | None = None

_instance: ClassVar[Config] | None = None
_instance: ClassVar[Self] | None = None
_defined: ClassVar[bool] = False

def __new__(cls, *args: Any, **kwargs: Any) -> Self:
Expand Down
25 changes: 3 additions & 22 deletions src/core/response.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import logging
from dataclasses import dataclass
from enum import Enum, auto
from typing import Any, Iterator, Literal, Mapping, overload
from typing import Any, Iterator, Mapping

import discord
from discord import Color, Embed

logger = logging.getLogger(__name__)


@dataclass()
@dataclass
class MessageDisplay(Mapping[str, Embed | str | None]):
"""
Used to represent the "display" of a message. It contains the content, the embeds, etc...
"""

embed: Embed | None = None
embed: Embed
content: str | None = None

def __getitem__(self, key: str) -> Any:
Expand Down Expand Up @@ -43,11 +43,6 @@ def __len__(self) -> int:
return 0


class _ResponseEmbed(MessageDisplay):
embed: Embed
content: str | None = None


class ResponseType(Enum):
success = auto()
info = auto()
Expand All @@ -70,20 +65,6 @@ class ResponseType(Enum):
}


@overload
def response_constructor(
response_type: ResponseType, message: str, embedded: Literal[True] = ..., author_url: str | None = ...
) -> _ResponseEmbed:
...


@overload
def response_constructor(
response_type: ResponseType, message: str, embedded: Literal[False] = ..., author_url: str | None = ...
) -> MessageDisplay:
...


def response_constructor(
response_type: ResponseType, message: str, embedded: bool = True, author_url: str | None = None
) -> MessageDisplay:
Expand Down
31 changes: 31 additions & 0 deletions typings/lingua.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from enum import Enum, auto
from typing import Self

class Language(Enum):
ENGLISH = auto()
ARABIC = auto()
CHINESE = auto()
FRENCH = auto()
GERMAN = auto()
HINDI = auto()
INDONESIAN = auto()
IRISH = auto()
ITALIAN = auto()
JAPANESE = auto()
KOREAN = auto()
POLISH = auto()
PORTUGUESE = auto()
RUSSIAN = auto()
SPANISH = auto()
TURKISH = auto()
VIETNAMESE = auto()

class LanguageDetectorBuilder:
@classmethod
def from_languages(cls, *args: Language) -> Self: ...
def with_low_accuracy_mode(self) -> Self: ...
def with_minimum_relative_distance(self, value: float) -> Self: ...
def build(self) -> LanguageDetector: ...

class LanguageDetector:
def detect_language_of(self, text: str) -> Language | None: ...

0 comments on commit 3e172b2

Please sign in to comment.