-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Change some tkinter function parameter types from bool to int. #4765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
I'm in the process of pulling a newer version of typeshed into Google
and seeing a lot of new errors due to code that passes 0 or 1 into
functions that are annotated as expecting bools.
Based on the fact that tk.{YES,NO,TRUE,FALSE} are defined as ints
(https://github.com/python/typeshed/blob/20a847218ac085ad691ea8d99155ee8ac7005479/stdlib/3/tkinter/constants.pyi#L3-L6)
and that the usage example in the source code also uses an int as a bool
(https://github.com/python/cpython/blob/cc75ab791dd5ae2cb9f6e0c3c5f734a6ae1eb2a9/Lib/tkinter/__init__.py#L25),
I think the annotations should be expanded.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: + porcupine/plugins/overview.py:37: error: No overload variant matches argument types "int", "bool", "bool", "Callable[[VarArg(object)], None]", "str"
+ porcupine/plugins/overview.py:37: note: <1 more non-matching overload not shown>
+ porcupine/plugins/overview.py:37: note: def configure(self, cnf: Optional[Dict[str, Any]] = ..., *, autoseparators: bool = ..., background: str = ..., bd: Union[str, float] = ..., bg: str = ..., blockcursor: bool = ..., border: Union[str, float] = ..., borderwidth: Union[str, float] = ..., cursor: Union[str, Tuple[str], Tuple[str, str], Tuple[str, str, str], Tuple[str, str, str, str]] = ..., endline: Union[int, Literal['']] = ..., exportselection: bool = ..., fg: str = ..., font: Union[str, Font, Tuple[str, int], Tuple[str, int, str], Tuple[str, int, Union[List[str], Tuple[str, ...]]]] = ..., foreground: str = ..., height: Union[str, float] = ..., highlightbackground: str = ..., highlightcolor: str = ..., highlightthickness: Union[str, float] = ..., inactiveselectbackground: str = ..., insertbackground: str = ..., insertborderwidth: Union[str, float] = ..., insertofftime: int = ..., insertontime: int = ..., insertunfocussed: Union[Literal['none'], Literal['hollow'], Literal['solid']] = ..., insertwidth: Union[str, float] = ..., maxundo: int = ..., padx: Union[str, float] = ..., pady: Union[str, float] = ..., relief: Union[Literal['raised'], Literal['sunken'], Literal['flat'], Literal['ridge'], Literal['solid'], Literal['groove']] = ..., selectbackground: str = ..., selectborderwidth: Union[str, float] = ..., selectforeground: str = ..., setgrid: bool = ..., spacing1: Union[str, float] = ..., spacing2: Union[str, float] = ..., spacing3: Union[str, float] = ..., startline: Union[int, Literal['']] = ..., state: Union[Literal['normal'], Literal['disabled']] = ..., tabs: Union[Union[str, float], str, Tuple[Union[Union[str, float], str], ...]] = ..., tabstyle: Union[Literal['tabular'], Literal['wordprocessor']] = ..., takefocus: Union[Literal[''], Callable[[str], Optional[int]]] = ..., undo: bool = ..., width: int = ..., wrap: Union[Literal['none'], Literal['char'], Literal['word']] = ..., xscrollcommand: Union[str, Callable[[float, float], Any]] = ..., yscrollcommand: Union[str, Callable[[float, float], Any]] = ...) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]
+ porcupine/plugins/overview.py:37: note: Possible overload variant:
+ more_plugins/tetris.py:227: error: Argument "takefocus" to "Canvas" has incompatible type "Literal[True]"; expected "Union[Literal[''], Callable[[str], Optional[int]]]"
|
Literal[True] doesn't seem to match Optional[int]?
I derped, didn't realize that Optional[int] was part of the Callable, not its own type.
srittau
approved these changes
Nov 13, 2020
Collaborator
srittau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think this is a bit unfortunate per the reasoning in #4634 and I hope this instance will get fixed in Python at some point, I agree that in this case it's best to use int (for now).
Akuli
added a commit
to Akuli/typeshed
that referenced
this pull request
Jan 5, 2021
python#4765)" This reverts commit a42f545.
Akuli
added a commit
to Akuli/typeshed
that referenced
this pull request
Jan 5, 2021
Akuli
added a commit
to Akuli/typeshed
that referenced
this pull request
Jan 5, 2021
Akuli
added a commit
to Akuli/typeshed
that referenced
this pull request
Jan 5, 2021
Akuli
added a commit
to Akuli/typeshed
that referenced
this pull request
Feb 10, 2024
python#4765)" This reverts commit a42f545.
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.
I'm in the process of pulling a newer version of typeshed into Google
and seeing a lot of new errors due to code that passes 0 or 1 into
functions that are annotated as expecting bools.
Based on the fact that tk.{YES,NO,TRUE,FALSE} are defined as ints
(
typeshed/stdlib/3/tkinter/constants.pyi
Lines 3 to 6 in 20a8472
and that the usage example in the source code also uses an int as a bool
(https://github.com/python/cpython/blob/cc75ab791dd5ae2cb9f6e0c3c5f734a6ae1eb2a9/Lib/tkinter/__init__.py#L25),
I think the annotations should be expanded.