Skip to content

Use typeshed.Incomplete and object instead of Any in tkinter stubs #8458

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

Merged
merged 13 commits into from
Aug 2, 2022

Conversation

Akuli
Copy link
Collaborator

@Akuli Akuli commented Aug 1, 2022

Created by replacing all Anys with Incomplete and then reviewing manually with git add -p.

Tkinter had quite a lot of Any for a few reasons:

  • Old versions of stubgen generated Any | None (actually Optional[Any]) for parameters with a None default value.
  • I used Any in callables before I learned about Callable[[foo], object] for ignored return values.
  • Things that are impossible to type accurately. I left these as Any.

@github-actions

This comment has been minimized.

@Akuli Akuli changed the title Use typeshed.Incomplete in tkinter stubs Use typeshed.Incomplete and object instead of Any in tkinter stubs Aug 1, 2022
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@Akuli Akuli marked this pull request as ready for review August 1, 2022 20:01
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks, this is very useful! I skimmed it, and while there are a few more places where the Incomplete could be removed, since this is only a stylistic nit, we can merge as is.

@github-actions

This comment has been minimized.

@Akuli Akuli merged commit 5e5f3b4 into python:master Aug 2, 2022
@Akuli Akuli deleted the tk-incomplete branch August 2, 2022 19:10
@@ -1126,7 +1131,7 @@ class Canvas(Widget, XView, YView):
insertontime: int = ...,
insertwidth: _ScreenUnits = ...,
name: str = ...,
offset: Any = ..., # undocumented
offset: Incomplete = ..., # undocumented
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
offset: Incomplete = ..., # undocumented
offset=..., # undocumented

@@ -1165,7 +1170,7 @@ class Canvas(Widget, XView, YView):
insertofftime: int = ...,
insertontime: int = ...,
insertwidth: _ScreenUnits = ...,
offset: Any = ..., # undocumented
offset: Incomplete = ..., # undocumented
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
offset: Incomplete = ..., # undocumented
offset=..., # undocumented

def go(self, dir_or_file: Any = ..., pattern: str = ..., default: str = ..., key: Any | None = ...): ...
def quit(self, how: Any | None = ...) -> None: ...
how: Incomplete | None
def go(self, dir_or_file: Incomplete = ..., pattern: str = ..., default: str = ..., key: Incomplete | None = ...): ...
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def go(self, dir_or_file: Incomplete = ..., pattern: str = ..., default: str = ..., key: Incomplete | None = ...): ...
def go(self, dir_or_file=..., pattern: str = ..., default: str = ..., key: Incomplete | None = ...): ...

@@ -77,7 +78,7 @@ class Button(Widget):
default: Literal["normal", "active", "disabled"] = ...,
image: tkinter._ImageSpec = ...,
name: str = ...,
padding: Any = ..., # undocumented
padding: Incomplete = ..., # undocumented
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
padding: Incomplete = ..., # undocumented
padding=..., # undocumented

@@ -96,7 +97,7 @@ class Button(Widget):
cursor: tkinter._Cursor = ...,
default: Literal["normal", "active", "disabled"] = ...,
image: tkinter._ImageSpec = ...,
padding: Any = ...,
padding: Incomplete = ...,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
padding: Incomplete = ...,
padding=...,

@@ -546,7 +547,7 @@ class Notebook(Widget):
sticky: str = ..., # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
padding: tkinter._Padding = ...,
text: str = ...,
image: Any = ..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)
image: Incomplete = ..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
image: Incomplete = ..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)
image=..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)

@@ -662,7 +663,7 @@ class Radiobutton(Widget):
cursor: tkinter._Cursor = ...,
image: tkinter._ImageSpec = ...,
name: str = ...,
padding: Any = ..., # undocumented
padding: Incomplete = ..., # undocumented
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
padding: Incomplete = ..., # undocumented
padding=..., # undocumented

@@ -682,7 +683,7 @@ class Radiobutton(Widget):
compound: _TtkCompound = ...,
cursor: tkinter._Cursor = ...,
image: tkinter._ImageSpec = ...,
padding: Any = ...,
padding: Incomplete = ...,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
padding: Incomplete = ...,
padding=...,

@@ -869,7 +870,7 @@ class Spinbox(Entry):
invalidcommand: tkinter._EntryValidateCommand = ..., # undocumented
justify: Literal["left", "center", "right"] = ..., # undocumented
name: str = ...,
show: Any = ..., # undocumented
show: Incomplete = ..., # undocumented
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
show: Incomplete = ..., # undocumented
show=..., # undocumented

@@ -898,7 +899,7 @@ class Spinbox(Entry):
increment: float = ...,
invalidcommand: tkinter._EntryValidateCommand = ...,
justify: Literal["left", "center", "right"] = ...,
show: Any = ...,
show: Incomplete = ...,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
show: Incomplete = ...,
show=...,

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Akuli
Copy link
Collaborator Author

Akuli commented Aug 2, 2022

Don't know how I missed all of those :D I'll make a new PR.

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