|
924 | 924 | # 2012--2015 Daniel Krenn < [email protected]> |
925 | 925 | # 2012--2015 Sara Kropf < [email protected]> |
926 | 926 | # |
927 | | -# Distributed under the terms of the GNU General Public License (GPL) |
928 | | -# as published by the Free Software Foundation; either version 2 of |
929 | | -# the License, or (at your option) any later version. |
930 | | -# https://www.gnu.org/licenses/ |
| 927 | +# This program is free software: you can redistribute it and/or modify |
| 928 | +# it under the terms of the GNU General Public License as published by |
| 929 | +# the Free Software Foundation, either version 2 of the License, or |
| 930 | +# (at your option) any later version. |
| 931 | +# https://www.gnu.org/licenses/ |
931 | 932 | # **************************************************************************** |
932 | | -from __future__ import print_function |
933 | 933 |
|
934 | 934 | from IPython.lib.pretty import pretty |
935 | | -import collections |
936 | 935 | import itertools |
| 936 | +from collections import defaultdict, deque, namedtuple, OrderedDict |
| 937 | +from collections.abc import Iterator |
937 | 938 | from copy import copy, deepcopy |
938 | 939 |
|
939 | 940 | from sage.calculus.var import var |
@@ -964,13 +965,13 @@ def full_group_by(l, key=lambda x: x): |
964 | 965 | A list of pairs ``(k, elements)`` such that ``key(e)=k`` for all |
965 | 966 | ``e`` in ``elements``. |
966 | 967 |
|
967 | | - This is similar to ``itertools.groupby`` except that lists are |
| 968 | + This is similar to :func:`itertools.groupby` except that lists are |
968 | 969 | returned instead of iterables and no prior sorting is required. |
969 | 970 |
|
970 | 971 | We do not require |
971 | 972 |
|
972 | 973 | - that the keys are sortable (in contrast to the |
973 | | - approach via ``sorted`` and ``itertools.groupby``) and |
| 974 | + approach via :func:`sorted` and :func:`itertools.groupby`) and |
974 | 975 | - that the keys are hashable (in contrast to the |
975 | 976 | implementation proposed in `<https://stackoverflow.com/a/15250161>`_). |
976 | 977 |
|
@@ -998,13 +999,13 @@ def full_group_by(l, key=lambda x: x): |
998 | 999 | 1/x [1] |
999 | 1000 | 2/x [2] |
1000 | 1001 |
|
1001 | | - Note that the behavior is different from ``itertools.groupby`` |
| 1002 | + Note that the behavior is different from :func:`itertools.groupby` |
1002 | 1003 | because neither `1/x<2/x` nor `2/x<1/x` does hold. |
1003 | 1004 |
|
1004 | 1005 | Here, the result ``r`` has been sorted in order to guarantee a |
1005 | 1006 | consistent order for the doctest suite. |
1006 | 1007 | """ |
1007 | | - elements = collections.defaultdict(list) |
| 1008 | + elements = defaultdict(list) |
1008 | 1009 | original_keys = {} |
1009 | 1010 | for item in l: |
1010 | 1011 | k = key(item) |
@@ -4924,7 +4925,7 @@ def key_function(s): |
4924 | 4925 | # transitions have to be sorted anyway, the performance |
4925 | 4926 | # penalty should be bearable; nevertheless, this is only |
4926 | 4927 | # required for doctests. |
4927 | | - adjacent = collections.OrderedDict( |
| 4928 | + adjacent = OrderedDict( |
4928 | 4929 | (pair, list(transitions)) |
4929 | 4930 | for pair, transitions in |
4930 | 4931 | itertools.groupby( |
@@ -13143,7 +13144,7 @@ def __init__(self, tape_cache_manager, tape, tape_ended, |
13143 | 13144 |
|
13144 | 13145 | self.tape_cache_manager = tape_cache_manager |
13145 | 13146 | self.tape_cache_manager.append(self) |
13146 | | - self.cache = tuple(collections.deque() for _ in self.tape) |
| 13147 | + self.cache = tuple(deque() for _ in self.tape) |
13147 | 13148 |
|
13148 | 13149 | def _repr_(self): |
13149 | 13150 | """ |
@@ -13927,8 +13928,7 @@ def is_FSMProcessIterator(PI): |
13927 | 13928 | # **************************************************************************** |
13928 | 13929 |
|
13929 | 13930 |
|
13930 | | -class FSMProcessIterator(SageObject, |
13931 | | - collections.Iterator): |
| 13931 | +class FSMProcessIterator(SageObject, Iterator): |
13932 | 13932 | """ |
13933 | 13933 | This class takes an input, feeds it into a finite state machine |
13934 | 13934 | (automaton or transducer, in particular), tests whether this was |
@@ -14215,7 +14215,7 @@ def __repr__(self): |
14215 | 14215 | return result |
14216 | 14216 |
|
14217 | 14217 |
|
14218 | | - FinishedBranch = collections.namedtuple('Branch', 'accept, state, output') |
| 14218 | + FinishedBranch = namedtuple('Branch', 'accept, state, output') |
14219 | 14219 | r""" |
14220 | 14220 | A :func:`named tuple <collections.namedtuple>` representing the |
14221 | 14221 | attributes of a branch, once |
@@ -14311,7 +14311,7 @@ def __init__(self, fsm, |
14311 | 14311 | self._finished_ = [] # contains (accept, state, output) |
14312 | 14312 |
|
14313 | 14313 |
|
14314 | | - _branch_ = collections.namedtuple('Branch', 'tape_cache, outputs') |
| 14314 | + _branch_ = namedtuple('Branch', 'tape_cache, outputs') |
14315 | 14315 | r""" |
14316 | 14316 | A :func:`named tuple <collections.namedtuple>` representing the |
14317 | 14317 | attributes of a branch at a particular state during processing. |
|
0 commit comments