Improve pymysql.converters stubs (#6267)

I spent far too much time being confused about why pyanalyze thought `pymysql.converters.escape_dict` only takes two arguments.

I rewrote the stubs from scratch using the implementation: https://github.com/PyMySQL/PyMySQL/blob/main/pymysql/converters.py.

The "charset" argument is ignored as far as I can tell; it gets passed to other functions but no function actually uses it.

Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
This commit is contained in:
Jelle Zijlstra
2021-11-09 07:57:29 -08:00
committed by GitHub
parent b95b729b9e
commit 98e5112195
3 changed files with 35 additions and 78 deletions

View File

@@ -1,47 +1,39 @@
from typing import Any
import datetime
import time
from collections.abc import Callable, Mapping, Sequence
from decimal import Decimal
from typing import Any, Optional, Type, TypeVar
from .charset import charset_by_id as charset_by_id
from .constants import FIELD_TYPE as FIELD_TYPE, FLAG as FLAG
_EscaperMapping = Optional[Mapping[Type[object], Callable[..., str]]]
_T = TypeVar("_T")
PYTHON3: Any
ESCAPE_REGEX: Any
ESCAPE_MAP: Any
def escape_item(val: object, charset: object, mapping: _EscaperMapping = ...) -> str: ...
def escape_dict(val: Mapping[str, object], charset: object, mapping: _EscaperMapping = ...) -> dict[str, str]: ...
def escape_sequence(val: Sequence[object], charset: object, mapping: _EscaperMapping = ...) -> str: ...
def escape_set(val: set[object], charset: object, mapping: _EscaperMapping = ...) -> str: ...
def escape_bool(value: bool, mapping: _EscaperMapping = ...) -> str: ...
def escape_int(value: int, mapping: _EscaperMapping = ...) -> str: ...
def escape_float(value: float, mapping: _EscaperMapping = ...) -> str: ...
def escape_string(value: str, mapping: _EscaperMapping = ...) -> str: ...
def escape_bytes_prefixed(value: bytes, mapping: _EscaperMapping = ...) -> str: ...
def escape_bytes(value: bytes, mapping: _EscaperMapping = ...) -> str: ...
def escape_str(value: str, mapping: _EscaperMapping = ...) -> str: ...
def escape_None(value: None, mapping: _EscaperMapping = ...) -> str: ...
def escape_timedelta(obj: datetime.timedelta, mapping: _EscaperMapping = ...) -> str: ...
def escape_time(obj: datetime.time, mapping: _EscaperMapping = ...) -> str: ...
def escape_datetime(obj: datetime.datetime, mapping: _EscaperMapping = ...) -> str: ...
def escape_date(obj: datetime.date, mapping: _EscaperMapping = ...) -> str: ...
def escape_struct_time(obj: time.struct_time, mapping: _EscaperMapping = ...) -> str: ...
def Decimal2Literal(o: Decimal, d: object) -> str: ...
def convert_datetime(obj: str | bytes) -> datetime.datetime | str: ...
def convert_timedelta(obj: str | bytes) -> datetime.timedelta | str: ...
def convert_time(obj: str | bytes) -> datetime.time | str: ...
def convert_date(obj: str | bytes) -> datetime.date | str: ...
def through(x: _T) -> _T: ...
def escape_item(val, charset): ...
def escape_dict(val, charset): ...
def escape_sequence(val, charset): ...
def escape_set(val, charset): ...
def escape_bool(value): ...
def escape_object(value): ...
convert_bit = through
escape_int: Any
escape_long: Any
def escape_float(value): ...
def escape_string(value): ...
def escape_unicode(value): ...
def escape_None(value): ...
def escape_timedelta(obj): ...
def escape_time(obj): ...
def escape_datetime(obj): ...
def escape_date(obj): ...
def escape_struct_time(obj): ...
def convert_datetime(connection, field, obj): ...
def convert_timedelta(connection, field, obj): ...
def convert_time(connection, field, obj): ...
def convert_date(connection, field, obj): ...
def convert_mysql_timestamp(connection, field, timestamp): ...
def convert_set(s): ...
def convert_bit(connection, field, b): ...
def convert_characters(connection, field, data): ...
def convert_int(connection, field, data): ...
def convert_long(connection, field, data): ...
def convert_float(connection, field, data): ...
encoders: Any
decoders: Any
conversions: Any
def convert_decimal(connection, field, data): ...
def escape_decimal(obj): ...
encoders: dict[Type[object], Callable[..., str]]
decoders: dict[int, Callable[[str | bytes], Any]]
conversions: dict[Type[object] | int, Callable[..., Any]]
Thing2Literal = escape_str