Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions scripts/create_baseline_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
import subprocess
import sys
import urllib.parse
from importlib.metadata import distribution

import aiohttp
import termcolor

if sys.version_info >= (3, 8):
from importlib.metadata import distribution

PYRIGHT_CONFIG = "pyrightconfig.stricter.json"


Expand Down Expand Up @@ -204,12 +202,11 @@ def main() -> None:
#
# The importlib.metadata module is used for projects whose name is different
# from the runtime Python package name (example: PyYAML/yaml)
if sys.version_info >= (3, 8):
dist = distribution(project).read_text("top_level.txt")
if dist is not None:
packages = [name for name in dist.split() if not name.startswith("_")]
if len(packages) == 1:
package = packages[0]
dist = distribution(project).read_text("top_level.txt")
if dist is not None:
packages = [name for name in dist.split() if not name.startswith("_")]
if len(packages) == 1:
package = packages[0]
print(f'Using detected package "{package}" for project "{project}"', file=sys.stderr)
print("Suggestion: Try again with --package argument if that's not what you wanted", file=sys.stderr)

Expand Down
66 changes: 22 additions & 44 deletions stdlib/_ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ from typing import Any, ClassVar
from typing_extensions import Literal

PyCF_ONLY_AST: Literal[1024]
if sys.version_info >= (3, 8):
PyCF_TYPE_COMMENTS: Literal[4096]
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
PyCF_TYPE_COMMENTS: Literal[4096]
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]

_Identifier: typing_extensions.TypeAlias = str

Expand All @@ -19,33 +18,29 @@ class AST:
# TODO: Not all nodes have all of the following attributes
lineno: int
col_offset: int
if sys.version_info >= (3, 8):
end_lineno: int | None
end_col_offset: int | None
type_comment: str | None
end_lineno: int | None
end_col_offset: int | None
type_comment: str | None

class mod(AST): ...
class type_ignore(AST): ...

if sys.version_info >= (3, 8):
class type_ignore(AST): ...

class TypeIgnore(type_ignore):
if sys.version_info >= (3, 10):
__match_args__ = ("lineno", "tag")
tag: str
class TypeIgnore(type_ignore):
if sys.version_info >= (3, 10):
__match_args__ = ("lineno", "tag")
tag: str

class FunctionType(mod):
if sys.version_info >= (3, 10):
__match_args__ = ("argtypes", "returns")
argtypes: list[expr]
returns: expr
class FunctionType(mod):
if sys.version_info >= (3, 10):
__match_args__ = ("argtypes", "returns")
argtypes: list[expr]
returns: expr

class Module(mod):
if sys.version_info >= (3, 10):
__match_args__ = ("body", "type_ignores")
body: list[stmt]
if sys.version_info >= (3, 8):
type_ignores: list[TypeIgnore]
type_ignores: list[TypeIgnore]

class Interactive(mod):
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -340,21 +335,6 @@ class JoinedStr(expr):
__match_args__ = ("values",)
values: list[expr]

if sys.version_info < (3, 8):
class Num(expr): # Deprecated in 3.8; use Constant
n: int | float | complex

class Str(expr): # Deprecated in 3.8; use Constant
s: str

class Bytes(expr): # Deprecated in 3.8; use Constant
s: bytes

class NameConstant(expr): # Deprecated in 3.8; use Constant
value: Any

class Ellipsis(expr): ... # Deprecated in 3.8; use Constant

class Constant(expr):
if sys.version_info >= (3, 10):
__match_args__ = ("value", "kind")
Expand All @@ -364,12 +344,11 @@ class Constant(expr):
s: Any
n: int | float | complex

if sys.version_info >= (3, 8):
class NamedExpr(expr):
if sys.version_info >= (3, 10):
__match_args__ = ("target", "value")
target: Name
value: expr
class NamedExpr(expr):
if sys.version_info >= (3, 10):
__match_args__ = ("target", "value")
target: Name
value: expr

class Attribute(expr):
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -498,8 +477,7 @@ class ExceptHandler(excepthandler):
class arguments(AST):
if sys.version_info >= (3, 10):
__match_args__ = ("posonlyargs", "args", "vararg", "kwonlyargs", "kw_defaults", "kwarg", "defaults")
if sys.version_info >= (3, 8):
posonlyargs: list[arg]
posonlyargs: list[arg]
args: list[arg]
vararg: arg | None
kwonlyargs: list[arg]
Expand Down
5 changes: 0 additions & 5 deletions stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ else:
def unicode_escape_decode(__data: str | ReadableBuffer, __errors: str | None = None) -> tuple[str, int]: ...

def unicode_escape_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...

