Skip to content

add tkinter.font stub #4350

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 9 commits into from
Jul 22, 2020
Merged

add tkinter.font stub #4350

merged 9 commits into from
Jul 22, 2020

Conversation

Akuli
Copy link
Collaborator

@Akuli Akuli commented Jul 21, 2020

# See 'FONT DESCRIPTIONS' in font man page. This uses str because Literal
# inside Tuple doesn't work.
_FontDescription = Union[
str, Font, Tuple[str, int], Tuple[str, int, Tuple[str, ...]], Tuple[str, int, List[str]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe:

Suggested change
str, Font, Tuple[str, int], Tuple[str, int, Tuple[str, ...]], Tuple[str, int, List[str]],
str, Font, Tuple[str, int], Tuple[str, int, Sequence[str]],

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tkinter does not accept arbitrary sequences. It only works with lists and tuples.

>>> tkinter.Label(font=('Helvetica', 12, collections.deque(['bold'])))
Traceback (most recent call last):
  ...
_tkinter.TclError: unknown font style "deque(['bold'])"

Comment on lines 72 to 75
@overload
def actual(self, option: None, *, displayof: Optional[tkinter.Misc] = ...) -> _FontDict: ...
@overload
def actual(self, *, displayof: Optional[tkinter.Misc] = ...) -> _FontDict: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think technically these last two overloads should be:

Suggested change
@overload
def actual(self, option: None, *, displayof: Optional[tkinter.Misc] = ...) -> _FontDict: ...
@overload
def actual(self, *, displayof: Optional[tkinter.Misc] = ...) -> _FontDict: ...
@overload
def actual(self, option: None = ..., displayof: Optional[tkinter.Misc] = ...) -> _FontDict: ...

since e.g, you could pass None, None positionally

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How would the type checker know that some_font.actual() is same as passing None for the option? Maybe just remove * from the actual(self, option: None, *, ...) overload?

Copy link
Collaborator

@hauntsaninja hauntsaninja Jul 22, 2020

Choose a reason for hiding this comment

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

Because it'd be the only overload where both parameters have default values.
What you've done also works :-)

@Akuli Akuli requested a review from hauntsaninja July 22, 2020 12:27
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.

mypy cannot find font module in tkinter
2 participants