[mmap] Use Final for constants (#14494)

This commit is contained in:
Semyon Moroz
2025-07-30 04:37:22 +00:00
committed by GitHub
parent 78faddc7f9
commit c06621ba71
2 changed files with 60 additions and 55 deletions
+55 -50
View File
@@ -1,38 +1,39 @@
import os
import sys
from _typeshed import ReadableBuffer, Unused
from collections.abc import Iterator
from typing import Final, Literal, NoReturn, overload
from typing_extensions import Self
ACCESS_DEFAULT: int
ACCESS_READ: int
ACCESS_WRITE: int
ACCESS_COPY: int
ACCESS_DEFAULT: Final = 0
ACCESS_READ: Final = 1
ACCESS_WRITE: Final = 2
ACCESS_COPY: Final = 3
ALLOCATIONGRANULARITY: int
ALLOCATIONGRANULARITY: Final[int]
if sys.platform == "linux":
MAP_DENYWRITE: int
MAP_EXECUTABLE: int
MAP_DENYWRITE: Final[int]
MAP_EXECUTABLE: Final[int]
if sys.version_info >= (3, 10):
MAP_POPULATE: int
MAP_POPULATE: Final[int]
if sys.version_info >= (3, 11) and sys.platform != "win32" and sys.platform != "darwin":
MAP_STACK: int
MAP_STACK: Final[int]
if sys.platform != "win32":
MAP_ANON: int
MAP_ANONYMOUS: int
MAP_PRIVATE: int
MAP_SHARED: int
PROT_EXEC: int
PROT_READ: int
PROT_WRITE: int
MAP_ANON: Final[int]
MAP_ANONYMOUS: Final[int]
MAP_PRIVATE: Final[int]
MAP_SHARED: Final[int]
PROT_EXEC: Final[int]
PROT_READ: Final[int]
PROT_WRITE: Final[int]
PAGESIZE: int
PAGESIZE: Final[int]
class mmap:
if sys.platform == "win32":
def __init__(self, fileno: int, length: int, tagname: str | None = ..., access: int = ..., offset: int = ...) -> None: ...
def __init__(self, fileno: int, length: int, tagname: str | None = None, access: int = 0, offset: int = 0) -> None: ...
else:
if sys.version_info >= (3, 13):
def __new__(
@@ -41,34 +42,38 @@ class mmap:
length: int,
flags: int = ...,
prot: int = ...,
access: int = ...,
offset: int = ...,
access: int = 0,
offset: int = 0,
*,
trackfd: bool = True,
) -> Self: ...
else:
def __new__(
cls, fileno: int, length: int, flags: int = ..., prot: int = ..., access: int = ..., offset: int = ...
cls, fileno: int, length: int, flags: int = ..., prot: int = ..., access: int = 0, offset: int = 0
) -> Self: ...
def close(self) -> None: ...
def flush(self, offset: int = ..., size: int = ...) -> None: ...
def flush(self, offset: int = 0, size: int = ...) -> None: ...
def move(self, dest: int, src: int, count: int) -> None: ...
def read_byte(self) -> int: ...
def readline(self) -> bytes: ...
def resize(self, newsize: int) -> None: ...
def seek(self, pos: int, whence: int = ...) -> None: ...
if sys.platform != "win32":
def seek(self, pos: int, whence: Literal[0, 1, 2, 3, 4] = os.SEEK_SET) -> None: ...
else:
def seek(self, pos: int, whence: Literal[0, 1, 2] = os.SEEK_SET) -> None: ...
def size(self) -> int: ...
def tell(self) -> int: ...
def write_byte(self, byte: int) -> None: ...
def __len__(self) -> int: ...
closed: bool
if sys.platform != "win32":
def madvise(self, option: int, start: int = ..., length: int = ...) -> None: ...
def madvise(self, option: int, start: int = 0, length: int = ...) -> None: ...
def find(self, sub: ReadableBuffer, start: int = ..., stop: int = ...) -> int: ...
def rfind(self, sub: ReadableBuffer, start: int = ..., stop: int = ...) -> int: ...
def read(self, n: int | None = ...) -> bytes: ...
def read(self, n: int | None = None) -> bytes: ...
def write(self, bytes: ReadableBuffer) -> int: ...
@overload
def __getitem__(self, key: int, /) -> int: ...
@@ -93,42 +98,42 @@ class mmap:
def seekable(self) -> Literal[True]: ...
if sys.platform != "win32":
MADV_NORMAL: int
MADV_RANDOM: int
MADV_SEQUENTIAL: int
MADV_WILLNEED: int
MADV_DONTNEED: int
MADV_FREE: int
MADV_NORMAL: Final[int]
MADV_RANDOM: Final[int]
MADV_SEQUENTIAL: Final[int]
MADV_WILLNEED: Final[int]
MADV_DONTNEED: Final[int]
MADV_FREE: Final[int]
if sys.platform == "linux":
MADV_REMOVE: int
MADV_DONTFORK: int
MADV_DOFORK: int
MADV_HWPOISON: int
MADV_MERGEABLE: int
MADV_UNMERGEABLE: int
MADV_REMOVE: Final[int]
MADV_DONTFORK: Final[int]
MADV_DOFORK: Final[int]
MADV_HWPOISON: Final[int]
MADV_MERGEABLE: Final[int]
MADV_UNMERGEABLE: Final[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_SOFT_OFFLINE: Final[int]
MADV_HUGEPAGE: Final[int]
MADV_NOHUGEPAGE: Final[int]
MADV_DONTDUMP: Final[int]
MADV_DODUMP: Final[int]
# This Values are defined for FreeBSD but type checkers do not support conditions for these
if sys.platform != "linux" and sys.platform != "darwin" and sys.platform != "win32":
MADV_NOSYNC: int
MADV_AUTOSYNC: int
MADV_NOCORE: int
MADV_CORE: int
MADV_PROTECT: int
MADV_NOSYNC: Final[int]
MADV_AUTOSYNC: Final[int]
MADV_NOCORE: Final[int]
MADV_CORE: Final[int]
MADV_PROTECT: Final[int]
if sys.version_info >= (3, 10) and sys.platform == "darwin":
MADV_FREE_REUSABLE: int
MADV_FREE_REUSE: int
MADV_FREE_REUSABLE: Final[int]
MADV_FREE_REUSE: Final[int]
if sys.version_info >= (3, 13) and sys.platform != "win32":
MAP_32BIT: Final = 32768
MAP_32BIT: Final[int]
if sys.version_info >= (3, 13) and sys.platform == "darwin":
MAP_NORESERVE: Final = 64
+5 -5
View File
@@ -597,12 +597,12 @@ if sys.platform == "darwin" and sys.version_info >= (3, 12):
PRIO_DARWIN_PROCESS: int
PRIO_DARWIN_THREAD: int
SEEK_SET: int
SEEK_CUR: int
SEEK_END: int
SEEK_SET: Final = 0
SEEK_CUR: Final = 1
SEEK_END: Final = 2
if sys.platform != "win32":
SEEK_DATA: int
SEEK_HOLE: int
SEEK_DATA: Final = 3
SEEK_HOLE: Final = 4
O_RDONLY: int
O_WRONLY: int