This commit is contained in:
@@ -3,13 +3,13 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
from typing import Collection
|
||||
from typing import ContextManager
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Mapping
|
||||
from typing import MutableMapping
|
||||
from typing import Optional
|
||||
from typing import overload
|
||||
from typing import Sequence
|
||||
from typing import TextIO
|
||||
from typing import Tuple
|
||||
from typing import TYPE_CHECKING
|
||||
@@ -17,6 +17,7 @@ from typing import Union
|
||||
|
||||
from sqlalchemy.sql.schema import Column
|
||||
from sqlalchemy.sql.schema import FetchedValue
|
||||
from typing_extensions import ContextManager
|
||||
from typing_extensions import Literal
|
||||
|
||||
from .migration import _ProxyTransaction
|
||||
@@ -107,7 +108,6 @@ CompareType = Callable[
|
||||
|
||||
|
||||
class EnvironmentContext(util.ModuleClsProxy):
|
||||
|
||||
"""A configurational facade made available in an ``env.py`` script.
|
||||
|
||||
The :class:`.EnvironmentContext` acts as a *facade* to the more
|
||||
@@ -227,9 +227,9 @@ class EnvironmentContext(util.ModuleClsProxy):
|
||||
has been configured.
|
||||
|
||||
"""
|
||||
return self.context_opts.get("as_sql", False)
|
||||
return self.context_opts.get("as_sql", False) # type: ignore[no-any-return] # noqa: E501
|
||||
|
||||
def is_transactional_ddl(self):
|
||||
def is_transactional_ddl(self) -> bool:
|
||||
"""Return True if the context is configured to expect a
|
||||
transactional DDL capable backend.
|
||||
|
||||
@@ -341,18 +341,17 @@ class EnvironmentContext(util.ModuleClsProxy):
|
||||
return self.context_opts.get("tag", None)
|
||||
|
||||
@overload
|
||||
def get_x_argument(self, as_dictionary: Literal[False]) -> List[str]:
|
||||
...
|
||||
def get_x_argument(self, as_dictionary: Literal[False]) -> List[str]: ...
|
||||
|
||||
@overload
|
||||
def get_x_argument(self, as_dictionary: Literal[True]) -> Dict[str, str]:
|
||||
...
|
||||
def get_x_argument(
|
||||
self, as_dictionary: Literal[True]
|
||||
) -> Dict[str, str]: ...
|
||||
|
||||
@overload
|
||||
def get_x_argument(
|
||||
self, as_dictionary: bool = ...
|
||||
) -> Union[List[str], Dict[str, str]]:
|
||||
...
|
||||
) -> Union[List[str], Dict[str, str]]: ...
|
||||
|
||||
def get_x_argument(
|
||||
self, as_dictionary: bool = False
|
||||
@@ -366,7 +365,11 @@ class EnvironmentContext(util.ModuleClsProxy):
|
||||
The return value is a list, returned directly from the ``argparse``
|
||||
structure. If ``as_dictionary=True`` is passed, the ``x`` arguments
|
||||
are parsed using ``key=value`` format into a dictionary that is
|
||||
then returned.
|
||||
then returned. If there is no ``=`` in the argument, value is an empty
|
||||
string.
|
||||
|
||||
.. versionchanged:: 1.13.1 Support ``as_dictionary=True`` when
|
||||
arguments are passed without the ``=`` symbol.
|
||||
|
||||
For example, to support passing a database URL on the command line,
|
||||
the standard ``env.py`` script can be modified like this::
|
||||
@@ -400,7 +403,12 @@ class EnvironmentContext(util.ModuleClsProxy):
|
||||
else:
|
||||
value = []
|
||||
if as_dictionary:
|
||||
value = dict(arg.split("=", 1) for arg in value)
|
||||
dict_value = {}
|
||||
for arg in value:
|
||||
x_key, _, x_value = arg.partition("=")
|
||||
dict_value[x_key] = x_value
|
||||
value = dict_value
|
||||
|
||||
return value
|
||||
|
||||
def configure(
|
||||
@@ -416,7 +424,7 @@ class EnvironmentContext(util.ModuleClsProxy):
|
||||
tag: Optional[str] = None,
|
||||
template_args: Optional[Dict[str, Any]] = None,
|
||||
render_as_batch: bool = False,
|
||||
target_metadata: Optional[MetaData] = None,
|
||||
target_metadata: Union[MetaData, Sequence[MetaData], None] = None,
|
||||
include_name: Optional[IncludeNameFn] = None,
|
||||
include_object: Optional[IncludeObjectFn] = None,
|
||||
include_schemas: bool = False,
|
||||
@@ -940,7 +948,7 @@ class EnvironmentContext(util.ModuleClsProxy):
|
||||
def execute(
|
||||
self,
|
||||
sql: Union[Executable, str],
|
||||
execution_options: Optional[dict] = None,
|
||||
execution_options: Optional[Dict[str, Any]] = None,
|
||||
) -> None:
|
||||
"""Execute the given SQL using the current change context.
|
||||
|
||||
@@ -968,7 +976,7 @@ class EnvironmentContext(util.ModuleClsProxy):
|
||||
|
||||
def begin_transaction(
|
||||
self,
|
||||
) -> Union[_ProxyTransaction, ContextManager[None]]:
|
||||
) -> Union[_ProxyTransaction, ContextManager[None, Optional[bool]]]:
|
||||
"""Return a context manager that will
|
||||
enclose an operation within a "transaction",
|
||||
as defined by the environment's offline
|
||||
|
||||
Reference in New Issue
Block a user