if sys.version_info < (3, 8):
def unicode_internal_decode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[str, int]: ...
def unicode_internal_encode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[bytes, int]: ...

def utf_16_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
def utf_16_be_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
def utf_16_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
Expand Down
14 changes: 7 additions & 7 deletions stdlib/_curses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,10 @@ if sys.platform != "win32":
def vline(self, ch: _ChType, n: int) -> None: ...
@overload
def vline(self, y: int, x: int, ch: _ChType, n: int) -> None: ...
if sys.version_info >= (3, 8):
class _ncurses_version(NamedTuple):
major: int
minor: int
patch: int
ncurses_version: _ncurses_version
window = _CursesWindow # undocumented

class _ncurses_version(NamedTuple):
major: int
minor: int
patch: int
ncurses_version: _ncurses_version
window = _CursesWindow # undocumented
19 changes: 7 additions & 12 deletions stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from _thread import _excepthook, _ExceptHookArgs
from _typeshed import ProfileFunction, TraceFunction
from collections.abc import Callable, Iterable, Mapping
from types import TracebackType
Expand Down Expand Up @@ -28,11 +29,10 @@ __all__ = [
"settrace",
"local",
"stack_size",
"ExceptHookArgs",
"excepthook",
]

if sys.version_info >= (3, 8):
__all__ += ["ExceptHookArgs", "excepthook"]

def active_count() -> int: ...
def current_thread() -> Thread: ...
def currentThread() -> Thread: ...
Expand Down Expand Up @@ -72,10 +72,8 @@ class Thread:
def join(self, timeout: float | None = None) -> None: ...
def getName(self) -> str: ...
def setName(self, name: str) -> None: ...
if sys.version_info >= (3, 8):
@property
def native_id(self) -> int | None: ... # only available on some platforms

@property
def native_id(self) -> int | None: ... # only available on some platforms
def is_alive(self) -> bool: ...
if sys.version_info < (3, 9):
def isAlive(self) -> bool: ...
Expand Down Expand Up @@ -138,11 +136,8 @@ class Event:
def clear(self) -> None: ...
def wait(self, timeout: float | None = None) -> bool: ...

if sys.version_info >= (3, 8):
from _thread import _excepthook, _ExceptHookArgs

excepthook = _excepthook
ExceptHookArgs = _ExceptHookArgs
excepthook = _excepthook
ExceptHookArgs = _ExceptHookArgs

