-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
add tkinter.font stub #4350
Conversation
stdlib/3/tkinter/font.pyi
Outdated
# 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]], |
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.
Maybe:
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]], |
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.
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'])"
stdlib/3/tkinter/font.pyi
Outdated
@overload | ||
def actual(self, option: None, *, displayof: Optional[tkinter.Misc] = ...) -> _FontDict: ... | ||
@overload | ||
def actual(self, *, displayof: Optional[tkinter.Misc] = ...) -> _FontDict: ... |
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.
I think technically these last two overloads should be:
@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
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.
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?
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.
Because it'd be the only overload where both parameters have default values.
What you've done also works :-)
fixes python/mypy#9157