[Python-checkins] bpo-45359: Support TopologicalSorter type subscript (GH-28714)

asvetlov webhook-mailer at python.org
Wed Dec 8 13:53:09 EST 2021


https://github.com/python/cpython/commit/3cb9731b7e59b0df9a7a9ab6b7746a669958b693
commit: 3cb9731b7e59b0df9a7a9ab6b7746a669958b693
branch: main
author: Jacob Hayes <jacob.r.hayes at gmail.com>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2021-12-08T20:52:57+02:00
summary:

bpo-45359: Support TopologicalSorter type subscript (GH-28714)

* Support TopologicalSorter type subscript

* 📜🤖 Added by blurb_it.

* Add TopologicalSorter to GenericAlias tests

* Update Misc/NEWS.d/next/Library/2021-10-03-22-27-35.bpo-45359.LX_uxe.rst

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Batuhan Taskaya <isidentical at gmail.com>

files:
A Misc/NEWS.d/next/Library/2021-10-03-22-27-35.bpo-45359.LX_uxe.rst
M Lib/graphlib.py
M Lib/test/test_genericalias.py

diff --git a/Lib/graphlib.py b/Lib/graphlib.py
index 1c5d9a413c944..636545648e12d 100644
--- a/Lib/graphlib.py
+++ b/Lib/graphlib.py
@@ -1,3 +1,5 @@
+from types import GenericAlias
+
 __all__ = ["TopologicalSorter", "CycleError"]
 
 _NODE_OUT = -1
@@ -244,3 +246,5 @@ def static_order(self):
             node_group = self.get_ready()
             yield from node_group
             self.done(*node_group)
+
+    __class_getitem__ = classmethod(GenericAlias)
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 0daaff099a868..706cc5ea1af2f 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -13,6 +13,7 @@
 from contextvars import ContextVar, Token
 from dataclasses import Field
 from functools import partial, partialmethod, cached_property
+from graphlib import TopologicalSorter
 from mailbox import Mailbox, _PartialFile
 try:
     import ctypes
@@ -56,6 +57,7 @@ class BaseTest(unittest.TestCase):
                      OrderedDict, Counter, UserDict, UserList,
                      Pattern, Match,
                      partial, partialmethod, cached_property,
+                     TopologicalSorter,
                      AbstractContextManager, AbstractAsyncContextManager,
                      Awaitable, Coroutine,
                      AsyncIterable, AsyncIterator,
diff --git a/Misc/NEWS.d/next/Library/2021-10-03-22-27-35.bpo-45359.LX_uxe.rst b/Misc/NEWS.d/next/Library/2021-10-03-22-27-35.bpo-45359.LX_uxe.rst
new file mode 100644
index 0000000000000..6f5c97fde82a0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-10-03-22-27-35.bpo-45359.LX_uxe.rst
@@ -0,0 +1 @@
+Implement :pep:`585` for :class:`graphlib.TopologicalSorter`.
\ No newline at end of file



More information about the Python-checkins mailing list