class Timer(Thread):
def __init__(
Expand Down
9 changes: 1 addition & 8 deletions stdlib/_osx_support.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from collections.abc import Iterable, Sequence
from typing import TypeVar

Expand All @@ -13,13 +12,7 @@ _COMPILER_CONFIG_VARS: tuple[str, ...] # undocumented
_INITPRE: str # undocumented

def _find_executable(executable: str, path: str | None = None) -> str | None: ... # undocumented

if sys.version_info >= (3, 8):
def _read_output(commandstring: str, capture_stderr: bool = False) -> str | None: ... # undocumented

else:
def _read_output(commandstring: str) -> str | None: ... # undocumented

def _read_output(commandstring: str, capture_stderr: bool = False) -> str | None: ... # undocumented
def _find_build_tool(toolname: str) -> str: ... # undocumented

_SYSTEM_VERSION: str | None # undocumented
Expand Down
88 changes: 40 additions & 48 deletions stdlib/_socket.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import sys
from _typeshed import ReadableBuffer, WriteableBuffer
from collections.abc import Iterable
from typing import Any, SupportsInt, overload
from typing import Any, SupportsIndex, overload
from typing_extensions import TypeAlias

if sys.version_info >= (3, 8):
from typing import SupportsIndex

_FD: TypeAlias = SupportsIndex
else:
_FD: TypeAlias = SupportsInt

_CMSG: TypeAlias = tuple[int, int, bytes]
_CMSGArg: TypeAlias = tuple[int, int, ReadableBuffer]

Expand Down Expand Up @@ -104,35 +97,34 @@ INADDR_UNSPEC_GROUP: int
IPPORT_RESERVED: int
IPPORT_USERRESERVED: int

if sys.platform != "win32" or sys.version_info >= (3, 8):
IPPROTO_AH: int
IPPROTO_DSTOPTS: int
IPPROTO_EGP: int
IPPROTO_ESP: int
IPPROTO_FRAGMENT: int
IPPROTO_GGP: int
IPPROTO_HOPOPTS: int
IPPROTO_ICMPV6: int
IPPROTO_IDP: int
IPPROTO_IGMP: int
IPPROTO_IPV4: int
IPPROTO_IPV6: int
IPPROTO_MAX: int
IPPROTO_ND: int
IPPROTO_NONE: int
IPPROTO_PIM: int
IPPROTO_PUP: int
IPPROTO_ROUTING: int
IPPROTO_SCTP: int

if sys.platform != "darwin":
IPPROTO_CBT: int
IPPROTO_ICLFXBM: int
IPPROTO_IGP: int
IPPROTO_L2TP: int
IPPROTO_PGM: int
IPPROTO_RDP: int
IPPROTO_ST: int
IPPROTO_AH: int
IPPROTO_DSTOPTS: int
IPPROTO_EGP: int
IPPROTO_ESP: int
IPPROTO_FRAGMENT: int
IPPROTO_GGP: int
IPPROTO_HOPOPTS: int
IPPROTO_ICMPV6: int
IPPROTO_IDP: int
IPPROTO_IGMP: int
IPPROTO_IPV4: int
IPPROTO_IPV6: int
IPPROTO_MAX: int
IPPROTO_ND: int
IPPROTO_NONE: int
IPPROTO_PIM: int
IPPROTO_PUP: int
IPPROTO_ROUTING: int
IPPROTO_SCTP: int

if sys.platform != "darwin":
IPPROTO_CBT: int
IPPROTO_ICLFXBM: int
IPPROTO_IGP: int
IPPROTO_L2TP: int
IPPROTO_PGM: int
IPPROTO_RDP: int
IPPROTO_ST: int

IPPROTO_ICMP: int
IPPROTO_IP: int
Expand Down Expand Up @@ -352,7 +344,7 @@ if sys.platform == "linux":

CAN_RAW_FD_FRAMES: int

if sys.platform == "linux" and sys.version_info >= (3, 8):
if sys.platform == "linux":
CAN_BCM_SETTIMER: int
CAN_BCM_STARTTIMER: int
CAN_BCM_TX_COUNTEVT: int
Expand Down Expand Up @@ -513,7 +505,7 @@ if sys.platform != "win32" and sys.platform != "darwin":
TCP_CONGESTION: int
TCP_USER_TIMEOUT: int

if sys.platform == "linux" and sys.version_info >= (3, 8):
if sys.platform == "linux":
AF_QIPCRTR: int

# Semi-documented constants
Expand Down Expand Up @@ -584,9 +576,11 @@ class socket:
@property
def timeout(self) -> float | None: ...
if sys.platform == "win32":
def __init__(self, family: int = ..., type: int = ..., proto: int = ..., fileno: _FD | bytes | None = ...) -> None: ...
def __init__(
self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | bytes | None = ...
) -> None: ...
else:
def __init__(self, family: int = ..., type: int = ..., proto: int = ..., fileno: _FD | None = ...) -> None: ...
def __init__(self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | None = ...) -> None: ...

def bind(self, __address: _Address) -> None: ...
def close(self) -> None: ...
Expand Down Expand Up @@ -650,8 +644,8 @@ SocketType = socket

# ----- Functions -----

def close(__fd: _FD) -> None: ...
def dup(__fd: _FD) -> int: ...
def close(__fd: SupportsIndex) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have a _typeshed.FileDescriptor alias but it's just int. No change needed in this PR, but might be worth looking into whether we can make that alias usable here.

def dup(__fd: SupportsIndex) -> int: ...

# the 5th tuple item is an address
def getaddrinfo(
Expand Down Expand Up @@ -687,11 +681,9 @@ if sys.platform != "win32":
def CMSG_SPACE(__length: int) -> int: ...
def socketpair(__family: int = ..., __type: int = ..., __proto: int = ...) -> tuple[socket, socket]: ...

# Windows added these in 3.8, but didn't have them before
if sys.platform != "win32" or sys.version_info >= (3, 8):
def if_nameindex() -> list[tuple[int, str]]: ...
def if_nametoindex(__name: str) -> int: ...
def if_indextoname(__index: int) -> str: ...
def if_nameindex() -> list[tuple[int, str]]: ...
def if_nametoindex(__name: str) -> int: ...
def if_indextoname(__index: int) -> str: ...

if sys.version_info >= (3, 12):
IP_PKTINFO: int
Expand Down
2 changes: 1 addition & 1 deletion stdlib/_stat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def S_ISSOCK(mode: int) -> bool: ...
def S_ISWHT(mode: int) -> bool: ...
def filemode(mode: int) -> str: ...

if sys.platform == "win32" and sys.version_info >= (3, 8):
if sys.platform == "win32":
IO_REPARSE_TAG_SYMLINK: int
IO_REPARSE_TAG_MOUNT_POINT: int
IO_REPARSE_TAG_APPEXECLINK: int
Expand Down
Loading