Skip to content

Commit 892796a

Browse files
authored
Remove, move or # noqa more TypeAlias declarations (#8450)
1 parent 3e88363 commit 892796a

File tree

5 files changed

+30
-48
lines changed

5 files changed

+30
-48
lines changed

stdlib/email/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ from typing import IO, Union
55
from typing_extensions import TypeAlias
66

77
# Definitions imported by multiple submodules in typeshed
8-
_ParamType: TypeAlias = Union[str, tuple[str | None, str | None, str]]
9-
_ParamsType: TypeAlias = Union[str, None, tuple[str, str | None, str]]
8+
_ParamType: TypeAlias = Union[str, tuple[str | None, str | None, str]] # noqa: Y047
9+
_ParamsType: TypeAlias = Union[str, None, tuple[str, str | None, str]] # noqa: Y047
1010

1111
def message_from_string(s: str, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
1212
def message_from_bytes(s: bytes, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...

stdlib/lib2to3/pgen2/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ from typing import Any
55
from typing_extensions import TypeAlias
66

77
# This is imported in several lib2to3/pgen2 submodules
8-
_Convert: TypeAlias = Callable[[Grammar, _RawNode], Any]
8+
_Convert: TypeAlias = Callable[[Grammar, _RawNode], Any] # noqa: Y047

stdlib/multiprocessing/__init__.pyi

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from multiprocessing import context, reduction as reducer, synchronize
2+
from multiprocessing import context, reduction as reducer
33
from multiprocessing.context import (
44
AuthenticationError as AuthenticationError,
55
BufferTooShort as BufferTooShort,
@@ -10,12 +10,14 @@ from multiprocessing.context import (
1010
from multiprocessing.process import active_children as active_children, current_process as current_process
1111

1212
# These are technically functions that return instances of these Queue classes.
13-
# Using them as annotations is deprecated. Either use imports from
14-
# multiprocessing.queues or the aliases defined below. See #4266 for discussion.
13+
# The stub here doesn't reflect reality exactly --
14+
# while e.g. `multiprocessing.queues.Queue` is a class,
15+
# `multiprocessing.Queue` is actually a function at runtime.
16+
# Avoid using `multiprocessing.Queue` as a type annotation;
17+
# use imports from multiprocessing.queues instead.
18+
# See #4266 and #8450 for discussion.
1519
from multiprocessing.queues import JoinableQueue as JoinableQueue, Queue as Queue, SimpleQueue as SimpleQueue
1620
from multiprocessing.spawn import freeze_support as freeze_support
17-
from typing import TypeVar
18-
from typing_extensions import TypeAlias
1921

2022
if sys.version_info >= (3, 8):
2123
from multiprocessing.process import parent_process as parent_process
@@ -62,27 +64,6 @@ __all__ = [
6264
if sys.version_info >= (3, 8):
6365
__all__ += ["parent_process"]
6466

65-
# The following type aliases can be used to annotate the return values of
66-
# the corresponding functions. They are not defined at runtime.
67-
#
68-
# from multiprocessing import Lock
69-
# from typing import TYPE_CHECKING
70-
# if TYPE_CHECKING:
71-
# from multiprocessing import _LockType
72-
# lock: _LockType = Lock()
73-
74-
_T = TypeVar("_T")
75-
_QueueType: TypeAlias = Queue[_T]
76-
_SimpleQueueType: TypeAlias = SimpleQueue[_T]
77-
_JoinableQueueType: TypeAlias = JoinableQueue[_T]
78-
_BarrierType: TypeAlias = synchronize.Barrier
79-
_BoundedSemaphoreType: TypeAlias = synchronize.BoundedSemaphore
80-
_ConditionType: TypeAlias = synchronize.Condition
81-
_EventType: TypeAlias = synchronize.Event
82-
_LockType: TypeAlias = synchronize.Lock
83-
_RLockType: TypeAlias = synchronize.RLock
84-
_SemaphoreType: TypeAlias = synchronize.Semaphore
85-
8667
# These functions (really bound methods)
8768
# are all autogenerated at runtime here: https://github.com/python/cpython/blob/600c65c094b0b48704d8ec2416930648052ba715/Lib/multiprocessing/__init__.py#L23
8869
RawValue = context._default_context.RawValue

stdlib/tkinter/__init__.pyi

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ _EntryValidateCommand: TypeAlias = (
186186
) # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P']
187187
_GridIndex: TypeAlias = int | str | Literal["all"]
188188
_ImageSpec: TypeAlias = _Image | str # str can be from e.g. tkinter.image_names()
189-
_Padding: TypeAlias = Union[
190-
_ScreenUnits,
191-
tuple[_ScreenUnits],
192-
tuple[_ScreenUnits, _ScreenUnits],
193-
tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits],
194-
tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits],
195-
]
196189
_Relief: TypeAlias = Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] # manual page: Tk_GetRelief
197190
_ScreenUnits: TypeAlias = str | float # Often the right type instead of int. Manual page: Tk_GetPixels
198191
# -xscrollcommand and -yscrollcommand in 'options' manual page

stdlib/tkinter/ttk.pyi

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import tkinter
44
from _typeshed import Incomplete
55
from collections.abc import Callable
66
from tkinter.font import _FontDescription
7-
from typing import Any, overload
7+
from typing import Any, Union, overload
88
from typing_extensions import Literal, TypeAlias, TypedDict
99

1010
__all__ = [
@@ -38,6 +38,14 @@ __all__ = [
3838
def tclobjs_to_py(adict: dict[Any, Any]) -> dict[Any, Any]: ...
3939
def setup_master(master: Incomplete | None = ...): ...
4040

41+
_Padding: TypeAlias = Union[
42+
tkinter._ScreenUnits,
43+
tuple[tkinter._ScreenUnits],
44+
tuple[tkinter._ScreenUnits, tkinter._ScreenUnits],
45+
tuple[tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits],
46+
tuple[tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits],
47+
]
48+
4149
# from ttk_widget (aka ttk::widget) manual page, differs from tkinter._Compound
4250
_TtkCompound: TypeAlias = Literal["text", "image", tkinter._Compound]
4351

@@ -337,7 +345,7 @@ class Frame(Widget):
337345
cursor: tkinter._Cursor = ...,
338346
height: tkinter._ScreenUnits = ...,
339347
name: str = ...,
340-
padding: tkinter._Padding = ...,
348+
padding: _Padding = ...,
341349
relief: tkinter._Relief = ...,
342350
style: str = ...,
343351
takefocus: tkinter._TakeFocusValue = ...,
@@ -352,7 +360,7 @@ class Frame(Widget):
352360
borderwidth: tkinter._ScreenUnits = ...,
353361
cursor: tkinter._Cursor = ...,
354362
height: tkinter._ScreenUnits = ...,
355-
padding: tkinter._Padding = ...,
363+
padding: _Padding = ...,
356364
relief: tkinter._Relief = ...,
357365
style: str = ...,
358366
takefocus: tkinter._TakeFocusValue = ...,
@@ -379,7 +387,7 @@ class Label(Widget):
379387
image: tkinter._ImageSpec = ...,
380388
justify: Literal["left", "center", "right"] = ...,
381389
name: str = ...,
382-
padding: tkinter._Padding = ...,
390+
padding: _Padding = ...,
383391
relief: tkinter._Relief = ...,
384392
state: str = ...,
385393
style: str = ...,
@@ -405,7 +413,7 @@ class Label(Widget):
405413
foreground: tkinter._Color = ...,
406414
image: tkinter._ImageSpec = ...,
407415
justify: Literal["left", "center", "right"] = ...,
408-
padding: tkinter._Padding = ...,
416+
padding: _Padding = ...,
409417
relief: tkinter._Relief = ...,
410418
state: str = ...,
411419
style: str = ...,
@@ -433,7 +441,7 @@ class Labelframe(Widget):
433441
labelanchor: Literal["nw", "n", "ne", "en", "e", "es", "se", "s", "sw", "ws", "w", "wn"] = ...,
434442
labelwidget: tkinter.Misc = ...,
435443
name: str = ...,
436-
padding: tkinter._Padding = ...,
444+
padding: _Padding = ...,
437445
relief: tkinter._Relief = ..., # undocumented
438446
style: str = ...,
439447
takefocus: tkinter._TakeFocusValue = ...,
@@ -452,7 +460,7 @@ class Labelframe(Widget):
452460
height: tkinter._ScreenUnits = ...,
453461
labelanchor: Literal["nw", "n", "ne", "en", "e", "es", "se", "s", "sw", "ws", "w", "wn"] = ...,
454462
labelwidget: tkinter.Misc = ...,
455-
padding: tkinter._Padding = ...,
463+
padding: _Padding = ...,
456464
relief: tkinter._Relief = ...,
457465
style: str = ...,
458466
takefocus: tkinter._TakeFocusValue = ...,
@@ -519,7 +527,7 @@ class Notebook(Widget):
519527
cursor: tkinter._Cursor = ...,
520528
height: int = ...,
521529
name: str = ...,
522-
padding: tkinter._Padding = ...,
530+
padding: _Padding = ...,
523531
style: str = ...,
524532
takefocus: tkinter._TakeFocusValue = ...,
525533
width: int = ...,
@@ -531,7 +539,7 @@ class Notebook(Widget):
531539
*,
532540
cursor: tkinter._Cursor = ...,
533541
height: int = ...,
534-
padding: tkinter._Padding = ...,
542+
padding: _Padding = ...,
535543
style: str = ...,
536544
takefocus: tkinter._TakeFocusValue = ...,
537545
width: int = ...,
@@ -545,7 +553,7 @@ class Notebook(Widget):
545553
*,
546554
state: Literal["normal", "disabled", "hidden"] = ...,
547555
sticky: str = ..., # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
548-
padding: tkinter._Padding = ...,
556+
padding: _Padding = ...,
549557
text: str = ...,
550558
image=..., # Sequence of an image name, followed by zero or more (sequences of one or more state names followed by an image name)
551559
compound: tkinter._Compound = ...,
@@ -958,7 +966,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
958966
displaycolumns: str | list[str] | tuple[str, ...] | list[int] | tuple[int, ...] | Literal["#all"] = ...,
959967
height: int = ...,
960968
name: str = ...,
961-
padding: tkinter._Padding = ...,
969+
padding: _Padding = ...,
962970
selectmode: Literal["extended", "browse", "none"] = ...,
963971
# list/tuple of Literal don't actually work in mypy
964972
#
@@ -979,7 +987,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
979987
cursor: tkinter._Cursor = ...,
980988
displaycolumns: str | list[str] | tuple[str, ...] | list[int] | tuple[int, ...] | Literal["#all"] = ...,
981989
height: int = ...,
982-
padding: tkinter._Padding = ...,
990+
padding: _Padding = ...,
983991
selectmode: Literal["extended", "browse", "none"] = ...,
984992
show: Literal["tree", "headings", "tree headings", ""] | list[str] | tuple[str, ...] = ...,
985993
style: str = ...,

0 commit comments

Comments
 (0)