Skip to content

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Feb 4, 2023

Found by grepping for : int = False

(I also grepped for : int = True, but there weren't any hits.)

@AlexWaygood AlexWaygood changed the title Use bool for annotations where the default is False stdlib: use bool for annotations where the default is False Feb 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

isort (https://github.com/pycqa/isort)
+ isort/api.py:196: error: No overload variant of "compile" matches argument types "str", "str", "str", "int", "int"  [call-overload]
+ isort/api.py:196: note: Possible overload variants:
+ isort/api.py:196: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: Literal[0], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> CodeType
+ isort/api.py:196: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, *, dont_inherit: bool = ..., optimize: int = ..., _feature_version: int = ...) -> CodeType
+ isort/api.py:196: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: Literal[1024], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> AST
+ isort/api.py:196: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: int, dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> Any
+ isort/api.py:223: error: No overload variant of "compile" matches argument types "str", "str", "str", "int", "int"  [call-overload]
+ isort/api.py:223: note: Possible overload variants:
+ isort/api.py:223: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: Literal[0], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> CodeType
+ isort/api.py:223: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, *, dont_inherit: bool = ..., optimize: int = ..., _feature_version: int = ...) -> CodeType
+ isort/api.py:223: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: Literal[1024], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> AST
+ isort/api.py:223: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: int, dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> Any

streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/runtime/scriptrunner/script_runner.py: note: In member "_run_script" of class "ScriptRunner":
+ lib/streamlit/runtime/scriptrunner/script_runner.py:495:20: error: No overload variant of "compile" matches argument types "Any", "str", "str", "int", "int", "int"  [call-overload]
+ lib/streamlit/runtime/scriptrunner/script_runner.py:495:20: note: Possible overload variants:
+ lib/streamlit/runtime/scriptrunner/script_runner.py:495:20: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: Literal[0], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> CodeType
+ lib/streamlit/runtime/scriptrunner/script_runner.py:495:20: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, *, dont_inherit: bool = ..., optimize: int = ..., _feature_version: int = ...) -> CodeType
+ lib/streamlit/runtime/scriptrunner/script_runner.py:495:20: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: Literal[1024], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> AST
+ lib/streamlit/runtime/scriptrunner/script_runner.py:495:20: note:     def compile(source: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], Module, Expression, Interactive], filename: Union[str, Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]], _PathLike[Any]], mode: str, flags: int, dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> Any

@AlexWaygood
Copy link
Member Author

It looks like a big fallout because of the verbose error messages, but in actual fact that's only 3 new hits being reported in user code.

I could also just revert the changes to builtins.compile(), however. Curious for other people's thoughts.

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

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

I like the simple defaults in stubs :)

@Akuli
Copy link
Collaborator

Akuli commented Feb 4, 2023

I think it's fine to get a new mypy error for using an integer as the compile() argument. The documentation of compile() talks about zero and nonzero integers, but was written before Python had a bool type (Python 2.2 docs have the same text).

@AlexWaygood
Copy link
Member Author

Then let's do it.

@AlexWaygood AlexWaygood merged commit 1e3d762 into main Feb 4, 2023
@AlexWaygood AlexWaygood deleted the bool-defaults branch February 4, 2023 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants