stdlib: fix signatures for some functions with unrepresentable defaults#11000
Merged
JelleZijlstra merged 3 commits intopython:mainfrom Nov 9, 2023
Merged
stdlib: fix signatures for some functions with unrepresentable defaults#11000JelleZijlstra merged 3 commits intopython:mainfrom
JelleZijlstra merged 3 commits intopython:mainfrom
Conversation
AlexWaygood
reviewed
Nov 9, 2023
This comment has been minimized.
This comment has been minimized.
AlexWaygood
reviewed
Nov 9, 2023
Co-authored-by: Alex Waygood <[email protected]>
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
AlexWaygood
approved these changes
Nov 9, 2023
Member
There was a problem hiding this comment.
These all look correct.
I pick up 14 more errors running stdlib stubtest locally on Python 3.12 with a Windows machine with your stubtest PR branch -- you could do those as well? But I'm also happy to defer those to another PR
Additional errors
error: _warnings.warn is inconsistent, stub does not have argument "skip_file_prefixes"
Stub: in file stdlib\_warnings.pyi:7
Overload(def (message: builtins.str, category: Union[Type[builtins.Warning], None] =, stacklevel: builtins.int =, source: Union[Any, None] =), def (message: builtins.Warning, category: Any =, stacklevel: builtins.int =, source: Union[Any, None] =))
Inferred signature: def (message: Union[builtins.str, builtins.Warning], category: Union[Type[builtins.Warning], None, Any] = ..., stacklevel: builtins.int = ..., source: Union[Any, None] = ...)
Runtime:
def (message, category=None, stacklevel=1, source=None, *, skip_file_prefixes=<unrepresentable>)
error: builtins.getattr is inconsistent, stub argument "__name" has a default value but runtime argument does not
Stub: in file stdlib\builtins.pyi:1426
Overload(def (builtins.object, builtins.str) -> Any, def (builtins.object, builtins.str, None) -> Union[Any, None], def (builtins.object, builtins.str, builtins.bool) -> Union[Any, builtins.bool], def (builtins.object, name: builtins.str, builtins.list[Any]) -> Union[Any, builtins.list[Any]], def (builtins.object, name: builtins.str, builtins.dict[Any, Any]) -> Union[Any, builtins.dict[Any, Any]], def [_T] (builtins.object, builtins.str, _T`-1) -> Union[Any, _T`-1])
Inferred signature: def (__o: builtins.object, __name: builtins.str = ..., name: builtins.str = ..., __default: Union[None, builtins.bool, builtins.list[Any], builtins.dict[Any, Any], _T`-1] = ...)
Runtime:
def (object, name, default=<unrepresentable>, /)
error: builtins.getattr is inconsistent, stub argument "name" differs from runtime argument "default"
Stub: in file stdlib\builtins.pyi:1426
Overload(def (builtins.object, builtins.str) -> Any, def (builtins.object, builtins.str, None) -> Union[Any, None], def (builtins.object, builtins.str, builtins.bool) -> Union[Any, builtins.bool], def (builtins.object, name: builtins.str, builtins.list[Any]) -> Union[Any, builtins.list[Any]], def (builtins.object, name: builtins.str, builtins.dict[Any, Any]) -> Union[Any, builtins.dict[Any, Any]], def [_T] (builtins.object, builtins.str, _T`-1) -> Union[Any, _T`-1])
Inferred signature: def (__o: builtins.object, __name: builtins.str = ..., name: builtins.str = ..., __default: Union[None, builtins.bool, builtins.list[Any], builtins.dict[Any, Any], _T`-1] = ...)
Runtime:
def (object, name, default=<unrepresentable>, /)
error: builtins.getattr is inconsistent, stub argument "name" should be positional-only (rename with a leading double underscore, i.e. "__default")
Stub: in file stdlib\builtins.pyi:1426
Overload(def (builtins.object, builtins.str) -> Any, def (builtins.object, builtins.str, None) -> Union[Any, None], def (builtins.object, builtins.str, builtins.bool) -> Union[Any, builtins.bool], def (builtins.object, name: builtins.str, builtins.list[Any]) -> Union[Any, builtins.list[Any]], def (builtins.object, name: builtins.str, builtins.dict[Any, Any]) -> Union[Any, builtins.dict[Any, Any]], def [_T] (builtins.object, builtins.str, _T`-1) -> Union[Any, _T`-1])
Inferred signature: def (__o: builtins.object, __name: builtins.str = ..., name: builtins.str = ..., __default: Union[None, builtins.bool, builtins.list[Any], builtins.dict[Any, Any], _T`-1] = ...)
Runtime:
def (object, name, default=<unrepresentable>, /)
error: builtins.getattr is inconsistent, runtime does not have argument "__default"
Stub: in file stdlib\builtins.pyi:1426
Overload(def (builtins.object, builtins.str) -> Any, def (builtins.object, builtins.str, None) -> Union[Any, None], def (builtins.object, builtins.str, builtins.bool) -> Union[Any, builtins.bool], def (builtins.object, name: builtins.str, builtins.list[Any]) -> Union[Any, builtins.list[Any]], def (builtins.object, name: builtins.str, builtins.dict[Any, Any]) -> Union[Any, builtins.dict[Any, Any]], def [_T] (builtins.object, builtins.str, _T`-1) -> Union[Any, _T`-1])
Inferred signature: def (__o: builtins.object, __name: builtins.str = ..., name: builtins.str = ..., __default: Union[None, builtins.bool, builtins.list[Any], builtins.dict[Any, Any], _T`-1] = ...)
Runtime:
def (object, name, default=<unrepresentable>, /)
error: builtins.iter is inconsistent, stub argument "__iterable" differs from runtime argument "object"
Stub: in file stdlib\builtins.pyi:1453
Overload(def [_SupportsNextT <: _typeshed.SupportsNext[Any]] (_typeshed.SupportsIter[_SupportsNextT`-1]) -> _SupportsNextT`-1, def [_T] (builtins._GetItemIterable[_T`-1]) -> typing.Iterator[_T`-1], def [_T] (def () -> Union[_T`-1, None], None) -> typing.Iterator[_T`-1], def [_T] (def () -> _T`-1, builtins.object) -> typing.Iterator[_T`-1])
Inferred signature: def (__iterable: Union[_typeshed.SupportsIter[_SupportsNextT`-1], builtins._GetItemIterable[_T`-1], def () -> Union[_T`-1, None]], __sentinel: builtins.object = ...)
Runtime:
def (object, sentinel=<unrepresentable>, /)
error: codecs.StreamReader.__getattr__ is inconsistent, runtime argument "getattr" has a default value of type def (Any, Any, Any =) -> Any, which is incompatible with stub argument type def (builtins.str) -> Any
Stub: in file stdlib\codecs.pyi:230
def (codecs.StreamReader, builtins.str, def (builtins.str) -> Any =) -> Any
Runtime: in file <frozen codecs>
def (self, name, getattr=<built-in function getattr>)
error: codecs.StreamWriter.__getattr__ is inconsistent, runtime argument "getattr" has a default value of type def (Any, Any, Any =) -> Any, which is incompatible with stub argument type def (builtins.str) -> Any
Stub: in file stdlib\codecs.pyi:216
def (codecs.StreamWriter, builtins.str, def (builtins.str) -> Any =) -> Any
Runtime: in file <frozen codecs>
def (self, name, getattr=<built-in function getattr>)
error: collections.OrderedDict.pop is inconsistent, stub argument "__key" should be positional or keyword (remove leading double underscore)
Stub: in file stdlib\collections\__init__.pyi:1106
Overload(def (self: builtins.dict[_KT`1, _VT`2], _KT`1) -> _VT`2, def (self: builtins.dict[_KT`1, _VT`2], _KT`1, _VT`2) -> _VT`2, def [_T] (self: builtins.dict[_KT`1, _VT`2], _KT`1, _T`-1) -> Union[_VT`2, _T`-1])
Inferred signature: def (self: builtins.dict[_KT`1, _VT`2], __key: _KT`1, __default: Union[_VT`2, _T`-1] = ...)
Runtime:
def (self, /, key, default=<unrepresentable>)
error: collections.OrderedDict.pop is inconsistent, stub argument "__default" should be positional or keyword (remove leading double underscore)
Stub: in file stdlib\collections\__init__.pyi:1106
Overload(def (self: builtins.dict[_KT`1, _VT`2], _KT`1) -> _VT`2, def (self: builtins.dict[_KT`1, _VT`2], _KT`1, _VT`2) -> _VT`2, def [_T] (self: builtins.dict[_KT`1, _VT`2], _KT`1, _T`-1) -> Union[_VT`2, _T`-1])
Inferred signature: def (self: builtins.dict[_KT`1, _VT`2], __key: _KT`1, __default: Union[_VT`2, _T`-1] = ...)
Runtime:
def (self, /, key, default=<unrepresentable>)
error: contextvars.ContextVar.get is inconsistent, stub argument "default" should be positional-only (rename with a leading double underscore, i.e. "__default")
Stub: in file stdlib\contextvars.pyi:24
Overload(def (self: contextvars.ContextVar[_T`1]) -> _T`1, def (self: contextvars.ContextVar[_T`1], default: _T`1) -> _T`1, def [_D] (self: contextvars.ContextVar[_T`1], default: _D`-1) -> Union[_D`-1, _T`1])
Inferred signature: def (self: contextvars.ContextVar[_T`1], default: Union[_T`1, _D`-1] = ...)
Runtime:
def (self, default=<unrepresentable>, /)
error: sqlite3.Connection.cursor is inconsistent, stub argument "cursorClass" differs from runtime argument "factory"
Stub: in file stdlib\sqlite3\__init__.pyi:351
Overload(def (self: sqlite3.dbapi2.Connection, cursorClass: None =) -> sqlite3.dbapi2.Cursor, def [_CursorT <: sqlite3.dbapi2.Cursor] (self: sqlite3.dbapi2.Connection, cursorClass: def (sqlite3.dbapi2.Connection) -> _CursorT`-1) -> _CursorT`-1)
Inferred signature: def (self: sqlite3.dbapi2.Connection, cursorClass: Union[None, def (sqlite3.dbapi2.Connection) -> _CursorT`-1] = ...)
Runtime:
def (self, /, factory=<unrepresentable>)
error: sqlite3.dbapi2.Connection.cursor is inconsistent, stub argument "cursorClass" differs from runtime argument "factory"
Stub: in file stdlib\sqlite3\dbapi2.pyi:351
Overload(def (self: sqlite3.dbapi2.Connection, cursorClass: None =) -> sqlite3.dbapi2.Cursor, def [_CursorT <: sqlite3.dbapi2.Cursor] (self: sqlite3.dbapi2.Connection, cursorClass: def (sqlite3.dbapi2.Connection) -> _CursorT`-1) -> _CursorT`-1)
Inferred signature: def (self: sqlite3.dbapi2.Connection, cursorClass: Union[None, def (sqlite3.dbapi2.Connection) -> _CursorT`-1] = ...)
Runtime:
def (self, /, factory=<unrepresentable>)
error: warnings.warn is inconsistent, stub does not have argument "skip_file_prefixes"
Stub: in file stdlib\warnings.pyi:7
Overload(def (message: builtins.str, category: Union[Type[builtins.Warning], None] =, stacklevel: builtins.int =, source: Union[Any, None] =), def (message: builtins.Warning, category: Any =, stacklevel: builtins.int =, source: Union[Any, None] =))
Inferred signature: def (message: Union[builtins.str, builtins.Warning], category: Union[Type[builtins.Warning], None, Any] = ..., stacklevel: builtins.int = ..., source: Union[Any, None] = ...)
Runtime:
def (message, category=None, stacklevel=1, source=None, *, skip_file_prefixes=<unrepresentable>)
Found 14 errors (checked 726 modules)
Member
Author
|
I was planning to point stubtest at my branch in a separate PR so I could see the fallout across versions and OSes. Also the |
Member
yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found with python/mypy#16433