diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-03-08 11:39:56 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-19 06:31:40 +0100 |
| commit | 1282b5e4207440af659ef0e0e0c486fdfba8e7b7 (patch) | |
| tree | cda22b2570a8ee23b8e31877ed4965c6841d5db2 /django/forms/widgets.py | |
| parent | 4470c2405c8dbb529501f9d78753e2aa4e9653a2 (diff) | |
Fixed #32528 -- Replaced django.utils.topological_sort with graphlib.TopologicalSort().
graphlib.TopologicalSort() is available since Python 3.9.
Diffstat (limited to 'django/forms/widgets.py')
| -rw-r--r-- | django/forms/widgets.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index c5c531ada7..a1c67bb863 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -6,6 +6,7 @@ import copy import datetime import warnings from collections import defaultdict +from graphlib import CycleError, TopologicalSorter from itertools import chain from django.forms.utils import to_current_timezone @@ -17,7 +18,6 @@ from django.utils.formats import get_format from django.utils.html import format_html, html_safe from django.utils.regex_helper import _lazy_re_compile from django.utils.safestring import mark_safe -from django.utils.topological_sort import CyclicDependencyError, stable_topological_sort from django.utils.translation import gettext_lazy as _ from .renderers import get_default_renderer @@ -151,22 +151,22 @@ class Media: in a certain order. In JavaScript you may not be able to reference a global or in CSS you might want to override a style. """ - dependency_graph = defaultdict(set) + ts = TopologicalSorter() all_items = OrderedSet() for list_ in filter(None, lists): head = list_[0] # The first items depend on nothing but have to be part of the # dependency graph to be included in the result. - dependency_graph.setdefault(head, set()) + ts.add(head) for item in list_: all_items.add(item) # No self dependencies if head != item: - dependency_graph[item].add(head) + ts.add(item, head) head = item try: - return stable_topological_sort(all_items, dependency_graph) - except CyclicDependencyError: + return list(ts.static_order()) + except CycleError: warnings.warn( "Detected duplicate Media files in an opposite order: {}".format( ", ".join(repr(list_) for list_ in lists) |
