mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
Add options to tkinter widgets (#4363)
In tkinter, `widget['foo'] = bar` and `widget.config(foo=bar)` do the same thing, but they will now type-check differently: the `widget['foo'] = bar` syntax allows 'foo' to be any string (e.g. a variable, not necessarily a Literal) and bar to be any object, while `widget.config(foo=bar)` checks the existence of the option and the type of bar. Similarly, cget takes a Literal argument but __getitem__ takes a string.
Testing script can still be found at c42a72c53e
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -9,21 +9,10 @@ ITALIC: Literal["italic"]
|
||||
|
||||
def nametofont(name: str) -> Font: ...
|
||||
|
||||
# _TkinterSequence[T] represents a sequence that tkinter understands. It
|
||||
# differs from typing.Sequence[T]. For example, collections.deque a valid
|
||||
# Sequence but not a valid _TkinterSequence:
|
||||
#
|
||||
# >>> tkinter.Label(font=('Helvetica', 12, collections.deque(['bold'])))
|
||||
# Traceback (most recent call last):
|
||||
# ...
|
||||
# _tkinter.TclError: unknown font style "deque(['bold'])"
|
||||
_T = TypeVar("_T")
|
||||
_TkinterSequence = Union[List[_T], Tuple[_T, ...]]
|
||||
|
||||
# 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, str], Tuple[str, int, _TkinterSequence[str]],
|
||||
str, Font, Tuple[str, int], Tuple[str, int, str], Tuple[str, int, tkinter._TkinterSequence[str]],
|
||||
]
|
||||
|
||||
class _FontDict(TypedDict):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user