-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
More complete type stubs for tkinter Canvas methods. #5188
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ /tmp/mypy_primer/new_typeshed/typeshed_to_test/stdlib/tkinter/__init__.pyi:1170: error: invalid syntax [syntax]
- porcupine/utils.py:22: error: Cannot find implementation or library stub for module named "dacite" [import]
- porcupine/settings.py:17: error: Cannot find implementation or library stub for module named "dacite" [import]
- porcupine/settings.py:80: error: unused 'type: ignore' comment
- porcupine/plugins/langserver.py:29: error: Cannot find implementation or library stub for module named "sansio_lsp_client" [import]
- porcupine/plugins/filetypes.py:11: error: Library stubs not installed for "toml" (or incompatible with Python 3.8) [import]
- porcupine/plugins/filetypes.py:11: note: (or run "mypy --install-types" to install all missing stub packages)
- porcupine/plugins/filetypes.py:11: note: Hint: "python3 -m pip install types-toml"
- porcupine/plugins/filetypes.py:11: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
|
It'll be a couple years before typeshed can use PEP 570 syntax, for now positional-only arguments are indicated by prefixing with a double underscore. |
Except for some auto generate code for protobuf, this is the first time we use |
Wow, I cannot wait to be done with Python 3.5.1 :-) |
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.
Thanks, remarks below! Also, running black on this file should hopefully fix the build issues.
I can't seem to get black installed on Windows for whatever reason, so I will hold off on that step if that's acceptable to you all. |
I blacked the code (pull before making more changes), but it is also possible on windows. I think something like:
|
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ porcupine/plugins/welcome.py:47: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/welcome.py:51: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/minimap.py:93: error: Argument "font" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/linenumbers.py:47: error: Argument 1 to "delete" of "Canvas" has incompatible type "str"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:307: error: Argument 1 to "delete" of "Canvas" has incompatible type "int"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:331: error: Argument "font" to "create_text" of "Canvas" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/fold.py:60: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:64: error: Argument "columns" to "Treeview" has incompatible type "Tuple[str, str, str]"; expected "Union[str, Union[List[str], Tuple[str, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:93: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pastebin.py:200: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
|
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ porcupine/plugins/welcome.py:47: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/welcome.py:51: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/minimap.py:93: error: Argument "font" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/linenumbers.py:47: error: Argument 1 to "delete" of "Canvas" has incompatible type "str"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:307: error: Argument 1 to "delete" of "Canvas" has incompatible type "int"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:331: error: Argument "font" to "create_text" of "Canvas" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/fold.py:60: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:64: error: Argument "columns" to "Treeview" has incompatible type "Tuple[str, str, str]"; expected "Union[str, Union[List[str], Tuple[str, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:93: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pastebin.py:200: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
|
1 similar comment
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ porcupine/plugins/welcome.py:47: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/welcome.py:51: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/minimap.py:93: error: Argument "font" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/linenumbers.py:47: error: Argument 1 to "delete" of "Canvas" has incompatible type "str"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:307: error: Argument 1 to "delete" of "Canvas" has incompatible type "int"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:331: error: Argument "font" to "create_text" of "Canvas" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/fold.py:60: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:64: error: Argument "columns" to "Treeview" has incompatible type "Tuple[str, str, str]"; expected "Union[str, Union[List[str], Tuple[str, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:93: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pastebin.py:200: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
|
Can you find/replace |
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ porcupine/plugins/welcome.py:47: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/welcome.py:51: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/minimap.py:93: error: Argument "font" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/linenumbers.py:47: error: Argument 1 to "delete" of "Canvas" has incompatible type "str"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:307: error: Argument 1 to "delete" of "Canvas" has incompatible type "int"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:331: error: Argument "font" to "create_text" of "Canvas" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/fold.py:60: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:64: error: Argument "columns" to "Treeview" has incompatible type "Tuple[str, str, str]"; expected "Union[str, Union[List[str], Tuple[str, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:93: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pastebin.py:200: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
|
1 similar comment
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ porcupine/plugins/welcome.py:47: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/welcome.py:51: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/minimap.py:93: error: Argument "font" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/linenumbers.py:47: error: Argument 1 to "delete" of "Canvas" has incompatible type "str"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:307: error: Argument 1 to "delete" of "Canvas" has incompatible type "int"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:331: error: Argument "font" to "create_text" of "Canvas" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/fold.py:60: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:64: error: Argument "columns" to "Treeview" has incompatible type "Tuple[str, str, str]"; expected "Union[str, Union[List[str], Tuple[str, Any]]]" [arg-type]
+ porcupine/plugins/pluginmanager.py:93: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, str]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
+ porcupine/plugins/pastebin.py:200: error: Argument "font" to "Label" has incompatible type "Tuple[str, int, Tuple[]]"; expected "Union[str, Font, Union[List[Any], Tuple[Any, Any]]]" [arg-type]
|
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ porcupine/plugins/linenumbers.py:47: error: Argument 1 to "delete" of "Canvas" has incompatible type "str"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
+ more_plugins/tetris.py:307: error: Argument 1 to "delete" of "Canvas" has incompatible type "int"; expected "Union[_CanvasObjectId, Iterable[_CanvasObjectId]]" [arg-type]
|
Often you can use a tag string instead of an item ID. The remaining mypy_primer failures are from code that does To fix this, you can replace _TagOrId = Union[_CanvasObjectId, str] |
@DanielRosenwasser Are you still interested in working on this? There's no hurry, but I can do the rest if you want. |
Hey @Akuli let me know if there's anything I've missed in the latest changes. |
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine.git)
+ more_plugins/tetris.py:307: error: Argument 1 to "delete" of "Canvas" has incompatible type "int"; expected "Union[str, _CanvasItemId]" [arg-type]
|
The
What do you think? |
I've been thinking about this a bit and it really depends on how much someone wants to protect against breaking the abstraction in addition to making sure you can't forge a fake object ID (on purpose or accidentally). In either case, it's not that important and unlikely that an ID will ever stop being an int. |
So I'll try to just turn it into a plain type alias to int later today. |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
1 similar comment
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
The code needs |
Co-authored-by: Akuli <akuviljanen17@gmail.com>
I decided to |
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.
Thanks!
Ah just as I was figuring out how to Thanks! |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
1 similar comment
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This change
_ObjectId
, meant to ensure that arbitrary handles aren't created.Canvas
instances.