From 675ae1afc8a5b0a9a515292c7e9d6bc2a38887be Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 17 May 2021 16:38:37 +0100 Subject: [PATCH] Sync typeshed (#10495) Source commit: https://github.com/python/typeshed/commit/17bc1d83ea5ba4c3fb8363259993047727caf6b3 This doesn't include some recent typeshed commits. In particular, this is from before the split of stdlib stubs to Python 2 and 3 variants. This way we can more easily narrow down issues it might have caused. --- mypy/typeshed/stdlib/@python2/os/path.pyi | 2 +- mypy/typeshed/stdlib/@python2/typing.pyi | 10 +- mypy/typeshed/stdlib/VERSIONS | 532 ++++++++++---------- mypy/typeshed/stdlib/_bootlocale.pyi | 5 +- mypy/typeshed/stdlib/builtins.pyi | 4 +- mypy/typeshed/stdlib/csv.pyi | 49 +- mypy/typeshed/stdlib/formatter.pyi | 198 ++++---- mypy/typeshed/stdlib/functools.pyi | 15 +- mypy/typeshed/stdlib/genericpath.pyi | 44 +- mypy/typeshed/stdlib/grp.pyi | 2 +- mypy/typeshed/stdlib/locale.pyi | 2 +- mypy/typeshed/stdlib/logging/__init__.pyi | 107 ++-- mypy/typeshed/stdlib/logging/config.pyi | 31 +- mypy/typeshed/stdlib/logging/handlers.pyi | 164 ++++-- mypy/typeshed/stdlib/macpath.pyi | 224 ++++----- mypy/typeshed/stdlib/macurl2path.pyi | 8 +- mypy/typeshed/stdlib/mmap.pyi | 53 +- mypy/typeshed/stdlib/ntpath.pyi | 161 +++--- mypy/typeshed/stdlib/os/__init__.pyi | 40 +- mypy/typeshed/stdlib/os/path.pyi | 123 +---- mypy/typeshed/stdlib/parser.pyi | 36 +- mypy/typeshed/stdlib/posix.pyi | 43 +- mypy/typeshed/stdlib/posixpath.pyi | 74 ++- mypy/typeshed/stdlib/pwd.pyi | 4 +- mypy/typeshed/stdlib/py_compile.pyi | 2 +- mypy/typeshed/stdlib/selectors.pyi | 2 + mypy/typeshed/stdlib/signal.pyi | 7 +- mypy/typeshed/stdlib/socket.pyi | 8 +- mypy/typeshed/stdlib/spwd.pyi | 2 +- mypy/typeshed/stdlib/ssl.pyi | 6 +- mypy/typeshed/stdlib/statistics.pyi | 19 +- mypy/typeshed/stdlib/symbol.pyi | 176 ++++--- mypy/typeshed/stdlib/time.pyi | 26 +- mypy/typeshed/stdlib/typing.pyi | 14 +- mypy/typeshed/stdlib/typing_extensions.pyi | 5 +- mypy/typeshed/stdlib/urllib/request.pyi | 28 +- mypy/typeshed/stdlib/urllib/robotparser.pyi | 2 +- mypy/typeshed/stdlib/webbrowser.pyi | 1 - 38 files changed, 1150 insertions(+), 1079 deletions(-) diff --git a/mypy/typeshed/stdlib/@python2/os/path.pyi b/mypy/typeshed/stdlib/@python2/os/path.pyi index f096428602d4..c89bc8b69e8d 100644 --- a/mypy/typeshed/stdlib/@python2/os/path.pyi +++ b/mypy/typeshed/stdlib/@python2/os/path.pyi @@ -1,7 +1,6 @@ import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from genericpath import exists as exists from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, overload _T = TypeVar("_T") @@ -40,6 +39,7 @@ else: # Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes # So, fall back to Any def commonprefix(m: Sequence[AnyPath]) -> Any: ... +def exists(path: AnyPath) -> bool: ... def lexists(path: AnyPath) -> bool: ... # These return float if os.stat_float_times() == True, diff --git a/mypy/typeshed/stdlib/@python2/typing.pyi b/mypy/typeshed/stdlib/@python2/typing.pyi index e134d17415b0..dfcac95197b0 100644 --- a/mypy/typeshed/stdlib/@python2/typing.pyi +++ b/mypy/typeshed/stdlib/@python2/typing.pyi @@ -5,7 +5,6 @@ from types import CodeType, FrameType, TracebackType # Definitions of special type checking related constructs. Their definitions # are not used, so their value does not matter. -overload = object() Any = object() class TypeVar: @@ -40,6 +39,7 @@ Final: _SpecialForm = ... _F = TypeVar("_F", bound=Callable[..., Any]) def final(f: _F) -> _F: ... +def overload(f: _F) -> _F: ... Literal: _SpecialForm = ... # TypedDict is a (non-subscriptable) special form. @@ -63,11 +63,9 @@ _KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers. _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers. _T_contra = TypeVar("_T_contra", contravariant=True) # Ditto contravariant. _TC = TypeVar("_TC", bound=Type[object]) -_C = TypeVar("_C", bound=Callable[..., Any]) -no_type_check = object() - -def no_type_check_decorator(decorator: _C) -> _C: ... +def no_type_check(f: _F) -> _F: ... +def no_type_check_decorator(decorator: _F) -> _F: ... # Type aliases and type constructors @@ -492,4 +490,4 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... # This itself is only available during type checking -def type_check_only(func_or_cls: _C) -> _C: ... +def type_check_only(func_or_cls: _F) -> _F: ... diff --git a/mypy/typeshed/stdlib/VERSIONS b/mypy/typeshed/stdlib/VERSIONS index d4c475561f2f..11219357c638 100644 --- a/mypy/typeshed/stdlib/VERSIONS +++ b/mypy/typeshed/stdlib/VERSIONS @@ -1,258 +1,274 @@ -__future__: 2.7 -__main__: 2.7 -_ast: 3.6 -_bisect: 2.7 -_bootlocale: 3.6 -_codecs: 2.7 -_collections_abc: 3.6 -_compat_pickle: 3.6 -_compression: 3.6 -_csv: 2.7 -_curses: 2.7 -_decimal: 3.6 -_dummy_thread: 3.6 -_dummy_threading: 2.7 -_heapq: 2.7 -_imp: 3.6 -_json: 3.6 -_markupbase: 3.6 -_msi: 2.7 -_operator: 3.6 -_osx_support: 3.6 -_posixsubprocess: 3.6 -_py_abc: 3.7 -_pydecimal: 3.6 -_random: 2.7 -_sitebuiltins: 3.6 -_stat: 3.6 -_thread: 3.6 -_threading_local: 3.6 -_tkinter: 3.6 -_tracemalloc: 3.6 -_typeshed: 2.7 -_warnings: 2.7 -_weakref: 2.7 -_weakrefset: 2.7 -_winapi: 3.6 -abc: 3.6 -aifc: 2.7 -antigravity: 2.7 -argparse: 2.7 -array: 2.7 -ast: 3.6 -asynchat: 2.7 -asyncio: 3.6 -asyncore: 2.7 -atexit: 3.6 -audioop: 2.7 -base64: 2.7 -bdb: 2.7 -binascii: 2.7 -binhex: 2.7 -bisect: 2.7 -builtins: 3.6 -bz2: 2.7 -cProfile: 2.7 -calendar: 2.7 -cgi: 3.6 -cgitb: 2.7 -chunk: 2.7 -cmath: 2.7 -cmd: 2.7 -code: 2.7 -codecs: 2.7 -codeop: 2.7 -collections: 3.6 -colorsys: 2.7 -compileall: 3.6 -concurrent: 3.6 -configparser: 3.6 -contextlib: 2.7 -contextvars: 3.7 -copy: 2.7 -copyreg: 3.6 -crypt: 2.7 -csv: 2.7 -ctypes: 2.7 -curses: 2.7 -dataclasses: 3.7 -datetime: 2.7 -dbm: 3.6 -decimal: 2.7 -difflib: 2.7 -dis: 2.7 -distutils: 3.6 -doctest: 2.7 -dummy_threading: 2.7 -email: 3.6 -encodings: 3.6 -ensurepip: 2.7 -enum: 3.6 -errno: 2.7 -faulthandler: 3.6 -fcntl: 3.6 -filecmp: 2.7 -fileinput: 2.7 -fnmatch: 3.6 -formatter: 2.7 -fractions: 2.7 -ftplib: 2.7 -functools: 3.6 -gc: 3.6 -genericpath: 2.7 -getopt: 3.6 -getpass: 3.6 -gettext: 3.6 -glob: 3.6 -graphlib: 3.9 -grp: 2.7 -gzip: 3.6 -hashlib: 3.6 -heapq: 3.6 -hmac: 2.7 -html: 3.6 -http: 3.6 -imaplib: 2.7 -imghdr: 2.7 -imp: 3.6 -importlib: 3.6 -inspect: 3.6 -io: 3.6 -ipaddress: 3.6 -itertools: 3.6 -json: 3.6 -keyword: 2.7 -lib2to3: 2.7 -linecache: 2.7 -locale: 2.7 -logging: 3.6 -lzma: 3.6 -macpath: 2.7 -macurl2path: 3.6 -mailbox: 2.7 -mailcap: 2.7 -marshal: 2.7 -math: 2.7 -mimetypes: 2.7 -mmap: 2.7 -modulefinder: 2.7 -msilib: 2.7 -msvcrt: 2.7 -multiprocessing: 3.6 -netrc: 2.7 -nis: 2.7 -nntplib: 3.6 -ntpath: 3.6 -nturl2path: 3.6 -numbers: 2.7 -opcode: 2.7 -operator: 2.7 -optparse: 2.7 -os: 3.6 -ossaudiodev: 3.6 -parser: 2.7 -pathlib: 3.6 -pdb: 2.7 -pickle: 2.7 -pickletools: 2.7 -pipes: 3.6 -pkgutil: 2.7 -platform: 3.6 -plistlib: 2.7 -poplib: 2.7 -posix: 3.6 -posixpath: 3.6 -pprint: 2.7 -profile: 2.7 -pstats: 2.7 -pty: 2.7 -pwd: 2.7 -py_compile: 2.7 -pyclbr: 2.7 -pydoc: 2.7 -pydoc_data: 2.7 -pyexpat: 2.7 -queue: 3.6 -quopri: 2.7 -random: 3.6 -re: 3.6 -readline: 2.7 -reprlib: 3.6 -resource: 3.6 -rlcompleter: 2.7 -runpy: 3.6 -sched: 2.7 -secrets: 3.6 -select: 2.7 -selectors: 3.6 -shelve: 3.6 -shlex: 3.6 -shutil: 2.7 -signal: 3.6 -site: 2.7 -smtpd: 2.7 -smtplib: 3.6 -sndhdr: 2.7 -socket: 2.7 -socketserver: 3.6 -spwd: 3.6 -sqlite3: 2.7 -sre_compile: 2.7 -sre_constants: 3.6 -sre_parse: 3.6 -ssl: 2.7 -stat: 3.6 -statistics: 3.6 -string: 3.6 -stringprep: 2.7 -struct: 2.7 -subprocess: 3.6 -sunau: 2.7 -symbol: 3.6 -symtable: 2.7 -sys: 3.6 -sysconfig: 2.7 -syslog: 2.7 -tabnanny: 2.7 -tarfile: 2.7 -telnetlib: 2.7 -tempfile: 3.6 -termios: 2.7 -textwrap: 3.6 -this: 2.7 -threading: 2.7 -time: 2.7 -timeit: 2.7 -tkinter: 3.6 -token: 2.7 -tokenize: 3.6 -trace: 2.7 -traceback: 2.7 -tracemalloc: 3.6 -tty: 2.7 -turtle: 2.7 -types: 3.6 -typing: 3.6 -typing_extensions: 2.7 -unicodedata: 2.7 -unittest: 3.6 -urllib: 3.6 -uu: 2.7 -uuid: 2.7 -venv: 3.6 -warnings: 2.7 -wave: 2.7 -weakref: 2.7 -webbrowser: 2.7 -winreg: 3.6 -winsound: 2.7 -wsgiref: 2.7 -xdrlib: 2.7 -xml: 2.7 -xmlrpc: 3.6 -xxlimited: 3.6 -zipapp: 3.6 -zipfile: 2.7 -zipimport: 2.7 -zlib: 2.7 -zoneinfo: 3.9 +# The structure of this file is as follows: +# - Blank lines and lines starting with `#` are ignored. +# - Lines contain the name of a top-level module, followed by a colon, +# a space, and a version range (for example: `symbol: 2.7-3.9`). +# +# Version ranges may be of the form "X.Y-A.B" or "X.Y-". The +# first form means that a module was introduced in version X.Y and last +# available in version A.B. The second form means that the module was +# introduced in version X.Y and is still available in the latest +# version of Python. +# +# Python versions before 2.7 are ignored, so any module that was already +# present in 2.7 will have "2.7" as its minimum version. Version ranges +# for unsupported versions of Python 3 (currently 3.5 and lower) are +# generally accurate but we do not guarantee their correctness. + +__future__: 2.7- +__main__: 2.7- +_ast: 2.7- +_bisect: 2.7- +_bootlocale: 3.6-3.9 +_codecs: 2.7- +_collections_abc: 3.6- +_compat_pickle: 3.6- +_compression: 3.6- +_csv: 2.7- +_curses: 2.7- +_decimal: 3.6- +_dummy_thread: 3.6- +_dummy_threading: 2.7- +_heapq: 2.7- +_imp: 3.6- +_json: 2.7- +_markupbase: 2.7- +_msi: 2.7- +_operator: 3.6- +_osx_support: 2.7- +_posixsubprocess: 3.6- +_py_abc: 3.7- +_pydecimal: 3.6- +_random: 2.7- +_sitebuiltins: 3.6- +_stat: 3.6- +_thread: 2.7- +_threading_local: 3.6- +_tkinter: 2.7- +_tracemalloc: 3.6- +_typeshed: 2.7- +_warnings: 2.7- +_weakref: 2.7- +_weakrefset: 2.7- +_winapi: 3.6- +abc: 2.7- +aifc: 2.7- +antigravity: 2.7- +argparse: 2.7- +array: 2.7- +ast: 2.7- +asynchat: 2.7- +asyncio: 3.4- +asyncore: 2.7- +atexit: 2.7- +audioop: 2.7- +base64: 2.7- +bdb: 2.7- +binascii: 2.7- +binhex: 2.7- +bisect: 2.7- +builtins: 3.0- +bz2: 2.7- +cProfile: 2.7- +calendar: 2.7- +cgi: 2.7- +cgitb: 2.7- +chunk: 2.7- +cmath: 2.7- +cmd: 2.7- +code: 2.7- +codecs: 2.7- +codeop: 2.7- +collections: 2.7- +colorsys: 2.7- +compileall: 2.7- +concurrent: 3.2- +configparser: 3.0- +contextlib: 2.7- +contextvars: 3.7- +copy: 2.7- +copyreg: 2.7- +crypt: 2.7- +csv: 2.7- +ctypes: 2.7- +curses: 2.7- +dataclasses: 3.7- +datetime: 2.7- +dbm: 2.7- +decimal: 2.7- +difflib: 2.7- +dis: 2.7- +distutils: 2.7- +doctest: 2.7- +dummy_threading: 2.7- +email: 2.7- +encodings: 2.7- +ensurepip: 2.7- +enum: 3.4- +errno: 2.7- +faulthandler: 3.3- +fcntl: 2.7- +filecmp: 2.7- +fileinput: 2.7- +fnmatch: 2.7- +formatter: 2.7-3.9 +fractions: 2.7- +ftplib: 2.7- +functools: 2.7- +gc: 2.7- +genericpath: 2.7- +getopt: 2.7- +getpass: 2.7- +gettext: 2.7- +glob: 2.7- +graphlib: 3.9- +grp: 2.7- +gzip: 2.7- +hashlib: 2.7- +heapq: 2.7- +hmac: 2.7- +html: 2.7- +http: 3.0- +imaplib: 2.7- +imghdr: 2.7- +imp: 2.7- +importlib: 2.7- +inspect: 2.7- +io: 2.7- +ipaddress: 2.7- +itertools: 2.7- +json: 2.7- +keyword: 2.7- +lib2to3: 2.7- +linecache: 2.7- +locale: 2.7- +logging: 2.7- +lzma: 3.3- +macpath: 2.7-3.7 +macurl2path: 2.7-3.6 +mailbox: 2.7- +mailcap: 2.7- +marshal: 2.7- +math: 2.7- +mimetypes: 2.7- +mmap: 2.7- +modulefinder: 2.7- +msilib: 2.7- +msvcrt: 2.7- +multiprocessing: 2.7- +netrc: 2.7- +nis: 2.7- +nntplib: 2.7- +ntpath: 2.7- +nturl2path: 2.7- +numbers: 2.7- +opcode: 2.7- +operator: 2.7- +optparse: 2.7- +os: 2.7- +ossaudiodev: 2.7- +parser: 2.7-3.9 +pathlib: 3.4- +pdb: 2.7- +pickle: 2.7- +pickletools: 2.7- +pipes: 2.7- +pkgutil: 2.7- +platform: 2.7- +plistlib: 2.7- +poplib: 2.7- +posix: 2.7- +posixpath: 2.7- +pprint: 2.7- +profile: 2.7- +pstats: 2.7- +pty: 2.7- +pwd: 2.7- +py_compile: 2.7- +pyclbr: 2.7- +pydoc: 2.7- +pydoc_data: 2.7- +pyexpat: 2.7- +queue: 2.7- +quopri: 2.7- +random: 2.7- +re: 2.7- +readline: 2.7- +reprlib: 2.7- +resource: 2.7- +rlcompleter: 2.7- +runpy: 2.7- +sched: 2.7- +secrets: 3.6- +select: 2.7- +selectors: 3.4- +shelve: 2.7- +shlex: 2.7- +shutil: 2.7- +signal: 2.7- +site: 2.7- +smtpd: 2.7- +smtplib: 2.7- +sndhdr: 2.7- +socket: 2.7- +socketserver: 2.7- +spwd: 2.7- +sqlite3: 2.7- +sre_compile: 2.7- +sre_constants: 2.7- +sre_parse: 2.7- +ssl: 2.7- +stat: 2.7- +statistics: 3.4- +string: 2.7- +stringprep: 2.7- +struct: 2.7- +subprocess: 2.7- +sunau: 2.7- +symbol: 2.7-3.9 +symtable: 2.7- +sys: 2.7- +sysconfig: 2.7- +syslog: 2.7- +tabnanny: 2.7- +tarfile: 2.7- +telnetlib: 2.7- +tempfile: 2.7- +termios: 2.7- +textwrap: 2.7- +this: 2.7- +threading: 2.7- +time: 2.7- +timeit: 2.7- +tkinter: 3.0- +token: 2.7- +tokenize: 2.7- +trace: 2.7- +traceback: 2.7- +tracemalloc: 3.4- +tty: 2.7- +turtle: 2.7- +types: 2.7- +typing: 3.5- +typing_extensions: 2.7- +unicodedata: 2.7- +unittest: 2.7- +urllib: 2.7- +uu: 2.7- +uuid: 2.7- +venv: 3.3- +warnings: 2.7- +wave: 2.7- +weakref: 2.7- +webbrowser: 2.7- +winreg: 2.7- +winsound: 2.7- +wsgiref: 2.7- +xdrlib: 2.7- +xml: 2.7- +xmlrpc: 3.0- +xxlimited: 3.6- +zipapp: 3.5- +zipfile: 2.7- +zipimport: 2.7- +zlib: 2.7- +zoneinfo: 3.9- diff --git a/mypy/typeshed/stdlib/_bootlocale.pyi b/mypy/typeshed/stdlib/_bootlocale.pyi index 73e7b6b546bd..ee2d89347a9f 100644 --- a/mypy/typeshed/stdlib/_bootlocale.pyi +++ b/mypy/typeshed/stdlib/_bootlocale.pyi @@ -1,4 +1 @@ -import sys - -if sys.version_info < (3, 10): - def getpreferredencoding(do_setlocale: bool = ...) -> str: ... +def getpreferredencoding(do_setlocale: bool = ...) -> str: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 4ca869ff8a0f..69da371906d0 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -27,7 +27,6 @@ from typing import ( BinaryIO, ByteString, Callable, - Container, Dict, FrozenSet, Generic, @@ -624,7 +623,7 @@ class bytearray(MutableSequence[int], ByteString): def __gt__(self, x: bytes) -> bool: ... def __ge__(self, x: bytes) -> bool: ... -class memoryview(Sized, Container[int]): +class memoryview(Sized, Sequence[int]): format: str itemsize: int shape: Optional[Tuple[int, ...]] @@ -827,6 +826,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... def __or__(self, __value: Mapping[_KT, _VT]) -> Dict[_KT, _VT]: ... + def __ror__(self, __value: Mapping[_KT, _VT]) -> Dict[_KT, _VT]: ... def __ior__(self, __value: Mapping[_KT, _VT]) -> Dict[_KT, _VT]: ... class set(MutableSet[_T], Generic[_T]): diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi index 606694dca533..db48e9e6c78a 100644 --- a/mypy/typeshed/stdlib/csv.pyi +++ b/mypy/typeshed/stdlib/csv.pyi @@ -17,10 +17,14 @@ from _csv import ( unregister_dialect as unregister_dialect, writer as writer, ) -from collections import OrderedDict -from typing import Any, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Text, Type +from typing import Any, Generic, Iterable, Iterator, List, Mapping, Optional, Sequence, Text, Type, TypeVar, overload -_DictRow = Mapping[str, Any] +if sys.version_info >= (3, 8) or sys.version_info < (3, 6): + from typing import Dict as _DictReadMapping +else: + from collections import OrderedDict as _DictReadMapping + +_T = TypeVar("_T") class excel(Dialect): delimiter: str @@ -42,23 +46,28 @@ if sys.version_info >= (3,): lineterminator: str quoting: int -if sys.version_info >= (3, 8): - _DRMapping = Dict[str, str] -elif sys.version_info >= (3, 6): - _DRMapping = OrderedDict[str, str] -else: - _DRMapping = Dict[str, str] - -class DictReader(Iterator[_DRMapping]): +class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]): + fieldnames: Optional[Sequence[_T]] restkey: Optional[str] restval: Optional[str] reader: _reader dialect: _DialectLike line_num: int - fieldnames: Optional[Sequence[str]] + @overload def __init__( self, f: Iterable[Text], + fieldnames: Sequence[_T], + restkey: Optional[str] = ..., + restval: Optional[str] = ..., + dialect: _DialectLike = ..., + *args: Any, + **kwds: Any, + ) -> None: ... + @overload + def __init__( + self: DictReader[str], + f: Iterable[Text], fieldnames: Optional[Sequence[str]] = ..., restkey: Optional[str] = ..., restval: Optional[str] = ..., @@ -66,21 +75,21 @@ class DictReader(Iterator[_DRMapping]): *args: Any, **kwds: Any, ) -> None: ... - def __iter__(self) -> DictReader: ... + def __iter__(self) -> DictReader[_T]: ... if sys.version_info >= (3,): - def __next__(self) -> _DRMapping: ... + def __next__(self) -> _DictReadMapping[_T, str]: ... else: - def next(self) -> _DRMapping: ... + def next(self) -> _DictReadMapping[_T, str]: ... -class DictWriter(object): - fieldnames: Sequence[str] +class DictWriter(Generic[_T]): + fieldnames: Sequence[_T] restval: Optional[Any] extrasaction: str writer: _writer def __init__( self, f: Any, - fieldnames: Iterable[str], + fieldnames: Sequence[_T], restval: Optional[Any] = ..., extrasaction: str = ..., dialect: _DialectLike = ..., @@ -91,8 +100,8 @@ class DictWriter(object): def writeheader(self) -> Any: ... else: def writeheader(self) -> None: ... - def writerow(self, rowdict: _DictRow) -> Any: ... - def writerows(self, rowdicts: Iterable[_DictRow]) -> None: ... + def writerow(self, rowdict: Mapping[_T, Any]) -> Any: ... + def writerows(self, rowdicts: Iterable[Mapping[_T, Any]]) -> None: ... class Sniffer(object): preferred: List[str] diff --git a/mypy/typeshed/stdlib/formatter.pyi b/mypy/typeshed/stdlib/formatter.pyi index d3ecaec5fab9..31c45592a215 100644 --- a/mypy/typeshed/stdlib/formatter.pyi +++ b/mypy/typeshed/stdlib/formatter.pyi @@ -1,99 +1,103 @@ -import sys from typing import IO, Any, Iterable, List, Optional, Tuple -if sys.version_info < (3, 10): - AS_IS: None - _FontType = Tuple[str, bool, bool, bool] - _StylesType = Tuple[Any, ...] - class NullFormatter: - writer: Optional[NullWriter] - def __init__(self, writer: Optional[NullWriter] = ...) -> None: ... - def end_paragraph(self, blankline: int) -> None: ... - def add_line_break(self) -> None: ... - def add_hor_rule(self, *args: Any, **kw: Any) -> None: ... - def add_label_data(self, format: str, counter: int, blankline: Optional[int] = ...) -> None: ... - def add_flowing_data(self, data: str) -> None: ... - def add_literal_data(self, data: str) -> None: ... - def flush_softspace(self) -> None: ... - def push_alignment(self, align: Optional[str]) -> None: ... - def pop_alignment(self) -> None: ... - def push_font(self, x: _FontType) -> None: ... - def pop_font(self) -> None: ... - def push_margin(self, margin: int) -> None: ... - def pop_margin(self) -> None: ... - def set_spacing(self, spacing: Optional[str]) -> None: ... - def push_style(self, *styles: _StylesType) -> None: ... - def pop_style(self, n: int = ...) -> None: ... - def assert_line_data(self, flag: int = ...) -> None: ... - class AbstractFormatter: - writer: NullWriter - align: Optional[str] - align_stack: List[Optional[str]] - font_stack: List[_FontType] - margin_stack: List[int] - spacing: Optional[str] - style_stack: Any - nospace: int - softspace: int - para_end: int - parskip: int - hard_break: int - have_label: int - def __init__(self, writer: NullWriter) -> None: ... - def end_paragraph(self, blankline: int) -> None: ... - def add_line_break(self) -> None: ... - def add_hor_rule(self, *args: Any, **kw: Any) -> None: ... - def add_label_data(self, format: str, counter: int, blankline: Optional[int] = ...) -> None: ... - def format_counter(self, format: Iterable[str], counter: int) -> str: ... - def format_letter(self, case: str, counter: int) -> str: ... - def format_roman(self, case: str, counter: int) -> str: ... - def add_flowing_data(self, data: str) -> None: ... - def add_literal_data(self, data: str) -> None: ... - def flush_softspace(self) -> None: ... - def push_alignment(self, align: Optional[str]) -> None: ... - def pop_alignment(self) -> None: ... - def push_font(self, font: _FontType) -> None: ... - def pop_font(self) -> None: ... - def push_margin(self, margin: int) -> None: ... - def pop_margin(self) -> None: ... - def set_spacing(self, spacing: Optional[str]) -> None: ... - def push_style(self, *styles: _StylesType) -> None: ... - def pop_style(self, n: int = ...) -> None: ... - def assert_line_data(self, flag: int = ...) -> None: ... - class NullWriter: - def __init__(self) -> None: ... - def flush(self) -> None: ... - def new_alignment(self, align: Optional[str]) -> None: ... - def new_font(self, font: _FontType) -> None: ... - def new_margin(self, margin: int, level: int) -> None: ... - def new_spacing(self, spacing: Optional[str]) -> None: ... - def new_styles(self, styles: Tuple[Any, ...]) -> None: ... - def send_paragraph(self, blankline: int) -> None: ... - def send_line_break(self) -> None: ... - def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... - def send_label_data(self, data: str) -> None: ... - def send_flowing_data(self, data: str) -> None: ... - def send_literal_data(self, data: str) -> None: ... - class AbstractWriter(NullWriter): - def new_alignment(self, align: Optional[str]) -> None: ... - def new_font(self, font: _FontType) -> None: ... - def new_margin(self, margin: int, level: int) -> None: ... - def new_spacing(self, spacing: Optional[str]) -> None: ... - def new_styles(self, styles: Tuple[Any, ...]) -> None: ... - def send_paragraph(self, blankline: int) -> None: ... - def send_line_break(self) -> None: ... - def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... - def send_label_data(self, data: str) -> None: ... - def send_flowing_data(self, data: str) -> None: ... - def send_literal_data(self, data: str) -> None: ... - class DumbWriter(NullWriter): - file: IO[str] - maxcol: int - def __init__(self, file: Optional[IO[str]] = ..., maxcol: int = ...) -> None: ... - def reset(self) -> None: ... - def send_paragraph(self, blankline: int) -> None: ... - def send_line_break(self) -> None: ... - def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... - def send_literal_data(self, data: str) -> None: ... - def send_flowing_data(self, data: str) -> None: ... - def test(file: Optional[str] = ...) -> None: ... +AS_IS: None +_FontType = Tuple[str, bool, bool, bool] +_StylesType = Tuple[Any, ...] + +class NullFormatter: + writer: Optional[NullWriter] + def __init__(self, writer: Optional[NullWriter] = ...) -> None: ... + def end_paragraph(self, blankline: int) -> None: ... + def add_line_break(self) -> None: ... + def add_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def add_label_data(self, format: str, counter: int, blankline: Optional[int] = ...) -> None: ... + def add_flowing_data(self, data: str) -> None: ... + def add_literal_data(self, data: str) -> None: ... + def flush_softspace(self) -> None: ... + def push_alignment(self, align: Optional[str]) -> None: ... + def pop_alignment(self) -> None: ... + def push_font(self, x: _FontType) -> None: ... + def pop_font(self) -> None: ... + def push_margin(self, margin: int) -> None: ... + def pop_margin(self) -> None: ... + def set_spacing(self, spacing: Optional[str]) -> None: ... + def push_style(self, *styles: _StylesType) -> None: ... + def pop_style(self, n: int = ...) -> None: ... + def assert_line_data(self, flag: int = ...) -> None: ... + +class AbstractFormatter: + writer: NullWriter + align: Optional[str] + align_stack: List[Optional[str]] + font_stack: List[_FontType] + margin_stack: List[int] + spacing: Optional[str] + style_stack: Any + nospace: int + softspace: int + para_end: int + parskip: int + hard_break: int + have_label: int + def __init__(self, writer: NullWriter) -> None: ... + def end_paragraph(self, blankline: int) -> None: ... + def add_line_break(self) -> None: ... + def add_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def add_label_data(self, format: str, counter: int, blankline: Optional[int] = ...) -> None: ... + def format_counter(self, format: Iterable[str], counter: int) -> str: ... + def format_letter(self, case: str, counter: int) -> str: ... + def format_roman(self, case: str, counter: int) -> str: ... + def add_flowing_data(self, data: str) -> None: ... + def add_literal_data(self, data: str) -> None: ... + def flush_softspace(self) -> None: ... + def push_alignment(self, align: Optional[str]) -> None: ... + def pop_alignment(self) -> None: ... + def push_font(self, font: _FontType) -> None: ... + def pop_font(self) -> None: ... + def push_margin(self, margin: int) -> None: ... + def pop_margin(self) -> None: ... + def set_spacing(self, spacing: Optional[str]) -> None: ... + def push_style(self, *styles: _StylesType) -> None: ... + def pop_style(self, n: int = ...) -> None: ... + def assert_line_data(self, flag: int = ...) -> None: ... + +class NullWriter: + def __init__(self) -> None: ... + def flush(self) -> None: ... + def new_alignment(self, align: Optional[str]) -> None: ... + def new_font(self, font: _FontType) -> None: ... + def new_margin(self, margin: int, level: int) -> None: ... + def new_spacing(self, spacing: Optional[str]) -> None: ... + def new_styles(self, styles: Tuple[Any, ...]) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def send_label_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + def send_literal_data(self, data: str) -> None: ... + +class AbstractWriter(NullWriter): + def new_alignment(self, align: Optional[str]) -> None: ... + def new_font(self, font: _FontType) -> None: ... + def new_margin(self, margin: int, level: int) -> None: ... + def new_spacing(self, spacing: Optional[str]) -> None: ... + def new_styles(self, styles: Tuple[Any, ...]) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def send_label_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + def send_literal_data(self, data: str) -> None: ... + +class DumbWriter(NullWriter): + file: IO[str] + maxcol: int + def __init__(self, file: Optional[IO[str]] = ..., maxcol: int = ...) -> None: ... + def reset(self) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args: Any, **kw: Any) -> None: ... + def send_literal_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + +def test(file: Optional[str] = ...) -> None: ... diff --git a/mypy/typeshed/stdlib/functools.pyi b/mypy/typeshed/stdlib/functools.pyi index ceb6ffcb3f11..d4a492c0102e 100644 --- a/mypy/typeshed/stdlib/functools.pyi +++ b/mypy/typeshed/stdlib/functools.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import SupportsLessThan +from _typeshed import SupportsItems, SupportsLessThan from typing import ( Any, Callable, @@ -11,6 +11,8 @@ from typing import ( NamedTuple, Optional, Sequence, + Set, + Sized, Tuple, Type, TypeVar, @@ -131,3 +133,14 @@ if sys.version_info >= (3, 8): if sys.version_info >= (3, 9): def cache(__user_function: Callable[..., _T]) -> _lru_cache_wrapper[_T]: ... + +def _make_key( + args: Tuple[Hashable, ...], + kwds: SupportsItems[Any, Any], + typed: bool, + kwd_mark: Tuple[object, ...] = ..., + fasttypes: Set[type] = ..., + tuple: type = ..., + type: Any = ..., + len: Callable[[Sized], int] = ..., +) -> Hashable: ... diff --git a/mypy/typeshed/stdlib/genericpath.pyi b/mypy/typeshed/stdlib/genericpath.pyi index fc314f0a1658..28c94ae1676a 100644 --- a/mypy/typeshed/stdlib/genericpath.pyi +++ b/mypy/typeshed/stdlib/genericpath.pyi @@ -1,22 +1,32 @@ +import os import sys -from _typeshed import AnyPath -from typing import AnyStr, Sequence, Text - -if sys.version_info >= (3, 0): - def commonprefix(m: Sequence[str]) -> str: ... - -else: - def commonprefix(m: Sequence[AnyStr]) -> AnyStr: ... +from _typeshed import AnyPath, BytesPath, StrPath, SupportsLessThanT +from typing import List, Sequence, Tuple, Union, overload +from typing_extensions import Literal +# All overloads can return empty string. Ideally, Literal[""] would be a valid +# Iterable[T], so that Union[List[T], Literal[""]] could be used as a return +# type. But because this only works when T is str, we need Sequence[T] instead. +@overload +def commonprefix(m: Sequence[StrPath]) -> str: ... +@overload +def commonprefix(m: Sequence[BytesPath]) -> Union[bytes, Literal[""]]: ... +@overload +def commonprefix(m: Sequence[List[SupportsLessThanT]]) -> Sequence[SupportsLessThanT]: ... +@overload +def commonprefix(m: Sequence[Tuple[SupportsLessThanT, ...]]) -> Sequence[SupportsLessThanT]: ... def exists(path: AnyPath) -> bool: ... -def isfile(path: Text) -> bool: ... -def isdir(s: Text) -> bool: ... -def getsize(filename: Text) -> int: ... -def getmtime(filename: Text) -> float: ... -def getatime(filename: Text) -> float: ... -def getctime(filename: Text) -> float: ... +def getsize(filename: AnyPath) -> int: ... +def isfile(path: AnyPath) -> bool: ... +def isdir(s: AnyPath) -> bool: ... + +# These return float if os.stat_float_times() == True, +# but int is a subclass of float. +def getatime(filename: AnyPath) -> float: ... +def getmtime(filename: AnyPath) -> float: ... +def getctime(filename: AnyPath) -> float: ... if sys.version_info >= (3, 4): - def samestat(s1: str, s2: str) -> int: ... - def samefile(f1: str, f2: str) -> int: ... - def sameopenfile(fp1: str, fp2: str) -> int: ... + def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... + def sameopenfile(fp1: int, fp2: int) -> bool: ... + def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... diff --git a/mypy/typeshed/stdlib/grp.pyi b/mypy/typeshed/stdlib/grp.pyi index 5b5855583243..8447f21736bb 100644 --- a/mypy/typeshed/stdlib/grp.pyi +++ b/mypy/typeshed/stdlib/grp.pyi @@ -7,5 +7,5 @@ class struct_group(NamedTuple): gr_mem: List[str] def getgrall() -> List[struct_group]: ... -def getgrgid(gid: int) -> struct_group: ... +def getgrgid(id: int) -> struct_group: ... def getgrnam(name: str) -> struct_group: ... diff --git a/mypy/typeshed/stdlib/locale.pyi b/mypy/typeshed/stdlib/locale.pyi index 920c006cda01..9be4aa2735e1 100644 --- a/mypy/typeshed/stdlib/locale.pyi +++ b/mypy/typeshed/stdlib/locale.pyi @@ -81,7 +81,7 @@ class Error(Exception): ... def setlocale(category: int, locale: Union[_str, Iterable[_str], None] = ...) -> _str: ... def localeconv() -> Mapping[_str, Union[int, _str, List[int]]]: ... -def nl_langinfo(option: int) -> _str: ... +def nl_langinfo(__key: int) -> _str: ... def getdefaultlocale(envvars: Tuple[_str, ...] = ...) -> Tuple[Optional[_str], Optional[_str]]: ... def getlocale(category: int = ...) -> Sequence[_str]: ... def getpreferredencoding(do_setlocale: bool = ...) -> _str: ... diff --git a/mypy/typeshed/stdlib/logging/__init__.pyi b/mypy/typeshed/stdlib/logging/__init__.pyi index 135d64a38a57..1cce244e5798 100644 --- a/mypy/typeshed/stdlib/logging/__init__.pyi +++ b/mypy/typeshed/stdlib/logging/__init__.pyi @@ -5,9 +5,9 @@ from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequenc from string import Template from time import struct_time from types import FrameType, TracebackType -from typing import IO, Any, ClassVar, Optional, Tuple, Type, Union +from typing import IO, Any, ClassVar, Optional, Pattern, Tuple, Type, Union -_SysExcInfoType = Union[Tuple[type, BaseException, Optional[TracebackType]], Tuple[None, None, None]] +_SysExcInfoType = Union[Tuple[Type[BaseException], BaseException, Optional[TracebackType]], Tuple[None, None, None]] _ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException] _ArgsType = Union[Tuple[Any, ...], Mapping[str, Any]] _FilterType = Union[Filter, Callable[[LogRecord], int]] @@ -31,7 +31,7 @@ class Filterer(object): def removeFilter(self, filter: _FilterType) -> None: ... def filter(self, record: LogRecord) -> bool: ... -class Manager(object): +class Manager(object): # undocumented root: RootLogger disable: int emittedNoHandlerWarning: bool @@ -44,14 +44,14 @@ class Manager(object): def setLogRecordFactory(self, factory: Callable[..., LogRecord]) -> None: ... class Logger(Filterer): - name: str - level: int - parent: Union[Logger, PlaceHolder] + name: str # undocumented + level: int # undocumented + parent: Optional[Logger] # undocumented propagate: bool - handlers: list[Handler] - disabled: int + handlers: list[Handler] # undocumented + disabled: bool # undocumented root: ClassVar[RootLogger] # undocumented - manager: ClassVar[Manager] # undocumented + manager: Manager # undocumented def __init__(self, name: str, level: _Level = ...) -> None: ... def setLevel(self, level: _Level) -> None: ... def isEnabledFor(self, level: int) -> bool: ... @@ -204,7 +204,6 @@ class Logger(Filterer): extra: Optional[dict[str, Any]] = ..., **kwargs: Any, ) -> None: ... - fatal = critical def log( self, level: int, @@ -233,6 +232,7 @@ class Logger(Filterer): extra: Optional[dict[str, Any]] = ..., stack_info: bool = ..., ) -> None: ... # undocumented + fatal = critical def filter(self, record: LogRecord) -> bool: ... def addHandler(self, hdlr: Handler) -> None: ... def removeHandler(self, hdlr: Handler) -> None: ... @@ -255,6 +255,7 @@ class Logger(Filterer): sinfo: Optional[str] = ..., ) -> LogRecord: ... def hasHandlers(self) -> bool: ... + def callHandlers(self, record: LogRecord) -> None: ... # undocumented CRITICAL: int FATAL: int @@ -271,26 +272,31 @@ class Handler(Filterer): lock: Optional[threading.Lock] # undocumented name: Optional[str] # undocumented def __init__(self, level: _Level = ...) -> None: ... + def get_name(self) -> str: ... # undocumented + def set_name(self, name: str) -> None: ... # undocumented def createLock(self) -> None: ... def acquire(self) -> None: ... def release(self) -> None: ... def setLevel(self, level: _Level) -> None: ... - def setFormatter(self, fmt: Formatter) -> None: ... + def setFormatter(self, fmt: Optional[Formatter]) -> None: ... def filter(self, record: LogRecord) -> bool: ... def flush(self) -> None: ... def close(self) -> None: ... - def handle(self, record: LogRecord) -> None: ... + def handle(self, record: LogRecord) -> bool: ... def handleError(self, record: LogRecord) -> None: ... def format(self, record: LogRecord) -> str: ... def emit(self, record: LogRecord) -> None: ... class Formatter: converter: Callable[[Optional[float]], struct_time] - _fmt: Optional[str] - datefmt: Optional[str] - _style: PercentStyle + _fmt: Optional[str] # undocumented + datefmt: Optional[str] # undocumented + _style: PercentStyle # undocumented default_time_format: str - default_msec_format: str + if sys.version_info >= (3, 9): + default_msec_format: Optional[str] + else: + default_msec_format: str if sys.version_info >= (3, 8): def __init__( @@ -303,15 +309,25 @@ class Formatter: def formatException(self, ei: _SysExcInfoType) -> str: ... def formatMessage(self, record: LogRecord) -> str: ... # undocumented def formatStack(self, stack_info: str) -> str: ... + def usesTime(self) -> bool: ... # undocumented + +class BufferingFormatter: + linefmt: Formatter + def __init__(self, linefmt: Optional[Formatter] = ...) -> None: ... + def formatHeader(self, records: Sequence[LogRecord]) -> str: ... + def formatFooter(self, records: Sequence[LogRecord]) -> str: ... + def format(self, records: Sequence[LogRecord]) -> str: ... class Filter: + name: str # undocumented + nlen: int # undocumented def __init__(self, name: str = ...) -> None: ... def filter(self, record: LogRecord) -> bool: ... class LogRecord: args: _ArgsType asctime: str - created: int + created: float exc_info: Optional[_SysExcInfoType] exc_text: Optional[str] filename: str @@ -320,17 +336,17 @@ class LogRecord: levelno: int lineno: int module: str - msecs: int + msecs: float message: str msg: str name: str pathname: str - process: int - processName: str - relativeCreated: int + process: Optional[int] + processName: Optional[str] + relativeCreated: float stack_info: Optional[str] - thread: int - threadName: str + thread: Optional[int] + threadName: Optional[str] def __init__( self, name: str, @@ -347,8 +363,13 @@ class LogRecord: class LoggerAdapter: logger: Logger - extra: Mapping[str, Any] - def __init__(self, logger: Logger, extra: Mapping[str, Any]) -> None: ... + manager: Manager # undocumented + if sys.version_info >= (3, 10): + extra: Optional[Mapping[str, Any]] + def __init__(self, logger: Logger, extra: Optional[Mapping[str, Any]]) -> None: ... + else: + extra: Mapping[str, Any] + def __init__(self, logger: Logger, extra: Mapping[str, Any]) -> None: ... def process(self, msg: Any, kwargs: MutableMapping[str, Any]) -> tuple[Any, MutableMapping[str, Any]]: ... if sys.version_info >= (3, 8): def debug( @@ -508,7 +529,7 @@ class LoggerAdapter: ) -> None: ... def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... - def setLevel(self, level: Union[int, str]) -> None: ... + def setLevel(self, level: _Level) -> None: ... def hasHandlers(self) -> bool: ... def _log( self, @@ -519,9 +540,11 @@ class LoggerAdapter: extra: Optional[dict[str, Any]] = ..., stack_info: bool = ..., ) -> None: ... # undocumented + @property + def name(self) -> str: ... # undocumented def getLogger(name: Optional[str] = ...) -> Logger: ... -def getLoggerClass() -> type: ... +def getLoggerClass() -> Type[Logger]: ... def getLogRecordFactory() -> Callable[..., LogRecord]: ... if sys.version_info >= (3, 8): @@ -675,7 +698,7 @@ else: def disable(level: int) -> None: ... def addLevelName(level: int, levelName: str) -> None: ... -def getLevelName(level: Union[int, str]) -> Any: ... +def getLevelName(level: _Level) -> Any: ... def makeLogRecord(dict: Mapping[str, Any]) -> LogRecord: ... if sys.version_info >= (3, 8): @@ -724,12 +747,24 @@ class FileHandler(StreamHandler): mode: str # undocumented encoding: Optional[str] # undocumented delay: bool # undocumented - def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ... + if sys.version_info >= (3, 9): + errors: Optional[str] # undocumented + def __init__( + self, + filename: StrPath, + mode: str = ..., + encoding: Optional[str] = ..., + delay: bool = ..., + errors: Optional[str] = ..., + ) -> None: ... + else: + def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ... def _open(self) -> IO[Any]: ... class NullHandler(Handler): ... -class PlaceHolder: +class PlaceHolder: # undocumented + loggerMap: dict[Logger, None] def __init__(self, alogger: Logger) -> None: ... def append(self, alogger: Logger) -> None: ... @@ -740,18 +775,24 @@ class RootLogger(Logger): root: RootLogger -class PercentStyle(object): +class PercentStyle(object): # undocumented default_format: str asctime_format: str asctime_search: str + if sys.version_info >= (3, 8): + validation_pattern: Pattern[str] _fmt: str def __init__(self, fmt: str) -> None: ... def usesTime(self) -> bool: ... + if sys.version_info >= (3, 8): + def validate(self) -> None: ... def format(self, record: Any) -> str: ... -class StrFormatStyle(PercentStyle): ... +class StrFormatStyle(PercentStyle): # undocumented + fmt_spec = Any + field_spec = Any -class StringTemplateStyle(PercentStyle): +class StringTemplateStyle(PercentStyle): # undocumented _tpl: Template _STYLES: dict[str, tuple[PercentStyle, str]] diff --git a/mypy/typeshed/stdlib/logging/config.pyi b/mypy/typeshed/stdlib/logging/config.pyi index c06f0b25291f..be2f2e68508d 100644 --- a/mypy/typeshed/stdlib/logging/config.pyi +++ b/mypy/typeshed/stdlib/logging/config.pyi @@ -3,16 +3,39 @@ from _typeshed import AnyPath, StrPath from collections.abc import Callable from configparser import RawConfigParser from threading import Thread -from typing import IO, Any, Optional, Union +from typing import IO, Any, Optional, Pattern, Union + +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal if sys.version_info >= (3, 7): _Path = AnyPath else: _Path = StrPath +DEFAULT_LOGGING_CONFIG_PORT: int +RESET_ERROR: int # undocumented +IDENTIFIER: Pattern[str] # undocumented + def dictConfig(config: dict[str, Any]) -> None: ... -def fileConfig( - fname: Union[_Path, IO[str], RawConfigParser], defaults: Optional[dict[str, str]] = ..., disable_existing_loggers: bool = ... -) -> None: ... + +if sys.version_info >= (3, 10): + def fileConfig( + fname: Union[_Path, IO[str], RawConfigParser], + defaults: Optional[dict[str, str]] = ..., + disable_existing_loggers: bool = ..., + encoding: Optional[str] = ..., + ) -> None: ... + +else: + def fileConfig( + fname: Union[_Path, IO[str], RawConfigParser], + defaults: Optional[dict[str, str]] = ..., + disable_existing_loggers: bool = ..., + ) -> None: ... + +def valid_ident(s: str) -> Literal[True]: ... # undocumented def listen(port: int = ..., verify: Optional[Callable[[bytes], Optional[bytes]]] = ...) -> Thread: ... def stopListening() -> None: ... diff --git a/mypy/typeshed/stdlib/logging/handlers.pyi b/mypy/typeshed/stdlib/logging/handlers.pyi index 4c20d4af2b56..a60190ee5bce 100644 --- a/mypy/typeshed/stdlib/logging/handlers.pyi +++ b/mypy/typeshed/stdlib/logging/handlers.pyi @@ -1,11 +1,12 @@ import datetime +import http.client import ssl import sys from _typeshed import StrPath from collections.abc import Callable from logging import FileHandler, Handler, LogRecord from socket import SocketKind, SocketType -from typing import Any, ClassVar, Optional, Union +from typing import Any, ClassVar, Optional, Pattern, Union if sys.version_info >= (3, 7): from queue import Queue, SimpleQueue @@ -20,49 +21,111 @@ SYSLOG_UDP_PORT: int SYSLOG_TCP_PORT: int class WatchedFileHandler(FileHandler): - dev: int - ino: int - def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ... - def _statstream(self) -> None: ... + dev: int # undocumented + ino: int # undocumented + if sys.version_info >= (3, 9): + def __init__( + self, + filename: StrPath, + mode: str = ..., + encoding: Optional[str] = ..., + delay: bool = ..., + errors: Optional[str] = ..., + ) -> None: ... + else: + def __init__(self, filename: StrPath, mode: str = ..., encoding: Optional[str] = ..., delay: bool = ...) -> None: ... + def _statstream(self) -> None: ... # undocumented + def reopenIfNeeded(self) -> None: ... class BaseRotatingHandler(FileHandler): - terminator: str namer: Optional[Callable[[str], str]] rotator: Optional[Callable[[str, str], None]] - def __init__(self, filename: StrPath, mode: str, encoding: Optional[str] = ..., delay: bool = ...) -> None: ... - def rotation_filename(self, default_name: str) -> None: ... + if sys.version_info >= (3, 9): + def __init__( + self, filename: StrPath, mode: str, encoding: Optional[str] = ..., delay: bool = ..., errors: Optional[str] = ... + ) -> None: ... + else: + def __init__(self, filename: StrPath, mode: str, encoding: Optional[str] = ..., delay: bool = ...) -> None: ... + def rotation_filename(self, default_name: str) -> str: ... def rotate(self, source: str, dest: str) -> None: ... class RotatingFileHandler(BaseRotatingHandler): - def __init__( - self, - filename: StrPath, - mode: str = ..., - maxBytes: int = ..., - backupCount: int = ..., - encoding: Optional[str] = ..., - delay: bool = ..., - ) -> None: ... + maxBytes: str # undocumented + backupCount: str # undocumented + if sys.version_info >= (3, 9): + def __init__( + self, + filename: StrPath, + mode: str = ..., + maxBytes: int = ..., + backupCount: int = ..., + encoding: Optional[str] = ..., + delay: bool = ..., + errors: Optional[str] = ..., + ) -> None: ... + else: + def __init__( + self, + filename: StrPath, + mode: str = ..., + maxBytes: int = ..., + backupCount: int = ..., + encoding: Optional[str] = ..., + delay: bool = ..., + ) -> None: ... def doRollover(self) -> None: ... + def shouldRollover(self, record: LogRecord) -> int: ... # undocumented class TimedRotatingFileHandler(BaseRotatingHandler): - def __init__( - self, - filename: StrPath, - when: str = ..., - interval: int = ..., - backupCount: int = ..., - encoding: Optional[str] = ..., - delay: bool = ..., - utc: bool = ..., - atTime: Optional[datetime.datetime] = ..., - ) -> None: ... + when: str # undocumented + backupCount: str # undocumented + utc: bool # undocumented + atTime: Optional[datetime.datetime] # undocumented + interval: int # undocumented + suffix: str # undocumented + dayOfWeek: int # undocumented + rolloverAt: int # undocumented + extMatch: Pattern[str] # undocumented + if sys.version_info >= (3, 9): + def __init__( + self, + filename: StrPath, + when: str = ..., + interval: int = ..., + backupCount: int = ..., + encoding: Optional[str] = ..., + delay: bool = ..., + utc: bool = ..., + atTime: Optional[datetime.datetime] = ..., + errors: Optional[str] = ..., + ) -> None: ... + else: + def __init__( + self, + filename: StrPath, + when: str = ..., + interval: int = ..., + backupCount: int = ..., + encoding: Optional[str] = ..., + delay: bool = ..., + utc: bool = ..., + atTime: Optional[datetime.datetime] = ..., + ) -> None: ... def doRollover(self) -> None: ... + def shouldRollover(self, record: LogRecord) -> int: ... # undocumented + def computeRollover(self, currentTime: int) -> int: ... # undocumented + def getFilesToDelete(self) -> list[str]: ... # undocumented class SocketHandler(Handler): - retryStart: float - retryFactor: float - retryMax: float + host: str # undocumented + port: Optional[int] # undocumented + address: Union[tuple[str, int], str] # undocumented + sock: Optional[SocketType] # undocumented + closeOnError: bool # undocumented + retryTime: Optional[float] # undocumented + retryStart: float # undocumented + retryFactor: float # undocumented + retryMax: float # undocumented def __init__(self, host: str, port: Optional[int]) -> None: ... def makeSocket(self, timeout: float = ...) -> SocketType: ... # timeout is undocumented def makePickle(self, record: LogRecord) -> bytes: ... @@ -112,6 +175,7 @@ class SysLogHandler(Handler): unixsocket: bool # undocumented socktype: SocketKind # undocumented ident: str # undocumented + append_nul: bool # undocumented facility: int # undocumented priority_names: ClassVar[dict[str, int]] # undocumented facility_names: ClassVar[dict[str, int]] # undocumented @@ -130,31 +194,50 @@ class NTEventLogHandler(Handler): def getMessageID(self, record: LogRecord) -> int: ... class SMTPHandler(Handler): - # TODO `secure` can also be an empty tuple + mailhost: str # undocumented + mailport: Optional[int] # undocumented + username: Optional[str] # undocumented + # password only exists as an attribute if passed credentials is a tuple or list + password: str # undocumented + fromaddr: str # undocumented + toaddrs: list[str] # undocumented + subject: str # undocumented + secure: Union[tuple[()], tuple[str], tuple[str, str], None] # undocumented + timeout: float # undocumented def __init__( self, mailhost: Union[str, tuple[str, int]], fromaddr: str, - toaddrs: list[str], + toaddrs: Union[str, list[str]], subject: str, credentials: Optional[tuple[str, str]] = ..., - secure: Union[tuple[str], tuple[str, str], None] = ..., + secure: Union[tuple[()], tuple[str], tuple[str, str], None] = ..., timeout: float = ..., ) -> None: ... def getSubject(self, record: LogRecord) -> str: ... class BufferingHandler(Handler): - buffer: list[LogRecord] + capacity: int # undocumented + buffer: list[LogRecord] # undocumented def __init__(self, capacity: int) -> None: ... def shouldFlush(self, record: LogRecord) -> bool: ... class MemoryHandler(BufferingHandler): + flushLevel: int # undocumented + target: Optional[Handler] # undocumented + flushOnClose: bool # undocumented def __init__( self, capacity: int, flushLevel: int = ..., target: Optional[Handler] = ..., flushOnClose: bool = ... ) -> None: ... - def setTarget(self, target: Handler) -> None: ... + def setTarget(self, target: Optional[Handler]) -> None: ... class HTTPHandler(Handler): + host: str # undocumented + url: str # undocumented + method: str # undocumented + secure: bool # undocumented + credentials: Optional[tuple[str, str]] # undocumented + context: Optional[ssl.SSLContext] # undocumented def __init__( self, host: str, @@ -165,24 +248,33 @@ class HTTPHandler(Handler): context: Optional[ssl.SSLContext] = ..., ) -> None: ... def mapLogRecord(self, record: LogRecord) -> dict[str, Any]: ... + if sys.version_info >= (3, 9): + def getConnection(self, host: str, secure: bool) -> http.client.HTTPConnection: ... # undocumented class QueueHandler(Handler): if sys.version_info >= (3, 7): + queue: Union[SimpleQueue[Any], Queue[Any]] # undocumented def __init__(self, queue: Union[SimpleQueue[Any], Queue[Any]]) -> None: ... else: + queue: Queue[Any] # undocumented def __init__(self, queue: Queue[Any]) -> None: ... def prepare(self, record: LogRecord) -> Any: ... def enqueue(self, record: LogRecord) -> None: ... class QueueListener: + handlers: tuple[Handler] # undocumented + respect_handler_level: bool # undocumented if sys.version_info >= (3, 7): + queue: Union[SimpleQueue[Any], Queue[Any]] # undocumented def __init__( self, queue: Union[SimpleQueue[Any], Queue[Any]], *handlers: Handler, respect_handler_level: bool = ... ) -> None: ... else: + queue: Queue[Any] # undocumented def __init__(self, queue: Queue[Any], *handlers: Handler, respect_handler_level: bool = ...) -> None: ... def dequeue(self, block: bool) -> LogRecord: ... def prepare(self, record: LogRecord) -> Any: ... def start(self) -> None: ... def stop(self) -> None: ... def enqueue_sentinel(self) -> None: ... + def handle(self, record: LogRecord) -> None: ... diff --git a/mypy/typeshed/stdlib/macpath.pyi b/mypy/typeshed/stdlib/macpath.pyi index 2a81776605b5..296f3a9ba151 100644 --- a/mypy/typeshed/stdlib/macpath.pyi +++ b/mypy/typeshed/stdlib/macpath.pyi @@ -1,132 +1,104 @@ -import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, Union, overload +from genericpath import ( + commonprefix as commonprefix, + exists as exists, + getatime as getatime, + getctime as getctime, + getmtime as getmtime, + getsize as getsize, + isdir as isdir, + isfile as isfile, +) -if sys.version_info < (3, 8): - _T = TypeVar("_T") +if sys.version_info >= (3, 4): + from genericpath import samefile as samefile, sameopenfile as sameopenfile, samestat as samestat - if sys.version_info >= (3, 6): - from os import PathLike +# Re-export common definitions from posixpath to reduce duplication +from posixpath import ( + abspath as abspath, + curdir as curdir, + defpath as defpath, + devnull as devnull, + expanduser as expanduser, + expandvars as expandvars, + extsep as extsep, + isabs as isabs, + lexists as lexists, + pardir as pardir, + pathsep as pathsep, + sep as sep, + splitdrive as splitdrive, + splitext as splitext, + supports_unicode_filenames as supports_unicode_filenames, +) +from typing import AnyStr, Optional, Text, Tuple, overload - # ----- os.path variables ----- - supports_unicode_filenames: bool - # aliases (also in os) - curdir: str - pardir: str - sep: str - altsep: Optional[str] - extsep: str - pathsep: str - defpath: str - devnull: str +altsep: Optional[str] - # ----- os.path function stubs ----- - if sys.version_info >= (3, 6): - # Overloads are necessary to work around python/mypy#3644. - @overload - def abspath(path: PathLike[AnyStr]) -> AnyStr: ... - @overload - def abspath(path: AnyStr) -> AnyStr: ... - @overload - def basename(s: PathLike[AnyStr]) -> AnyStr: ... - @overload - def basename(s: AnyStr) -> AnyStr: ... - @overload - def dirname(s: PathLike[AnyStr]) -> AnyStr: ... - @overload - def dirname(s: AnyStr) -> AnyStr: ... - @overload - def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... - @overload - def expanduser(path: AnyStr) -> AnyStr: ... - @overload - def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... - @overload - def expandvars(path: AnyStr) -> AnyStr: ... - @overload - def normcase(path: PathLike[AnyStr]) -> AnyStr: ... - @overload - def normcase(path: AnyStr) -> AnyStr: ... - @overload - def normpath(s: PathLike[AnyStr]) -> AnyStr: ... - @overload - def normpath(s: AnyStr) -> AnyStr: ... - @overload - def realpath(path: PathLike[AnyStr]) -> AnyStr: ... - @overload - def realpath(path: AnyStr) -> AnyStr: ... - else: - def abspath(path: AnyStr) -> AnyStr: ... - def basename(s: AnyStr) -> AnyStr: ... - def dirname(s: AnyStr) -> AnyStr: ... - def expanduser(path: AnyStr) -> AnyStr: ... - def expandvars(path: AnyStr) -> AnyStr: ... - def normcase(path: AnyStr) -> AnyStr: ... - def normpath(s: AnyStr) -> AnyStr: ... - def realpath(path: AnyStr) -> AnyStr: ... - # NOTE: Empty lists results in '' (str) regardless of contained type. - # Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes - # So, fall back to Any - def commonprefix(m: Sequence[AnyPath]) -> Any: ... - if sys.version_info >= (3, 3): - def exists(path: Union[AnyPath, int]) -> bool: ... - else: - def exists(path: AnyPath) -> bool: ... - def lexists(path: AnyPath) -> bool: ... - # These return float if os.stat_float_times() == True, - # but int is a subclass of float. - def getatime(filename: AnyPath) -> float: ... - def getmtime(filename: AnyPath) -> float: ... - def getctime(filename: AnyPath) -> float: ... - def getsize(filename: AnyPath) -> int: ... - def isabs(s: AnyPath) -> bool: ... - def isfile(path: AnyPath) -> bool: ... - def isdir(s: AnyPath) -> bool: ... - def islink(s: AnyPath) -> bool: ... - def ismount(s: AnyPath) -> bool: ... - if sys.version_info < (3, 0): - # Make sure signatures are disjunct, and allow combinations of bytes and unicode. - # (Since Python 2 allows that, too) - # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in - # a type error. - @overload - def join(__p1: bytes, *p: bytes) -> bytes: ... - @overload - def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: AnyPath) -> Text: ... - @overload - def join(__p1: bytes, __p2: bytes, __p3: Text, *p: AnyPath) -> Text: ... - @overload - def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ... - @overload - def join(__p1: Text, *p: AnyPath) -> Text: ... - elif sys.version_info >= (3, 6): - # Mypy complains that the signatures overlap, but things seem to behave correctly anyway. - @overload - def join(s: StrPath, *paths: StrPath) -> Text: ... - @overload - def join(s: BytesPath, *paths: BytesPath) -> bytes: ... - else: - def join(s: AnyStr, *paths: AnyStr) -> AnyStr: ... - def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... - def sameopenfile(fp1: int, fp2: int) -> bool: ... - def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... - if sys.version_info >= (3, 6): - @overload - def split(s: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... - @overload - def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - @overload - def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... - @overload - def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - @overload - def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... - @overload - def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - else: - def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - if sys.version_info < (3,): - def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ... +if sys.version_info >= (3, 6): + from os import PathLike + @overload + def basename(s: PathLike[AnyStr]) -> AnyStr: ... + @overload + def basename(s: AnyStr) -> AnyStr: ... + @overload + def dirname(s: PathLike[AnyStr]) -> AnyStr: ... + @overload + def dirname(s: AnyStr) -> AnyStr: ... + @overload + def normcase(path: PathLike[AnyStr]) -> AnyStr: ... + @overload + def normcase(path: AnyStr) -> AnyStr: ... + @overload + def normpath(s: PathLike[AnyStr]) -> AnyStr: ... + @overload + def normpath(s: AnyStr) -> AnyStr: ... + @overload + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... + +else: + def basename(s: AnyStr) -> AnyStr: ... + def dirname(s: AnyStr) -> AnyStr: ... + def normcase(path: AnyStr) -> AnyStr: ... + def normpath(s: AnyStr) -> AnyStr: ... + def realpath(path: AnyStr) -> AnyStr: ... + +def islink(s: AnyPath) -> bool: ... + +if sys.version_info >= (3, 6): + # Mypy complains that the signatures overlap, but things seem to behave correctly anyway. + @overload + def join(s: StrPath, *paths: StrPath) -> Text: ... + @overload + def join(s: BytesPath, *paths: BytesPath) -> bytes: ... + +elif sys.version_info >= (3, 0): + def join(s: AnyStr, *paths: AnyStr) -> AnyStr: ... + +else: + # Make sure signatures are disjunct, and allow combinations of bytes and unicode. + # (Since Python 2 allows that, too) + # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in + # a type error. + @overload + def join(__p1: bytes, *p: bytes) -> bytes: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: AnyPath) -> Text: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: Text, *p: AnyPath) -> Text: ... + @overload + def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ... + @overload + def join(__p1: Text, *p: AnyPath) -> Text: ... + +if sys.version_info >= (3, 6): + @overload + def split(s: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + +else: + def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ... diff --git a/mypy/typeshed/stdlib/macurl2path.pyi b/mypy/typeshed/stdlib/macurl2path.pyi index 41befd1d95c7..025820b44e89 100644 --- a/mypy/typeshed/stdlib/macurl2path.pyi +++ b/mypy/typeshed/stdlib/macurl2path.pyi @@ -1,7 +1,5 @@ -import sys from typing import Union -if sys.version_info < (3, 7): - def url2pathname(pathname: str) -> str: ... - def pathname2url(pathname: str) -> str: ... - def _pncomp2url(component: Union[str, bytes]) -> str: ... +def url2pathname(pathname: str) -> str: ... +def pathname2url(pathname: str) -> str: ... +def _pncomp2url(component: Union[str, bytes]) -> str: ... diff --git a/mypy/typeshed/stdlib/mmap.pyi b/mypy/typeshed/stdlib/mmap.pyi index 7039e3da9870..0ba69e5896d7 100644 --- a/mypy/typeshed/stdlib/mmap.pyi +++ b/mypy/typeshed/stdlib/mmap.pyi @@ -9,11 +9,13 @@ ACCESS_COPY: int ALLOCATIONGRANULARITY: int +if sys.platform == "linux": + MAP_DENYWRITE: int + MAP_EXECUTABLE: int + if sys.platform != "win32": MAP_ANON: int MAP_ANONYMOUS: int - MAP_DENYWRITE: int - MAP_EXECUTABLE: int MAP_PRIVATE: int MAP_SHARED: int PROT_EXEC: int @@ -82,26 +84,37 @@ else: def __delitem__(self, index: Union[int, slice]) -> None: ... def __setitem__(self, index: Union[int, slice], object: bytes) -> None: ... -if sys.version_info >= (3, 8): +if sys.version_info >= (3, 8) and sys.platform != "win32": MADV_NORMAL: int MADV_RANDOM: int MADV_SEQUENTIAL: int MADV_WILLNEED: int MADV_DONTNEED: int - MADV_REMOVE: int - MADV_DONTFORK: int - MADV_DOFORK: int - MADV_HWPOISON: int - MADV_MERGEABLE: int - MADV_UNMERGEABLE: int - MADV_SOFT_OFFLINE: int - MADV_HUGEPAGE: int - MADV_NOHUGEPAGE: int - MADV_DONTDUMP: int - MADV_DODUMP: int - MADV_FREE: int - MADV_NOSYNC: int - MADV_AUTOSYNC: int - MADV_NOCORE: int - MADV_CORE: int - MADV_PROTECT: int + + if sys.platform == "linux": + MADV_REMOVE: int + MADV_DONTFORK: int + MADV_DOFORK: int + MADV_HWPOISON: int + MADV_MERGEABLE: int + MADV_UNMERGEABLE: int + # Seems like this constant is not defined in glibc. + # See https://github.com/python/typeshed/pull/5360 for details + # MADV_SOFT_OFFLINE: int + MADV_HUGEPAGE: int + MADV_NOHUGEPAGE: int + MADV_DONTDUMP: int + MADV_DODUMP: int + MADV_FREE: int + + # This Values are defined for FreeBSD but type checkers do not support conditions for these + if sys.platform != "linux" and sys.platform != "darwin": + MADV_NOSYNC: int + MADV_AUTOSYNC: int + MADV_NOCORE: int + MADV_CORE: int + MADV_PROTECT: int + +if sys.version_info >= (3, 10) and sys.platform == "darwin": + MADV_FREE_REUSABLE: int + MADV_FREE_REUSE: int diff --git a/mypy/typeshed/stdlib/ntpath.pyi b/mypy/typeshed/stdlib/ntpath.pyi index 4ee1b31c64e3..d454d7f93fbf 100644 --- a/mypy/typeshed/stdlib/ntpath.pyi +++ b/mypy/typeshed/stdlib/ntpath.pyi @@ -1,113 +1,70 @@ -import os import sys -from _typeshed import AnyPath, BytesPath, StrPath -from genericpath import exists as exists +from _typeshed import BytesPath, StrPath +from genericpath import ( + commonprefix as commonprefix, + exists as exists, + getatime as getatime, + getctime as getctime, + getmtime as getmtime, + getsize as getsize, + isdir as isdir, + isfile as isfile, + samefile as samefile, + sameopenfile as sameopenfile, + samestat as samestat, +) from os import PathLike -from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload -_T = TypeVar("_T") +# Re-export common definitions from posixpath to reduce duplication +from posixpath import ( + abspath as abspath, + basename as basename, + commonpath as commonpath, + curdir as curdir, + defpath as defpath, + devnull as devnull, + dirname as dirname, + expanduser as expanduser, + expandvars as expandvars, + extsep as extsep, + isabs as isabs, + islink as islink, + ismount as ismount, + lexists as lexists, + normcase as normcase, + normpath as normpath, + pardir as pardir, + pathsep as pathsep, + relpath as relpath, + sep as sep, + split as split, + splitdrive as splitdrive, + splitext as splitext, + supports_unicode_filenames as supports_unicode_filenames, +) +from typing import AnyStr, Tuple, overload -# ----- os.path variables ----- -supports_unicode_filenames: bool -# aliases (also in os) -curdir: str -pardir: str -sep: str -if sys.platform == "win32": - altsep: str -else: - altsep: Optional[str] -extsep: str -pathsep: str -defpath: str -devnull: str +altsep: str +if sys.version_info < (3, 7) and sys.platform == "win32": + def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated -# ----- os.path function stubs ----- -# Overloads are necessary to work around python/mypy#3644. -@overload -def abspath(path: PathLike[AnyStr]) -> AnyStr: ... -@overload -def abspath(path: AnyStr) -> AnyStr: ... -@overload -def basename(p: PathLike[AnyStr]) -> AnyStr: ... -@overload -def basename(p: AnyStr) -> AnyStr: ... -@overload -def dirname(p: PathLike[AnyStr]) -> AnyStr: ... +# Similar to posixpath, but have slightly different argument names @overload -def dirname(p: AnyStr) -> AnyStr: ... -@overload -def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... -@overload -def expanduser(path: AnyStr) -> AnyStr: ... -@overload -def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... -@overload -def expandvars(path: AnyStr) -> AnyStr: ... -@overload -def normcase(s: PathLike[AnyStr]) -> AnyStr: ... -@overload -def normcase(s: AnyStr) -> AnyStr: ... -@overload -def normpath(path: PathLike[AnyStr]) -> AnyStr: ... +def join(path: StrPath, *paths: StrPath) -> str: ... @overload -def normpath(path: AnyStr) -> AnyStr: ... +def join(path: BytesPath, *paths: BytesPath) -> bytes: ... if sys.platform == "win32": - @overload - def realpath(path: PathLike[AnyStr]) -> AnyStr: ... - @overload - def realpath(path: AnyStr) -> AnyStr: ... + if sys.version_info >= (3, 10): + @overload + def realpath(path: PathLike[AnyStr], *, strict: bool = ...) -> AnyStr: ... + @overload + def realpath(path: AnyStr, *, strict: bool = ...) -> AnyStr: ... + else: + @overload + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... else: - @overload - def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... - @overload - def realpath(filename: AnyStr) -> AnyStr: ... - -# In reality it returns str for sequences of StrPath and bytes for sequences -# of BytesPath, but mypy does not accept such a signature. -def commonpath(paths: Sequence[AnyPath]) -> Any: ... - -# NOTE: Empty lists results in '' (str) regardless of contained type. -# So, fall back to Any -def commonprefix(m: Sequence[AnyPath]) -> Any: ... -def lexists(path: AnyPath) -> bool: ... - -# These return float if os.stat_float_times() == True, -# but int is a subclass of float. -def getatime(filename: AnyPath) -> float: ... -def getmtime(filename: AnyPath) -> float: ... -def getctime(filename: AnyPath) -> float: ... -def getsize(filename: AnyPath) -> int: ... -def isabs(s: AnyPath) -> bool: ... -def isfile(path: AnyPath) -> bool: ... -def isdir(s: AnyPath) -> bool: ... -def islink(path: AnyPath) -> bool: ... -def ismount(path: AnyPath) -> bool: ... -@overload -def join(path: StrPath, *paths: StrPath) -> str: ... -@overload -def join(path: BytesPath, *paths: BytesPath) -> bytes: ... -@overload -def relpath(path: BytesPath, start: Optional[BytesPath] = ...) -> bytes: ... -@overload -def relpath(path: StrPath, start: Optional[StrPath] = ...) -> str: ... -def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... -def sameopenfile(fp1: int, fp2: int) -> bool: ... -def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... -@overload -def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... -@overload -def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - -if sys.version_info < (3, 7) and sys.platform == "win32": - def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated + realpath = abspath diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index 98f078be869f..4500a748d574 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -39,13 +39,13 @@ from typing import ( ) from typing_extensions import Literal -from . import path as path +from . import path as _path if sys.version_info >= (3, 9): from types import GenericAlias -# We need to use something from path, or flake8 and pytype get unhappy -_supports_unicode_filenames = path.supports_unicode_filenames +# This unnecessary alias is to work around various errors +path = _path _T = TypeVar("_T") _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) @@ -117,6 +117,8 @@ if sys.platform != "win32": RTLD_LOCAL: int RTLD_NODELETE: int RTLD_NOLOAD: int + +if sys.platform == "linux": RTLD_DEEPBIND: int SEEK_SET: int @@ -388,9 +390,9 @@ if sys.platform != "win32": def getegid() -> int: ... def geteuid() -> int: ... def getgid() -> int: ... - def getgrouplist(user: str, gid: int) -> List[int]: ... + def getgrouplist(__user: str, __group: int) -> List[int]: ... def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac - def initgroups(username: str, gid: int) -> None: ... + def initgroups(__username: str, __gid: int) -> None: ... def getpgid(pid: int) -> int: ... def getpgrp() -> int: ... def getpriority(which: int, who: int) -> int: ... @@ -550,11 +552,11 @@ if sys.platform != "win32": def pread(__fd: int, __length: int, __offset: int) -> bytes: ... def pwrite(__fd: int, __buffer: bytes, __offset: int) -> int: ... @overload - def sendfile(__out_fd: int, __in_fd: int, offset: Optional[int], count: int) -> int: ... + def sendfile(out_fd: int, in_fd: int, offset: Optional[int], count: int) -> int: ... @overload def sendfile( - __out_fd: int, - __in_fd: int, + out_fd: int, + in_fd: int, offset: int, count: int, headers: Sequence[bytes] = ..., @@ -712,7 +714,7 @@ if sys.platform != "win32": ) -> Iterator[Tuple[str, List[str], List[str], int]]: ... if sys.platform == "linux": def getxattr(path: _FdOrAnyPath, attribute: AnyPath, *, follow_symlinks: bool = ...) -> bytes: ... - def listxattr(path: _FdOrAnyPath, *, follow_symlinks: bool = ...) -> List[str]: ... + def listxattr(path: Optional[_FdOrAnyPath] = ..., *, follow_symlinks: bool = ...) -> List[str]: ... def removexattr(path: _FdOrAnyPath, attribute: AnyPath, *, follow_symlinks: bool = ...) -> None: ... def setxattr( path: _FdOrAnyPath, attribute: AnyPath, value: bytes, flags: int = ..., *, follow_symlinks: bool = ... @@ -791,8 +793,9 @@ else: def spawnvp(mode: int, file: AnyPath, args: _ExecVArgs) -> int: ... def spawnvpe(mode: int, file: AnyPath, args: _ExecVArgs, env: _ExecEnv) -> int: ... def wait() -> Tuple[int, int]: ... # Unix only - from posix import waitid_result - def waitid(idtype: int, ident: int, options: int) -> waitid_result: ... + if sys.platform != "darwin": + from posix import waitid_result + def waitid(idtype: int, ident: int, options: int) -> waitid_result: ... def wait3(options: int) -> Tuple[int, int, Any]: ... def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ... def WCOREDUMP(__status: int) -> bool: ... @@ -808,14 +811,15 @@ if sys.platform != "win32": from posix import sched_param def sched_get_priority_min(policy: int) -> int: ... # some flavors of Unix def sched_get_priority_max(policy: int) -> int: ... # some flavors of Unix - def sched_setscheduler(pid: int, policy: int, param: sched_param) -> None: ... # some flavors of Unix - def sched_getscheduler(pid: int) -> int: ... # some flavors of Unix - def sched_setparam(pid: int, param: sched_param) -> None: ... # some flavors of Unix - def sched_getparam(pid: int) -> sched_param: ... # some flavors of Unix - def sched_rr_get_interval(pid: int) -> float: ... # some flavors of Unix def sched_yield() -> None: ... # some flavors of Unix - def sched_setaffinity(pid: int, mask: Iterable[int]) -> None: ... # some flavors of Unix - def sched_getaffinity(pid: int) -> Set[int]: ... # some flavors of Unix + if sys.platform != "darwin": + def sched_setscheduler(pid: int, policy: int, param: sched_param) -> None: ... # some flavors of Unix + def sched_getscheduler(pid: int) -> int: ... # some flavors of Unix + def sched_rr_get_interval(pid: int) -> float: ... # some flavors of Unix + def sched_setparam(pid: int, param: sched_param) -> None: ... # some flavors of Unix + def sched_getparam(pid: int) -> sched_param: ... # some flavors of Unix + def sched_setaffinity(pid: int, mask: Iterable[int]) -> None: ... # some flavors of Unix + def sched_getaffinity(pid: int) -> Set[int]: ... # some flavors of Unix def cpu_count() -> Optional[int]: ... diff --git a/mypy/typeshed/stdlib/os/path.pyi b/mypy/typeshed/stdlib/os/path.pyi index a8b30eb71b6c..4533738983f7 100644 --- a/mypy/typeshed/stdlib/os/path.pyi +++ b/mypy/typeshed/stdlib/os/path.pyi @@ -1,125 +1,6 @@ -import os import sys -from _typeshed import AnyPath, BytesPath, StrPath -from genericpath import exists as exists -from os import PathLike -from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload - -_T = TypeVar("_T") - -# ----- os.path variables ----- -supports_unicode_filenames: bool -# aliases (also in os) -curdir: str -pardir: str -sep: str -if sys.platform == "win32": - altsep: str -else: - altsep: Optional[str] -extsep: str -pathsep: str -defpath: str -devnull: str - -# ----- os.path function stubs ----- -# Overloads are necessary to work around python/mypy#3644. -@overload -def abspath(path: PathLike[AnyStr]) -> AnyStr: ... -@overload -def abspath(path: AnyStr) -> AnyStr: ... -@overload -def basename(p: PathLike[AnyStr]) -> AnyStr: ... -@overload -def basename(p: AnyStr) -> AnyStr: ... -@overload -def dirname(p: PathLike[AnyStr]) -> AnyStr: ... -@overload -def dirname(p: AnyStr) -> AnyStr: ... -@overload -def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... -@overload -def expanduser(path: AnyStr) -> AnyStr: ... -@overload -def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... -@overload -def expandvars(path: AnyStr) -> AnyStr: ... -@overload -def normcase(s: PathLike[AnyStr]) -> AnyStr: ... -@overload -def normcase(s: AnyStr) -> AnyStr: ... -@overload -def normpath(path: PathLike[AnyStr]) -> AnyStr: ... -@overload -def normpath(path: AnyStr) -> AnyStr: ... if sys.platform == "win32": - if sys.version_info >= (3, 10): - @overload - def realpath(path: PathLike[AnyStr], *, strict: bool = ...) -> AnyStr: ... - @overload - def realpath(path: AnyStr, *, strict: bool = ...) -> AnyStr: ... - else: - @overload - def realpath(path: PathLike[AnyStr]) -> AnyStr: ... - @overload - def realpath(path: AnyStr) -> AnyStr: ... - + from ntpath import * else: - if sys.version_info >= (3, 10): - @overload - def realpath(filename: PathLike[AnyStr], *, strict: bool = ...) -> AnyStr: ... - @overload - def realpath(filename: AnyStr, *, strict: bool = ...) -> AnyStr: ... - else: - @overload - def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... - @overload - def realpath(filename: AnyStr) -> AnyStr: ... - -# In reality it returns str for sequences of StrPath and bytes for sequences -# of BytesPath, but mypy does not accept such a signature. -def commonpath(paths: Sequence[AnyPath]) -> Any: ... - -# NOTE: Empty lists results in '' (str) regardless of contained type. -# So, fall back to Any -def commonprefix(m: Sequence[AnyPath]) -> Any: ... -def lexists(path: AnyPath) -> bool: ... - -# These return float if os.stat_float_times() == True, -# but int is a subclass of float. -def getatime(filename: AnyPath) -> float: ... -def getmtime(filename: AnyPath) -> float: ... -def getctime(filename: AnyPath) -> float: ... -def getsize(filename: AnyPath) -> int: ... -def isabs(s: AnyPath) -> bool: ... -def isfile(path: AnyPath) -> bool: ... -def isdir(s: AnyPath) -> bool: ... -def islink(path: AnyPath) -> bool: ... -def ismount(path: AnyPath) -> bool: ... -@overload -def join(a: StrPath, *paths: StrPath) -> str: ... -@overload -def join(a: BytesPath, *paths: BytesPath) -> bytes: ... -@overload -def relpath(path: BytesPath, start: Optional[BytesPath] = ...) -> bytes: ... -@overload -def relpath(path: StrPath, start: Optional[StrPath] = ...) -> str: ... -def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... -def sameopenfile(fp1: int, fp2: int) -> bool: ... -def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... -@overload -def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... -@overload -def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... -@overload -def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - -if sys.version_info < (3, 7) and sys.platform == "win32": - def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated + from posixpath import * diff --git a/mypy/typeshed/stdlib/parser.pyi b/mypy/typeshed/stdlib/parser.pyi index 36fe6cafc0aa..799f25cf6a48 100644 --- a/mypy/typeshed/stdlib/parser.pyi +++ b/mypy/typeshed/stdlib/parser.pyi @@ -1,22 +1,22 @@ -import sys from _typeshed import AnyPath from types import CodeType from typing import Any, List, Sequence, Text, Tuple -if sys.version_info < (3, 10): - def expr(source: Text) -> STType: ... - def suite(source: Text) -> STType: ... - def sequence2st(sequence: Sequence[Any]) -> STType: ... - def tuple2st(sequence: Sequence[Any]) -> STType: ... - def st2list(st: STType, line_info: bool = ..., col_info: bool = ...) -> List[Any]: ... - def st2tuple(st: STType, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any]: ... - def compilest(st: STType, filename: AnyPath = ...) -> CodeType: ... - def isexpr(st: STType) -> bool: ... - def issuite(st: STType) -> bool: ... - class ParserError(Exception): ... - class STType: - def compile(self, filename: AnyPath = ...) -> CodeType: ... - def isexpr(self) -> bool: ... - def issuite(self) -> bool: ... - def tolist(self, line_info: bool = ..., col_info: bool = ...) -> List[Any]: ... - def totuple(self, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any]: ... +def expr(source: Text) -> STType: ... +def suite(source: Text) -> STType: ... +def sequence2st(sequence: Sequence[Any]) -> STType: ... +def tuple2st(sequence: Sequence[Any]) -> STType: ... +def st2list(st: STType, line_info: bool = ..., col_info: bool = ...) -> List[Any]: ... +def st2tuple(st: STType, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any]: ... +def compilest(st: STType, filename: AnyPath = ...) -> CodeType: ... +def isexpr(st: STType) -> bool: ... +def issuite(st: STType) -> bool: ... + +class ParserError(Exception): ... + +class STType: + def compile(self, filename: AnyPath = ...) -> CodeType: ... + def isexpr(self) -> bool: ... + def issuite(self) -> bool: ... + def tolist(self, line_info: bool = ..., col_info: bool = ...) -> List[Any]: ... + def totuple(self, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any]: ... diff --git a/mypy/typeshed/stdlib/posix.pyi b/mypy/typeshed/stdlib/posix.pyi index 5d0f69fa4394..2499463647cd 100644 --- a/mypy/typeshed/stdlib/posix.pyi +++ b/mypy/typeshed/stdlib/posix.pyi @@ -16,12 +16,13 @@ class times_result(NamedTuple): children_system: float elapsed: float -class waitid_result(NamedTuple): - si_pid: int - si_uid: int - si_signo: int - si_status: int - si_code: int +if sys.platform != "darwin": + class waitid_result(NamedTuple): + si_pid: int + si_uid: int + si_signo: int + si_status: int + si_code: int class sched_param(NamedTuple): sched_priority: int @@ -59,8 +60,9 @@ F_TEST: int F_TLOCK: int F_ULOCK: int -GRND_NONBLOCK: int -GRND_RANDOM: int +if sys.platform == "linux": + GRND_NONBLOCK: int + GRND_RANDOM: int NGROUPS_MAX: int O_APPEND: int @@ -84,12 +86,13 @@ O_SYNC: int O_TRUNC: int O_WRONLY: int -POSIX_FADV_DONTNEED: int -POSIX_FADV_NOREUSE: int -POSIX_FADV_NORMAL: int -POSIX_FADV_RANDOM: int -POSIX_FADV_SEQUENTIAL: int -POSIX_FADV_WILLNEED: int +if sys.platform != "darwin": + POSIX_FADV_DONTNEED: int + POSIX_FADV_NOREUSE: int + POSIX_FADV_NORMAL: int + POSIX_FADV_RANDOM: int + POSIX_FADV_SEQUENTIAL: int + POSIX_FADV_WILLNEED: int PRIO_PGRP: int PRIO_PROCESS: int @@ -99,7 +102,8 @@ P_ALL: int P_PGID: int P_PID: int -RTLD_DEEPBIND: int +if sys.platform == "linux": + RTLD_DEEPBIND: int RTLD_GLOBAL: int RTLD_LAZY: int RTLD_LOCAL: int @@ -107,13 +111,16 @@ RTLD_NODELETE: int RTLD_NOLOAD: int RTLD_NOW: int -SCHED_BATCH: int SCHED_FIFO: int -SCHED_IDLE: int SCHED_OTHER: int -SCHED_RESET_ON_FORK: int SCHED_RR: int +if sys.platform == "linux": + SCHED_BATCH: int + SCHED_IDLE: int +if sys.platform != "darwin": + SCHED_RESET_ON_FORK: int + SEEK_DATA: int SEEK_HOLE: int diff --git a/mypy/typeshed/stdlib/posixpath.pyi b/mypy/typeshed/stdlib/posixpath.pyi index 2fcbe12f8a08..98176eaa03ec 100644 --- a/mypy/typeshed/stdlib/posixpath.pyi +++ b/mypy/typeshed/stdlib/posixpath.pyi @@ -1,28 +1,32 @@ -import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from genericpath import exists as exists +from genericpath import ( + commonprefix as commonprefix, + exists as exists, + getatime as getatime, + getctime as getctime, + getmtime as getmtime, + getsize as getsize, + isdir as isdir, + isfile as isfile, + samefile as samefile, + sameopenfile as sameopenfile, + samestat as samestat, +) from os import PathLike -from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload +from typing import AnyStr, Optional, Sequence, Tuple, overload -_T = TypeVar("_T") - -# ----- os.path variables ----- supports_unicode_filenames: bool # aliases (also in os) curdir: str pardir: str sep: str -if sys.platform == "win32": - altsep: str -else: - altsep: Optional[str] +altsep: Optional[str] extsep: str pathsep: str defpath: str devnull: str -# ----- os.path function stubs ----- # Overloads are necessary to work around python/mypy#3644. @overload def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @@ -52,12 +56,20 @@ def normcase(s: AnyStr) -> AnyStr: ... def normpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(path: AnyStr) -> AnyStr: ... +@overload +def commonpath(paths: Sequence[StrPath]) -> str: ... +@overload +def commonpath(paths: Sequence[BytesPath]) -> bytes: ... +@overload +def join(a: StrPath, *paths: StrPath) -> str: ... +@overload +def join(a: BytesPath, *paths: BytesPath) -> bytes: ... -if sys.platform == "win32": +if sys.version_info >= (3, 10): @overload - def realpath(path: PathLike[AnyStr]) -> AnyStr: ... + def realpath(filename: PathLike[AnyStr], *, strict: bool = ...) -> AnyStr: ... @overload - def realpath(path: AnyStr) -> AnyStr: ... + def realpath(filename: AnyStr, *, strict: bool = ...) -> AnyStr: ... else: @overload @@ -65,37 +77,10 @@ else: @overload def realpath(filename: AnyStr) -> AnyStr: ... -# In reality it returns str for sequences of StrPath and bytes for sequences -# of BytesPath, but mypy does not accept such a signature. -def commonpath(paths: Sequence[AnyPath]) -> Any: ... - -# NOTE: Empty lists results in '' (str) regardless of contained type. -# So, fall back to Any -def commonprefix(m: Sequence[AnyPath]) -> Any: ... -def lexists(path: AnyPath) -> bool: ... - -# These return float if os.stat_float_times() == True, -# but int is a subclass of float. -def getatime(filename: AnyPath) -> float: ... -def getmtime(filename: AnyPath) -> float: ... -def getctime(filename: AnyPath) -> float: ... -def getsize(filename: AnyPath) -> int: ... -def isabs(s: AnyPath) -> bool: ... -def isfile(path: AnyPath) -> bool: ... -def isdir(s: AnyPath) -> bool: ... -def islink(path: AnyPath) -> bool: ... -def ismount(path: AnyPath) -> bool: ... -@overload -def join(a: StrPath, *paths: StrPath) -> str: ... -@overload -def join(a: BytesPath, *paths: BytesPath) -> bytes: ... @overload def relpath(path: BytesPath, start: Optional[BytesPath] = ...) -> bytes: ... @overload def relpath(path: StrPath, start: Optional[StrPath] = ...) -> str: ... -def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... -def sameopenfile(fp1: int, fp2: int) -> bool: ... -def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... @overload def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload @@ -108,6 +93,7 @@ def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... - -if sys.version_info < (3, 7) and sys.platform == "win32": - def splitunc(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated +def isabs(s: AnyPath) -> bool: ... +def islink(path: AnyPath) -> bool: ... +def ismount(path: AnyPath) -> bool: ... +def lexists(path: AnyPath) -> bool: ... diff --git a/mypy/typeshed/stdlib/pwd.pyi b/mypy/typeshed/stdlib/pwd.pyi index ea5845200613..83020c1576dd 100644 --- a/mypy/typeshed/stdlib/pwd.pyi +++ b/mypy/typeshed/stdlib/pwd.pyi @@ -10,5 +10,5 @@ class struct_passwd(Tuple[str, str, int, int, str, str, str]): pw_shell: str def getpwall() -> List[struct_passwd]: ... -def getpwuid(uid: int) -> struct_passwd: ... -def getpwnam(name: str) -> struct_passwd: ... +def getpwuid(__uid: int) -> struct_passwd: ... +def getpwnam(__name: str) -> struct_passwd: ... diff --git a/mypy/typeshed/stdlib/py_compile.pyi b/mypy/typeshed/stdlib/py_compile.pyi index 7f6815b33197..49473b17708e 100644 --- a/mypy/typeshed/stdlib/py_compile.pyi +++ b/mypy/typeshed/stdlib/py_compile.pyi @@ -1,4 +1,3 @@ -import enum import sys from typing import AnyStr, List, Optional, Text, Type, Union @@ -12,6 +11,7 @@ class PyCompileError(Exception): def __init__(self, exc_type: Type[BaseException], exc_value: BaseException, file: str, msg: str = ...) -> None: ... if sys.version_info >= (3, 7): + import enum class PycInvalidationMode(enum.Enum): TIMESTAMP: int = ... CHECKED_HASH: int = ... diff --git a/mypy/typeshed/stdlib/selectors.pyi b/mypy/typeshed/stdlib/selectors.pyi index b019c4f9c442..94690efadbf8 100644 --- a/mypy/typeshed/stdlib/selectors.pyi +++ b/mypy/typeshed/stdlib/selectors.pyi @@ -41,6 +41,8 @@ if sys.platform != "win32": def unregister(self, fileobj: FileDescriptorLike) -> SelectorKey: ... def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ... + +if sys.platform == "linux": class EpollSelector(BaseSelector): def fileno(self) -> int: ... def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = ...) -> SelectorKey: ... diff --git a/mypy/typeshed/stdlib/signal.pyi b/mypy/typeshed/stdlib/signal.pyi index 53d8caaca471..aa0bbf2bffd1 100644 --- a/mypy/typeshed/stdlib/signal.pyi +++ b/mypy/typeshed/stdlib/signal.pyi @@ -137,7 +137,7 @@ if sys.platform == "win32": CTRL_C_EVENT: int CTRL_BREAK_EVENT: int -if sys.platform != "win32": +if sys.platform != "win32" and sys.platform != "darwin": class struct_siginfo(Tuple[int, int, int, int, int, int, int]): def __init__(self, sequence: Iterable[int]) -> None: ... @property @@ -189,6 +189,7 @@ def signal(__signalnum: _SIGNUM, __handler: _HANDLER) -> _HANDLER: ... if sys.platform != "win32": def sigpending() -> Any: ... - def sigtimedwait(sigset: Iterable[int], timeout: float) -> Optional[struct_siginfo]: ... def sigwait(__sigset: Iterable[int]) -> _SIGNUM: ... - def sigwaitinfo(sigset: Iterable[int]) -> struct_siginfo: ... + if sys.platform != "darwin": + def sigtimedwait(sigset: Iterable[int], timeout: float) -> Optional[struct_siginfo]: ... + def sigwaitinfo(sigset: Iterable[int]) -> struct_siginfo: ... diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi index 1d315fc1267d..e3f5d9b35bef 100644 --- a/mypy/typeshed/stdlib/socket.pyi +++ b/mypy/typeshed/stdlib/socket.pyi @@ -768,7 +768,13 @@ def getnameinfo(sockaddr: Union[Tuple[str, int], Tuple[str, int, int, int]], fla def getprotobyname(protocolname: str) -> int: ... def getservbyname(servicename: str, protocolname: str = ...) -> int: ... def getservbyport(port: int, protocolname: str = ...) -> str: ... -def socketpair(family: int = ..., type: int = ..., proto: int = ...) -> Tuple[socket, socket]: ... + +if sys.platform == "win32": + def socketpair(family: int = ..., type: int = ..., proto: int = ...) -> Tuple[socket, socket]: ... + +else: + def socketpair(family: Optional[int] = ..., type: int = ..., proto: int = ...) -> Tuple[socket, socket]: ... + def ntohl(x: int) -> int: ... # param & ret val are 32-bit ints def ntohs(x: int) -> int: ... # param & ret val are 16-bit ints def htonl(x: int) -> int: ... # param & ret val are 32-bit ints diff --git a/mypy/typeshed/stdlib/spwd.pyi b/mypy/typeshed/stdlib/spwd.pyi index 1fb972f6d990..8a6656194614 100644 --- a/mypy/typeshed/stdlib/spwd.pyi +++ b/mypy/typeshed/stdlib/spwd.pyi @@ -12,4 +12,4 @@ class struct_spwd(NamedTuple): sp_flag: int def getspall() -> List[struct_spwd]: ... -def getspnam(name: str) -> struct_spwd: ... +def getspnam(__arg: str) -> struct_spwd: ... diff --git a/mypy/typeshed/stdlib/ssl.pyi b/mypy/typeshed/stdlib/ssl.pyi index 160501d1e1e7..838211d959e5 100644 --- a/mypy/typeshed/stdlib/ssl.pyi +++ b/mypy/typeshed/stdlib/ssl.pyi @@ -1,10 +1,12 @@ -import enum import socket import sys from _typeshed import StrPath from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Optional, Set, Text, Tuple, Type, Union, overload from typing_extensions import Literal +if sys.version_info >= (3, 4): + import enum + _PCTRTT = Tuple[Tuple[str, str], ...] _PCTRTTT = Tuple[_PCTRTT, ...] _PeerCertRetDictType = Dict[str, Union[str, _PCTRTTT, _PCTRTT]] @@ -228,7 +230,7 @@ class _ASN1Object(NamedTuple): longname: str oid: str -if sys.version_info >= (3, 0): +if sys.version_info >= (3, 4): class Purpose(_ASN1Object, enum.Enum): SERVER_AUTH: _ASN1Object CLIENT_AUTH: _ASN1Object diff --git a/mypy/typeshed/stdlib/statistics.pyi b/mypy/typeshed/stdlib/statistics.pyi index d842965247f5..4435bf8a001b 100644 --- a/mypy/typeshed/stdlib/statistics.pyi +++ b/mypy/typeshed/stdlib/statistics.pyi @@ -2,10 +2,11 @@ import sys from _typeshed import SupportsLessThanT from decimal import Decimal from fractions import Fraction -from typing import Any, Hashable, Iterable, List, Optional, SupportsFloat, Type, TypeVar, Union +from typing import Any, Hashable, Iterable, List, NamedTuple, Optional, Sequence, SupportsFloat, Type, TypeVar, Union _T = TypeVar("_T") # Most functions in this module accept homogeneous collections of one of these types +_Number = Union[float, Decimal, Fraction] _NumberT = TypeVar("_NumberT", float, Decimal, Fraction) # Used in mode, multimode @@ -18,7 +19,13 @@ if sys.version_info >= (3, 8): def geometric_mean(data: Iterable[SupportsFloat]) -> float: ... def mean(data: Iterable[_NumberT]) -> _NumberT: ... -def harmonic_mean(data: Iterable[_NumberT]) -> _NumberT: ... + +if sys.version_info >= (3, 10): + def harmonic_mean(data: Iterable[_NumberT], weights: Optional[Iterable[_Number]] = ...) -> _NumberT: ... + +else: + def harmonic_mean(data: Iterable[_NumberT]) -> _NumberT: ... + def median(data: Iterable[_NumberT]) -> _NumberT: ... def median_low(data: Iterable[SupportsLessThanT]) -> SupportsLessThanT: ... def median_high(data: Iterable[SupportsLessThanT]) -> SupportsLessThanT: ... @@ -70,3 +77,11 @@ if sys.version_info >= (3, 8): def __rsub__(self, x2: Union[float, NormalDist]) -> NormalDist: ... __rmul__ = __mul__ def __hash__(self) -> int: ... + +if sys.version_info >= (3, 10): + def correlation(__x: Sequence[_Number], __y: Sequence[_Number]) -> float: ... + def covariance(__x: Sequence[_Number], __y: Sequence[_Number]) -> float: ... + class LinearRegression(NamedTuple): + intercept: float + slope: float + def linear_regression(__regressor: Sequence[_Number], __dependent_variable: Sequence[_Number]) -> LinearRegression: ... diff --git a/mypy/typeshed/stdlib/symbol.pyi b/mypy/typeshed/stdlib/symbol.pyi index 036d3191452d..6fbe306fabe9 100644 --- a/mypy/typeshed/stdlib/symbol.pyi +++ b/mypy/typeshed/stdlib/symbol.pyi @@ -1,92 +1,90 @@ -import sys from typing import Dict -if sys.version_info < (3, 10): - single_input: int - file_input: int - eval_input: int - decorator: int - decorators: int - decorated: int - async_funcdef: int - funcdef: int - parameters: int - typedargslist: int - tfpdef: int - varargslist: int - vfpdef: int - stmt: int - simple_stmt: int - small_stmt: int - expr_stmt: int - annassign: int - testlist_star_expr: int - augassign: int - del_stmt: int - pass_stmt: int - flow_stmt: int - break_stmt: int - continue_stmt: int - return_stmt: int - yield_stmt: int - raise_stmt: int - import_stmt: int - import_name: int - import_from: int - import_as_name: int - dotted_as_name: int - import_as_names: int - dotted_as_names: int - dotted_name: int - global_stmt: int - nonlocal_stmt: int - assert_stmt: int - compound_stmt: int - async_stmt: int - if_stmt: int - while_stmt: int - for_stmt: int - try_stmt: int - with_stmt: int - with_item: int - except_clause: int - suite: int - test: int - test_nocond: int - lambdef: int - lambdef_nocond: int - or_test: int - and_test: int - not_test: int - comparison: int - comp_op: int - star_expr: int - expr: int - xor_expr: int - and_expr: int - shift_expr: int - arith_expr: int - term: int - factor: int - power: int - atom_expr: int - atom: int - testlist_comp: int - trailer: int - subscriptlist: int - subscript: int - sliceop: int - exprlist: int - testlist: int - dictorsetmaker: int - classdef: int - arglist: int - argument: int - comp_iter: int - comp_for: int - comp_if: int - encoding_decl: int - yield_expr: int - yield_arg: int +single_input: int +file_input: int +eval_input: int +decorator: int +decorators: int +decorated: int +async_funcdef: int +funcdef: int +parameters: int +typedargslist: int +tfpdef: int +varargslist: int +vfpdef: int +stmt: int +simple_stmt: int +small_stmt: int +expr_stmt: int +annassign: int +testlist_star_expr: int +augassign: int +del_stmt: int +pass_stmt: int +flow_stmt: int +break_stmt: int +continue_stmt: int +return_stmt: int +yield_stmt: int +raise_stmt: int +import_stmt: int +import_name: int +import_from: int +import_as_name: int +dotted_as_name: int +import_as_names: int +dotted_as_names: int +dotted_name: int +global_stmt: int +nonlocal_stmt: int +assert_stmt: int +compound_stmt: int +async_stmt: int +if_stmt: int +while_stmt: int +for_stmt: int +try_stmt: int +with_stmt: int +with_item: int +except_clause: int +suite: int +test: int +test_nocond: int +lambdef: int +lambdef_nocond: int +or_test: int +and_test: int +not_test: int +comparison: int +comp_op: int +star_expr: int +expr: int +xor_expr: int +and_expr: int +shift_expr: int +arith_expr: int +term: int +factor: int +power: int +atom_expr: int +atom: int +testlist_comp: int +trailer: int +subscriptlist: int +subscript: int +sliceop: int +exprlist: int +testlist: int +dictorsetmaker: int +classdef: int +arglist: int +argument: int +comp_iter: int +comp_for: int +comp_if: int +encoding_decl: int +yield_expr: int +yield_arg: int - sym_name: Dict[int, str] +sym_name: Dict[int, str] diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi index e3315733510e..6e926c68dc39 100644 --- a/mypy/typeshed/stdlib/time.pyi +++ b/mypy/typeshed/stdlib/time.pyi @@ -13,22 +13,28 @@ daylight: int timezone: int tzname: Tuple[str, str] -if sys.version_info >= (3, 7) and sys.platform != "win32": - CLOCK_BOOTTIME: int # Linux - CLOCK_PROF: int # FreeBSD, NetBSD, OpenBSD - CLOCK_UPTIME: int # FreeBSD, OpenBSD +if sys.version_info >= (3, 7): + if sys.platform == "linux": + CLOCK_BOOTTIME: int + if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin": + CLOCK_PROF: int # FreeBSD, NetBSD, OpenBSD + CLOCK_UPTIME: int # FreeBSD, OpenBSD if sys.version_info >= (3, 3) and sys.platform != "win32": - CLOCK_HIGHRES: int # Solaris only - CLOCK_MONOTONIC: int # Unix only - CLOCK_MONOTONIC_RAW: int # Linux 2.6.28 or later - CLOCK_PROCESS_CPUTIME_ID: int # Unix only - CLOCK_REALTIME: int # Unix only - CLOCK_THREAD_CPUTIME_ID: int # Unix only + CLOCK_MONOTONIC: int + CLOCK_MONOTONIC_RAW: int + CLOCK_PROCESS_CPUTIME_ID: int + CLOCK_REALTIME: int + CLOCK_THREAD_CPUTIME_ID: int + if sys.platform != "linux" and sys.platform != "darwin": + CLOCK_HIGHRES: int # Solaris only if sys.version_info >= (3, 8) and sys.platform == "darwin": CLOCK_UPTIME_RAW: int +if sys.version_info >= (3, 9) and sys.platform == "linux": + CLOCK_TAI: int + class _struct_time(NamedTuple): tm_year: int tm_mon: int diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 03336ac6ec60..aafb1fbdf1b3 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -12,7 +12,6 @@ if sys.version_info >= (3, 9): # Definitions of special type checking related constructs. Their definitions # are not used, so their value does not matter. -overload = object() Any = object() class TypeVar: @@ -35,6 +34,10 @@ _promote = object() class _SpecialForm: def __getitem__(self, typeargs: Any) -> object: ... +_F = TypeVar("_F", bound=Callable[..., Any]) + +def overload(func: _F) -> _F: ... + Union: _SpecialForm = ... Optional: _SpecialForm = ... Tuple: _SpecialForm = ... @@ -46,7 +49,6 @@ Type: _SpecialForm = ... ClassVar: _SpecialForm = ... if sys.version_info >= (3, 8): Final: _SpecialForm = ... - _F = TypeVar("_F", bound=Callable[..., Any]) def final(f: _F) -> _F: ... Literal: _SpecialForm = ... # TypedDict is a (non-subscriptable) special form. @@ -94,11 +96,9 @@ _KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers. _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers. _T_contra = TypeVar("_T_contra", contravariant=True) # Ditto contravariant. _TC = TypeVar("_TC", bound=Type[object]) -_C = TypeVar("_C", bound=Callable[..., Any]) - -no_type_check = object() -def no_type_check_decorator(decorator: _C) -> _C: ... +def no_type_check(arg: _F) -> _F: ... +def no_type_check_decorator(decorator: _F) -> _F: ... # Type aliases and type constructors @@ -681,7 +681,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... # This itself is only available during type checking -def type_check_only(func_or_cls: _C) -> _C: ... +def type_check_only(func_or_cls: _F) -> _F: ... if sys.version_info >= (3, 7): from types import CodeType diff --git a/mypy/typeshed/stdlib/typing_extensions.pyi b/mypy/typeshed/stdlib/typing_extensions.pyi index 90bb75765bee..0250866f3eb8 100644 --- a/mypy/typeshed/stdlib/typing_extensions.pyi +++ b/mypy/typeshed/stdlib/typing_extensions.pyi @@ -22,6 +22,7 @@ from typing import ( TypeVar, Union, ValuesView, + _Alias, overload as overload, ) @@ -43,7 +44,7 @@ def final(f: _F) -> _F: ... Literal: _SpecialForm = ... -def IntVar(__name: str) -> Any: ... # returns a new TypeVar +def IntVar(name: str) -> Any: ... # returns a new TypeVar # Internal mypy fallback type for all typed dicts (does not exist at runtime) class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): @@ -68,6 +69,8 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): # TypedDict is a (non-subscriptable) special form. TypedDict: object = ... +OrderedDict = _Alias() + if sys.version_info >= (3, 3): from typing import ChainMap as ChainMap diff --git a/mypy/typeshed/stdlib/urllib/request.pyi b/mypy/typeshed/stdlib/urllib/request.pyi index bed840c00663..3f09496a6dcf 100644 --- a/mypy/typeshed/stdlib/urllib/request.pyi +++ b/mypy/typeshed/stdlib/urllib/request.pyi @@ -1,5 +1,6 @@ import os import ssl +import sys from email.message import Message from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar @@ -21,7 +22,7 @@ from typing import ( overload, ) from urllib.error import HTTPError -from urllib.response import addinfourl +from urllib.response import addclosehook, addinfourl _T = TypeVar("_T") _UrlopenRet = Any @@ -38,12 +39,22 @@ def urlopen( ) -> _UrlopenRet: ... def install_opener(opener: OpenerDirector) -> None: ... def build_opener(*handlers: Union[BaseHandler, Callable[[], BaseHandler]]) -> OpenerDirector: ... -def url2pathname(pathname: str) -> str: ... -def pathname2url(pathname: str) -> str: ... + +if sys.platform == "win32": + from nturl2path import pathname2url as pathname2url, url2pathname as url2pathname +else: + def url2pathname(pathname: str) -> str: ... + def pathname2url(pathname: str) -> str: ... + def getproxies() -> Dict[str, str]: ... def parse_http_list(s: str) -> List[str]: ... def parse_keqv_list(l: List[str]) -> Dict[str, str]: ... -def proxy_bypass(host: str) -> Any: ... # Undocumented + +if sys.platform == "win32" or sys.platform == "darwin": + def proxy_bypass(host: str) -> Any: ... # Undocumented + +else: + def proxy_bypass(host: str, proxies: Optional[Mapping[str, str]] = ...) -> Any: ... # Undocumented class Request: @property @@ -97,7 +108,6 @@ class BaseHandler: parent: OpenerDirector def add_parent(self, parent: OpenerDirector) -> None: ... def close(self) -> None: ... - def http_error_nnn(self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]) -> _UrlopenRet: ... class HTTPDefaultErrorHandler(BaseHandler): def http_error_default( @@ -156,6 +166,8 @@ class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): class AbstractBasicAuthHandler: rx: ClassVar[Pattern[str]] # undocumented + passwd: HTTPPasswordMgr + add_password: Callable[[str, Union[str, Sequence[str]], str, str], None] def __init__(self, password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ... def http_error_auth_reqed(self, authreq: str, host: str, req: Request, headers: Mapping[str, str]) -> None: ... def http_request(self, req: Request) -> Request: ... # undocumented @@ -228,6 +240,12 @@ class ftpwrapper: # undocumented def __init__( self, user: str, passwd: str, host: str, port: int, dirs: str, timeout: Optional[float] = ..., persistent: bool = ... ) -> None: ... + def close(self) -> None: ... + def endtransfer(self) -> None: ... + def file_close(self) -> None: ... + def init(self) -> None: ... + def real_close(self) -> None: ... + def retrfile(self, file: str, type: str) -> Tuple[addclosehook, int]: ... class FTPHandler(BaseHandler): def ftp_open(self, req: Request) -> addinfourl: ... diff --git a/mypy/typeshed/stdlib/urllib/robotparser.pyi b/mypy/typeshed/stdlib/urllib/robotparser.pyi index ad96ca12bfc4..382dcee0e859 100644 --- a/mypy/typeshed/stdlib/urllib/robotparser.pyi +++ b/mypy/typeshed/stdlib/urllib/robotparser.pyi @@ -10,7 +10,7 @@ class RobotFileParser: def set_url(self, url: str) -> None: ... def read(self) -> None: ... def parse(self, lines: Iterable[str]) -> None: ... - def can_fetch(self, user_agent: str, url: str) -> bool: ... + def can_fetch(self, useragent: str, url: str) -> bool: ... def mtime(self) -> int: ... def modified(self) -> None: ... def crawl_delay(self, useragent: str) -> Optional[str]: ... diff --git a/mypy/typeshed/stdlib/webbrowser.pyi b/mypy/typeshed/stdlib/webbrowser.pyi index 00e3f9f2624c..322ec2764e39 100644 --- a/mypy/typeshed/stdlib/webbrowser.pyi +++ b/mypy/typeshed/stdlib/webbrowser.pyi @@ -48,7 +48,6 @@ class UnixBrowser(BaseBrowser): def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... class Mozilla(UnixBrowser): - raise_opts: List[str] remote_args: List[str] remote_action: str remote_action_newwin: str