-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve type hint #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from math import ceil | ||
from typing import Callable, Union | ||
from typing import Callable, Optional, Union | ||
|
||
from fastapi import HTTPException | ||
from starlette.requests import Request | ||
|
@@ -46,11 +46,11 @@ async def ws_default_callback(ws: WebSocket, pexpire: int): | |
|
||
class FastAPILimiter: | ||
redis = None | ||
prefix: str = None | ||
lua_sha: str = None | ||
identifier: Callable = None | ||
http_callback: Callable = None | ||
ws_callback: Callable = None | ||
prefix: Optional[str] = None | ||
lua_sha: Optional[str] = None | ||
identifier: Optional[Callable] = None | ||
http_callback: Optional[Callable] = None | ||
ws_callback: Optional[Callable] = None | ||
lua_script = """local key = KEYS[1] | ||
local limit = tonumber(ARGV[1]) | ||
local expire_time = ARGV[2] | ||
|
@@ -76,7 +76,7 @@ async def init( | |
identifier: Callable = default_identifier, | ||
http_callback: Callable = http_default_callback, | ||
ws_callback: Callable = ws_default_callback, | ||
): | ||
) -> None: | ||
cls.redis = redis | ||
cls.prefix = prefix | ||
cls.identifier = identifier | ||
|
@@ -85,5 +85,5 @@ async def init( | |
cls.lua_sha = await redis.script_load(cls.lua_script) | ||
|
||
@classmethod | ||
async def close(cls): | ||
async def close(cls) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my project mypy says...
|
||
await cls.redis.close() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from typing import Callable, Optional | ||
from typing import Annotated, Callable, Optional | ||
|
||
from pydantic import conint | ||
from pydantic import Field | ||
from starlette.requests import Request | ||
from starlette.responses import Response | ||
from starlette.websockets import WebSocket | ||
|
@@ -12,11 +12,11 @@ | |
class RateLimiter: | ||
def __init__( | ||
self, | ||
times: conint(ge=0) = 1, | ||
milliseconds: conint(ge=-1) = 0, | ||
seconds: conint(ge=-1) = 0, | ||
minutes: conint(ge=-1) = 0, | ||
hours: conint(ge=-1) = 0, | ||
times: Annotated[int, Field(ge=0)] = 1, | ||
milliseconds: Annotated[int, Field(ge=-1)] = 0, | ||
seconds: Annotated[int, Field(ge=-1)] = 0, | ||
minutes: Annotated[int, Field(ge=-1)] = 0, | ||
hours: Annotated[int, Field(ge=-1)] = 0, | ||
identifier: Optional[Callable] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I migrated according to this |
||
callback: Optional[Callable] = None, | ||
): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Optional