mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-16 00:37:10 +08:00
Fix incorrect usage of AnyStr (#1215)
* Fix incorrect usage of AnyStr - sqlite3 was using Union[bytes, AnyStr], which doesn't make sense - The urllib functions I changed accept either bytes or str for their "safe" argument - Also added supports for PathLike to pstats - Remove some unused imports of AnyStr * pstats: python 2 accepts unicode
This commit is contained in:
committed by
Matthias Kramm
parent
dad65e4121
commit
1d6e3f492e
@@ -2,7 +2,7 @@
|
||||
|
||||
# Based on http://docs.python.org/2/library/subprocess.html and Python 3 stub
|
||||
|
||||
from typing import Sequence, Any, AnyStr, Mapping, Callable, Tuple, IO, Union, Optional, List, Text
|
||||
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Union, Optional, List, Text
|
||||
|
||||
_FILE = Union[int, IO[Any]]
|
||||
_TXT = Union[bytes, Text]
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
from profile import Profile
|
||||
from cProfile import Profile as cProfile
|
||||
from typing import Any, AnyStr, Dict, IO, Iterable, List, Text, Tuple, TypeVar, Union, overload
|
||||
import os
|
||||
import sys
|
||||
from typing import Any, Dict, IO, Iterable, List, Text, Tuple, TypeVar, Union, overload
|
||||
|
||||
_Selector = Union[str, float, int]
|
||||
_T = TypeVar('_T', bound='Stats')
|
||||
if sys.version_info >= (3, 6):
|
||||
_Path = Union[bytes, Text, os.PathLike[Any]]
|
||||
else:
|
||||
_Path = Union[bytes, Text]
|
||||
|
||||
class Stats:
|
||||
def __init__(self: _T, __arg: Union[None, str, Text, Profile, cProfile] = ...,
|
||||
@@ -13,7 +19,7 @@ class Stats:
|
||||
def load_stats(self, arg: Union[None, str, Text, Profile, cProfile]) -> None: ...
|
||||
def get_top_level_stats(self) -> None: ...
|
||||
def add(self: _T, *arg_list: Union[None, str, Text, Profile, cProfile, _T]) -> _T: ...
|
||||
def dump_stats(self, filename: AnyStr) -> None: ...
|
||||
def dump_stats(self, filename: _Path) -> None: ...
|
||||
def get_sort_arg_defs(self) -> Dict[str, Tuple[Tuple[Tuple[int, int], ...], str]]: ...
|
||||
@overload
|
||||
def sort_stats(self: _T, field: int) -> _T: ...
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Filip Hron <filip.hron@gmail.com>
|
||||
# based heavily on Andrey Vlasovskikh's python-skeletons https://github.com/JetBrains/python-skeletons/blob/master/sqlite3.py
|
||||
|
||||
from typing import Any, Union, List, AnyStr, Iterator, Optional
|
||||
from typing import Any, Union, List, Iterator, Optional
|
||||
from numbers import Integral
|
||||
from datetime import time, datetime
|
||||
from collections import Iterable
|
||||
@@ -69,9 +69,9 @@ version = ... # type: str
|
||||
def adapt(obj, protocol, alternate): ...
|
||||
def complete_statement(sql: str) -> bool: ...
|
||||
if sys.version_info >= (3, 4):
|
||||
def connect(database: Union[bytes, AnyStr], timeout: float = ..., detect_types: int = ..., isolation_level: Union[str, None] = ..., check_same_thread: bool = ..., factory: Union[Connection, None] = ..., cached_statements: int = ..., uri: bool = ...) -> Connection: ...
|
||||
def connect(database: Union[bytes, str], timeout: float = ..., detect_types: int = ..., isolation_level: Union[str, None] = ..., check_same_thread: bool = ..., factory: Union[Connection, None] = ..., cached_statements: int = ..., uri: bool = ...) -> Connection: ...
|
||||
else:
|
||||
def connect(database: Union[bytes, AnyStr], timeout: float = ..., detect_types: int = ..., isolation_level: Union[str, None] = ..., check_same_thread: bool = ..., factory: Union[Connection, None] = ..., cached_statements: int = ...) -> Connection: ...
|
||||
def connect(database: Union[bytes, str], timeout: float = ..., detect_types: int = ..., isolation_level: Union[str, None] = ..., check_same_thread: bool = ..., factory: Union[Connection, None] = ..., cached_statements: int = ...) -> Connection: ...
|
||||
def enable_callback_tracebacks(flag: bool) -> None: ...
|
||||
def enable_shared_cache(do_enable: int) -> None: ...
|
||||
def register_adapter(type: type, callable: Any) -> None: ...
|
||||
@@ -109,7 +109,7 @@ class Connection:
|
||||
def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ...
|
||||
# TODO: please check in executemany() if seq_of_parameters type is possible like this
|
||||
def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]) -> Cursor: ...
|
||||
def executescript(self, sql_script: Union[bytes, AnyStr]) -> Cursor: ...
|
||||
def executescript(self, sql_script: Union[bytes, str]) -> Cursor: ...
|
||||
def interrupt(self, *args, **kwargs) -> None: ...
|
||||
def iterdump(self, *args, **kwargs) -> None: ...
|
||||
def rollback(self, *args, **kwargs) -> None: ...
|
||||
@@ -138,7 +138,7 @@ class Cursor(Iterator[Any]):
|
||||
def close(self, *args, **kwargs): ...
|
||||
def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ...
|
||||
def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]): ...
|
||||
def executescript(self, sql_script: Union[bytes, AnyStr]) -> Cursor: ...
|
||||
def executescript(self, sql_script: Union[bytes, str]) -> Cursor: ...
|
||||
def fetchall(self) -> List[Any]: ...
|
||||
def fetchmany(self, size: Integral = ...) -> List[Any]: ...
|
||||
def fetchone(self) -> Any: ...
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
# Based on http://docs.python.org/3.2/library/string.html
|
||||
|
||||
from typing import Mapping, Sequence, Any, Optional, Union, List, Tuple, Iterable, AnyStr
|
||||
from typing import Mapping, Sequence, Any, Optional, Union, List, Tuple, Iterable
|
||||
|
||||
ascii_letters = ... # type: str
|
||||
ascii_lowercase = ... # type: str
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
# Based on http://docs.python.org/3.6/library/subprocess.html
|
||||
import sys
|
||||
from typing import Sequence, Any, AnyStr, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text
|
||||
from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text
|
||||
from types import TracebackType
|
||||
|
||||
_FILE = Union[int, IO[Any]]
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
from typing import Any, List, Dict, Tuple, AnyStr, Generic, overload, Sequence, Mapping, Union, NamedTuple, Callable
|
||||
import sys
|
||||
|
||||
_Str = Union[bytes, str]
|
||||
|
||||
__all__ = (
|
||||
'urlparse',
|
||||
'urlunparse',
|
||||
@@ -103,20 +105,20 @@ def parse_qsl(qs: AnyStr, keep_blank_values: bool = ..., strict_parsing: bool =
|
||||
|
||||
|
||||
@overload
|
||||
def quote(string: str, safe: AnyStr = ..., encoding: str = ..., errors: str = ...) -> str: ...
|
||||
def quote(string: str, safe: _Str = ..., encoding: str = ..., errors: str = ...) -> str: ...
|
||||
@overload
|
||||
def quote(string: bytes, safe: AnyStr = ...) -> str: ...
|
||||
def quote(string: bytes, safe: _Str = ...) -> str: ...
|
||||
|
||||
def quote_from_bytes(bs: bytes, safe: AnyStr = ...) -> str: ...
|
||||
def quote_from_bytes(bs: bytes, safe: _Str = ...) -> str: ...
|
||||
|
||||
@overload
|
||||
def quote_plus(string: str, safe: AnyStr = ..., encoding: str = ..., errors: str = ...) -> str: ...
|
||||
def quote_plus(string: str, safe: _Str = ..., encoding: str = ..., errors: str = ...) -> str: ...
|
||||
@overload
|
||||
def quote_plus(string: bytes, safe: AnyStr = ...) -> str: ...
|
||||
def quote_plus(string: bytes, safe: _Str = ...) -> str: ...
|
||||
|
||||
def unquote(string: str, encoding: str = ..., errors: str = ...) -> str: ...
|
||||
|
||||
def unquote_to_bytes(string: AnyStr) -> bytes: ...
|
||||
def unquote_to_bytes(string: _Str) -> bytes: ...
|
||||
|
||||
def unquote_plus(string: str, encoding: str = ..., errors: str = ...) -> str: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user