Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dc02ae

Browse files
authored
Fix stubtest issues (#5360)
* Fix some stubtest issues * Remove MADV_SOFT_OFFLINE
1 parent e3f510e commit 2dc02ae

8 files changed

Lines changed: 34 additions & 33 deletions

File tree

stdlib/mmap.pyi

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,37 @@ else:
8282
def __delitem__(self, index: Union[int, slice]) -> None: ...
8383
def __setitem__(self, index: Union[int, slice], object: bytes) -> None: ...
8484

85-
if sys.version_info >= (3, 8):
85+
if sys.version_info >= (3, 8) and sys.platform != "win32":
8686
MADV_NORMAL: int
8787
MADV_RANDOM: int
8888
MADV_SEQUENTIAL: int
8989
MADV_WILLNEED: int
9090
MADV_DONTNEED: int
91-
MADV_REMOVE: int
92-
MADV_DONTFORK: int
93-
MADV_DOFORK: int
94-
MADV_HWPOISON: int
95-
MADV_MERGEABLE: int
96-
MADV_UNMERGEABLE: int
97-
MADV_SOFT_OFFLINE: int
98-
MADV_HUGEPAGE: int
99-
MADV_NOHUGEPAGE: int
100-
MADV_DONTDUMP: int
101-
MADV_DODUMP: int
102-
MADV_FREE: int
103-
MADV_NOSYNC: int
104-
MADV_AUTOSYNC: int
105-
MADV_NOCORE: int
106-
MADV_CORE: int
107-
MADV_PROTECT: int
91+
92+
if sys.platform == "linux":
93+
MADV_REMOVE: int
94+
MADV_DONTFORK: int
95+
MADV_DOFORK: int
96+
MADV_HWPOISON: int
97+
MADV_MERGEABLE: int
98+
MADV_UNMERGEABLE: int
99+
# Seems like this constant is not defined in glibc.
100+
# See https://github.com/python/typeshed/pull/5360 for details
101+
# MADV_SOFT_OFFLINE: int
102+
MADV_HUGEPAGE: int
103+
MADV_NOHUGEPAGE: int
104+
MADV_DONTDUMP: int
105+
MADV_DODUMP: int
106+
MADV_FREE: int
107+
108+
# This Values are defined for FreeBSD but type checkers do not support conditions for these
109+
if sys.platform != "linux" and sys.platform != "darwin":
110+
MADV_NOSYNC: int
111+
MADV_AUTOSYNC: int
112+
MADV_NOCORE: int
113+
MADV_CORE: int
114+
MADV_PROTECT: int
115+
116+
if sys.version_info >= (3, 10) and sys.platform == "darwin":
117+
MADV_FREE_REUSABLE: int
118+
MADV_FREE_REUSE: int

stdlib/urllib/request.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class BaseHandler:
9797
parent: OpenerDirector
9898
def add_parent(self, parent: OpenerDirector) -> None: ...
9999
def close(self) -> None: ...
100-
def http_error_nnn(self, req: Request, fp: IO[str], code: int, msg: int, headers: Mapping[str, str]) -> _UrlopenRet: ...
101100

102101
class HTTPDefaultErrorHandler(BaseHandler):
103102
def http_error_default(

stdlib/urllib/robotparser.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RobotFileParser:
1010
def set_url(self, url: str) -> None: ...
1111
def read(self) -> None: ...
1212
def parse(self, lines: Iterable[str]) -> None: ...
13-
def can_fetch(self, user_agent: str, url: str) -> bool: ...
13+
def can_fetch(self, useragent: str, url: str) -> bool: ...
1414
def mtime(self) -> int: ...
1515
def modified(self) -> None: ...
1616
def crawl_delay(self, useragent: str) -> Optional[str]: ...

stdlib/webbrowser.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class UnixBrowser(BaseBrowser):
4848
def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ...
4949

5050
class Mozilla(UnixBrowser):
51-
raise_opts: List[str]
5251
remote_args: List[str]
5352
remote_action: str
5453
remote_action_newwin: str

tests/stubtest_whitelists/py310.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ logging.handlers.TimedRotatingFileHandler.__init__
6464
logging.handlers.WatchedFileHandler.__init__
6565
macpath # module removed in 3.8
6666
macurl2path # module removed in 3.7
67-
mmap.MADV_[A-Z_]+ # platform dependent constants
6867
multiprocessing.spawn._main
6968
os.getgrouplist
7069
os.sendfile

tests/stubtest_whitelists/py38.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ collections.abc.AsyncGenerator.ag_running
3434
collections.abc.ItemsView.__reversed__
3535
collections.abc.KeysView.__reversed__
3636
collections.abc.ValuesView.__reversed__
37-
concurrent.futures.ProcessPoolExecutor.map
3837
contextlib.nullcontext # not a function at runtime
3938
contextvars.Context.__init__ # Default C __init__ signature is wrong
4039
dataclasses.field
@@ -52,7 +51,6 @@ ipaddress._BaseNetwork.broadcast_address
5251
ipaddress._BaseNetwork.hostmask
5352
macpath # removed in 3.8
5453
macurl2path # removed in 3.7
55-
mmap.MADV_[A-Z_]+
5654
multiprocessing.spawn._main
5755
pickle.Pickler.reducer_override # implemented in C pickler
5856
queue.SimpleQueue.__init__ # Default C __init__ signature is wrong

tests/stubtest_whitelists/py39.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ logging.handlers.TimedRotatingFileHandler.__init__
7373
logging.handlers.WatchedFileHandler.__init__
7474
macpath # module removed in 3.8
7575
macurl2path # module removed in 3.7
76-
mmap.MADV_[A-Z_]+ # platform dependent constants
7776
multiprocessing.spawn._main
7877
os.MFD_HUGE_32MB
7978
os.MFD_HUGE_512MB

tests/stubtest_whitelists/py3_common.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,17 @@ typing.IO.__next__ # Added because IO streams are iterable. See https://github.
208208
typing.type_check_only # typing decorator that is not available at runtime
209209
unittest.mock.patch # It's a complicated overload and I haven't been able to figure out why stubtest doesn't like it
210210
urllib.parse._DefragResultBase.__new__ # Generic NamedTuple is problematic in mypy, so regular tuple was used. See https://github.com/python/mypy/issues/685
211-
urllib.request.BaseHandler.http_error_nnn
212-
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__
213-
urllib.robotparser.RobotFileParser.can_fetch
211+
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified
214212
warnings.catch_warnings.__init__ # Defining this ruins the __new__ overrides
215213
weakref.CallableProxyType.__getattr__ # Should have all attributes of proxy
216214
weakref.ProxyType.__getattr__ # Should have all attributes of proxy
217215
weakref.ReferenceType.__call__ # C function default annotation is wrong
218216
weakref.WeakKeyDictionary.get
219217
weakref.WeakKeyDictionary.update
220218
weakref.WeakValueDictionary.get
221-
webbrowser.Mozilla.raise_opts
222-
webbrowser.UnixBrowser.raise_opts
223-
webbrowser.UnixBrowser.remote_action
224-
webbrowser.UnixBrowser.remote_action_newtab
225-
webbrowser.UnixBrowser.remote_action_newwin
219+
webbrowser.UnixBrowser.remote_action # always overridden in inheriting class
220+
webbrowser.UnixBrowser.remote_action_newtab # always overridden in inheriting class
221+
webbrowser.UnixBrowser.remote_action_newwin # always overridden in inheriting class
226222
wsgiref.types # Doesn't exist, see comments in file
227223

228224
# ==========

0 commit comments

Comments
 (0)