Skip to content

Commit

Permalink
Standardize use of dict, list, tuple & set for typing
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed Feb 15, 2025
1 parent 23f88d9 commit 5b7c1fe
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 96 deletions.
26 changes: 10 additions & 16 deletions flask_limiter/commands.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import itertools
import time
from collections.abc import Generator
from functools import partial
from typing import (
Any,
Callable,
Dict,
Generator,
List,
Optional,
Set,
Tuple,
Union,
cast,
)
Expand Down Expand Up @@ -111,7 +107,7 @@ def render_limit(limit: Limit, simple: bool = True) -> str:
def render_limits(
app: Flask,
limiter: Limiter,
limits: Tuple[List[Limit], ...],
limits: tuple[list[Limit], ...],
endpoint: Optional[str] = None,
blueprint: Optional[str] = None,
rule: Optional[Rule] = None,
Expand Down Expand Up @@ -386,12 +382,12 @@ def limits(
watch: bool = False,
) -> None:
with current_app.test_request_context():
limiters: Set[Limiter] = current_app.extensions.get("limiter", set())
limiters: set[Limiter] = current_app.extensions.get("limiter", set())
limiter: Optional[Limiter] = list(limiters)[0] if limiters else None
console = Console(theme=limiter_theme)
if limiter:
manager = limiter.limit_manager
groups: Dict[str, List[Callable[..., Tree]]] = {}
groups: dict[str, list[Callable[..., Tree]]] = {}

filter_endpoint = get_filtered_endpoint(
current_app, console, endpoint, path, method
Expand Down Expand Up @@ -516,14 +512,12 @@ def clear(
filter_endpoint = get_filtered_endpoint(
current_app, console, endpoint, path, method
)
Details = TypedDict(
"Details",
{
"rule": Rule,
"limits": Tuple[List[Limit], ...],
},
)
rule_limits: Dict[str, Details] = {}

class Details(TypedDict):
rule: Rule
limits: tuple[list[Limit], ...]

rule_limits: dict[str, Details] = {}
for rule in sorted(
current_app.url_map.iter_rules(filter_endpoint), key=lambda r: str(r)
):
Expand Down
Loading

0 comments on commit 5b7c1fe

Please sign in to comment.