mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-03-16 22:20:24 +00:00
Switch to modern dict type hints for improved readability and consistency.
This commit is contained in:
parent
992999193d
commit
84fd0508ff
1 changed files with 11 additions and 11 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import logging
|
||||
import os
|
||||
import urllib.parse as urlparse
|
||||
from typing import Any, Callable, Dict, List, Optional, TypedDict, Union
|
||||
from typing import Any, Callable, Optional, TypedDict
|
||||
|
||||
DEFAULT_ENV = "DATABASE_URL"
|
||||
ENGINE_SCHEMES: Dict[str, "Engine"] = {}
|
||||
ENGINE_SCHEMES: dict[str, "Engine"] = {}
|
||||
|
||||
|
||||
# From https://docs.djangoproject.com/en/stable/ref/settings/#databases
|
||||
|
|
@ -17,16 +17,16 @@ class DBConfig(TypedDict, total=False):
|
|||
ENGINE: str
|
||||
HOST: str
|
||||
NAME: str
|
||||
OPTIONS: Dict[str, Any]
|
||||
OPTIONS: dict[str, Any]
|
||||
PASSWORD: str
|
||||
PORT: Union[str, int]
|
||||
TEST: Dict[str, Any]
|
||||
PORT: str | int
|
||||
TEST: dict[str, Any]
|
||||
TIME_ZONE: str
|
||||
USER: str
|
||||
|
||||
|
||||
PostprocessCallable = Callable[[DBConfig], None]
|
||||
OptionType = Union[int, str, bool]
|
||||
OptionType = int | str | bool
|
||||
|
||||
|
||||
class ParseError(ValueError):
|
||||
|
|
@ -38,7 +38,7 @@ class ParseError(ValueError):
|
|||
|
||||
|
||||
class UnknownSchemeError(ValueError):
|
||||
def __init__(self, scheme: str) -> None:
|
||||
def __init__(self, scheme: str):
|
||||
self.scheme = scheme
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
|
@ -59,7 +59,7 @@ class Engine:
|
|||
self,
|
||||
backend: str,
|
||||
postprocess: PostprocessCallable = default_postprocess,
|
||||
) -> None:
|
||||
):
|
||||
self.backend = backend
|
||||
self.postprocess = postprocess
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ def config(
|
|||
conn_health_checks: bool = False,
|
||||
disable_server_side_cursors: bool = False,
|
||||
ssl_require: bool = False,
|
||||
test_options: Optional[Dict[str, Any]] = None,
|
||||
test_options: Optional[dict[str, Any]] = None,
|
||||
) -> DBConfig:
|
||||
"""Returns configured DATABASE dictionary from DATABASE_URL."""
|
||||
s = os.environ.get(env, default)
|
||||
|
|
@ -162,7 +162,7 @@ def parse(
|
|||
conn_health_checks: bool = False,
|
||||
disable_server_side_cursors: bool = False,
|
||||
ssl_require: bool = False,
|
||||
test_options: Optional[Dict[str, Any]] = None,
|
||||
test_options: Optional[dict[str, Any]] = None,
|
||||
) -> DBConfig:
|
||||
"""Parses a database URL and returns configured DATABASE dictionary."""
|
||||
settings = _convert_to_settings(
|
||||
|
|
@ -216,7 +216,7 @@ def parse(
|
|||
return parsed_config
|
||||
|
||||
|
||||
def _parse_option_values(values: List[str]) -> Union[OptionType, List[OptionType]]:
|
||||
def _parse_option_values(values: list[str]) -> OptionType | list[OptionType]:
|
||||
parsed_values = [_parse_value(v) for v in values]
|
||||
return parsed_values[0] if len(parsed_values) == 1 else parsed_values
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue