mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-03-16 22:20:24 +00:00
Enable annotations future; use futuristic annotations
This commit is contained in:
parent
1ca8ccf7db
commit
a87f12185e
1 changed files with 13 additions and 12 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import urllib.parse as urlparse
|
import urllib.parse as urlparse
|
||||||
from typing import Any, Callable, Optional, TypedDict
|
from collections.abc import Callable
|
||||||
|
from typing import Any, TypedDict
|
||||||
|
|
||||||
DEFAULT_ENV = "DATABASE_URL"
|
DEFAULT_ENV = "DATABASE_URL"
|
||||||
ENGINE_SCHEMES: dict[str, "Engine"] = {}
|
ENGINE_SCHEMES: dict[str, "Engine"] = {}
|
||||||
|
|
@ -11,7 +12,7 @@ ENGINE_SCHEMES: dict[str, "Engine"] = {}
|
||||||
class DBConfig(TypedDict, total=False):
|
class DBConfig(TypedDict, total=False):
|
||||||
ATOMIC_REQUESTS: bool
|
ATOMIC_REQUESTS: bool
|
||||||
AUTOCOMMIT: bool
|
AUTOCOMMIT: bool
|
||||||
CONN_MAX_AGE: Optional[int]
|
CONN_MAX_AGE: int | None
|
||||||
CONN_HEALTH_CHECKS: bool
|
CONN_HEALTH_CHECKS: bool
|
||||||
DISABLE_SERVER_SIDE_CURSORS: bool
|
DISABLE_SERVER_SIDE_CURSORS: bool
|
||||||
ENGINE: str
|
ENGINE: str
|
||||||
|
|
@ -125,13 +126,13 @@ def apply_current_schema(parsed_config: DBConfig) -> None:
|
||||||
|
|
||||||
def config(
|
def config(
|
||||||
env: str = DEFAULT_ENV,
|
env: str = DEFAULT_ENV,
|
||||||
default: Optional[str] = None,
|
default: str | None = None,
|
||||||
engine: Optional[str] = None,
|
engine: str | None = None,
|
||||||
conn_max_age: Optional[int] = 0,
|
conn_max_age: int | None = 0,
|
||||||
conn_health_checks: bool = False,
|
conn_health_checks: bool = False,
|
||||||
disable_server_side_cursors: bool = False,
|
disable_server_side_cursors: bool = False,
|
||||||
ssl_require: bool = False,
|
ssl_require: bool = False,
|
||||||
test_options: Optional[dict[str, Any]] = None,
|
test_options: dict[str, Any] | None = None,
|
||||||
) -> DBConfig:
|
) -> DBConfig:
|
||||||
"""Returns configured DATABASE dictionary from DATABASE_URL."""
|
"""Returns configured DATABASE dictionary from DATABASE_URL."""
|
||||||
s = os.environ.get(env, default)
|
s = os.environ.get(env, default)
|
||||||
|
|
@ -157,12 +158,12 @@ def config(
|
||||||
|
|
||||||
def parse(
|
def parse(
|
||||||
url: str,
|
url: str,
|
||||||
engine: Optional[str] = None,
|
engine: str | None = None,
|
||||||
conn_max_age: Optional[int] = 0,
|
conn_max_age: int | None = 0,
|
||||||
conn_health_checks: bool = False,
|
conn_health_checks: bool = False,
|
||||||
disable_server_side_cursors: bool = False,
|
disable_server_side_cursors: bool = False,
|
||||||
ssl_require: bool = False,
|
ssl_require: bool = False,
|
||||||
test_options: Optional[dict[str, Any]] = None,
|
test_options: dict[str, Any] | None = None,
|
||||||
) -> DBConfig:
|
) -> DBConfig:
|
||||||
"""Parses a database URL and returns configured DATABASE dictionary."""
|
"""Parses a database URL and returns configured DATABASE dictionary."""
|
||||||
settings = _convert_to_settings(
|
settings = _convert_to_settings(
|
||||||
|
|
@ -230,12 +231,12 @@ def _parse_value(value: str) -> OptionType:
|
||||||
|
|
||||||
|
|
||||||
def _convert_to_settings(
|
def _convert_to_settings(
|
||||||
engine: Optional[str],
|
engine: str | None,
|
||||||
conn_max_age: Optional[int],
|
conn_max_age: int | None,
|
||||||
conn_health_checks: bool,
|
conn_health_checks: bool,
|
||||||
disable_server_side_cursors: bool,
|
disable_server_side_cursors: bool,
|
||||||
ssl_require: bool,
|
ssl_require: bool,
|
||||||
test_options: Optional[dict[str, Any]],
|
test_options: dict[str, Any] | None,
|
||||||
) -> DBConfig:
|
) -> DBConfig:
|
||||||
settings: DBConfig = {
|
settings: DBConfig = {
|
||||||
"CONN_MAX_AGE": conn_max_age,
|
"CONN_MAX_AGE": conn_max_age,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue