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:
Jelle Zijlstra
2017-04-27 08:47:59 -07:00
committed by Matthias Kramm
parent dad65e4121
commit 1d6e3f492e
6 changed files with 24 additions and 16 deletions

View File

@@ -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: ...