|
1 |
| -# -*- coding: utf-8 -*- |
2 | 1 | # sage.doctest: needs sage.graphs sage.modules
|
3 | 2 | r"""
|
4 | 3 | Finite posets
|
|
287 | 286 | # ****************************************************************************
|
288 | 287 | from __future__ import annotations
|
289 | 288 | from collections import defaultdict
|
290 |
| -from copy import copy, deepcopy |
| 289 | +from copy import copy |
291 | 290 | from itertools import product
|
292 |
| -from typing import List |
293 | 291 |
|
294 | 292 | from sage.misc.cachefunc import cached_method
|
295 | 293 | from sage.misc.lazy_attribute import lazy_attribute
|
@@ -706,7 +704,7 @@ def Poset(data=None, element_labels=None, cover_relations=False, linear_extensio
|
706 | 704 | if data is None: # type 0
|
707 | 705 | D = DiGraph()
|
708 | 706 | elif isinstance(data, DiGraph): # type 4
|
709 |
| - D = deepcopy(data) |
| 707 | + D = data.copy(immutable=True) |
710 | 708 | elif isinstance(data, dict): # type 3: dictionary of upper covers
|
711 | 709 | D = DiGraph(data, format="dict_of_lists")
|
712 | 710 | elif isinstance(data, (list, tuple)): # types 1, 2, 3 (list/tuple)
|
@@ -1319,7 +1317,7 @@ def __call__(self, element):
|
1319 | 1317 | """
|
1320 | 1318 | if self._is_facade and element in self._element_to_vertex_dict:
|
1321 | 1319 | return element
|
1322 |
| - return super(FinitePoset, self).__call__(element) |
| 1320 | + return super().__call__(element) |
1323 | 1321 |
|
1324 | 1322 | def hasse_diagram(self):
|
1325 | 1323 | r"""
|
@@ -1403,7 +1401,7 @@ def _repr_(self):
|
1403 | 1401 | sage: M._repr_()
|
1404 | 1402 | 'Finite meet-semilattice containing 3 elements'
|
1405 | 1403 | """
|
1406 |
| - s = "%s containing %s elements" % (self._desc, self._hasse_diagram.order()) |
| 1404 | + s = f"{self._desc} containing {self._hasse_diagram.order()} elements" |
1407 | 1405 | if self._with_linear_extension:
|
1408 | 1406 | s += " with distinguished linear extension"
|
1409 | 1407 | return s
|
@@ -1444,13 +1442,13 @@ def _rich_repr_(self, display_manager, **kwds):
|
1444 | 1442 | return output
|
1445 | 1443 | # create text for non-graphical output
|
1446 | 1444 | if can_plot:
|
1447 |
| - text = '{0} (use the .plot() method to plot)'.format(repr(self)) |
| 1445 | + text = f'{repr(self)} (use the .plot() method to plot)' |
1448 | 1446 | else:
|
1449 | 1447 | text = repr(self)
|
1450 | 1448 | # latex() produces huge tikz environment, override
|
1451 | 1449 | tp = display_manager.types
|
1452 | 1450 | if (prefs.text == 'latex' and tp.OutputLatex in display_manager.supported_output()):
|
1453 |
| - return tp.OutputLatex(r'\text{{{0}}}'.format(text)) |
| 1451 | + return tp.OutputLatex(fr'\text{{{text}}}') |
1454 | 1452 | return tp.OutputPlainText(text)
|
1455 | 1453 |
|
1456 | 1454 | def __iter__(self):
|
@@ -2669,7 +2667,7 @@ def relations_number(self):
|
2669 | 2667 | # Maybe this should also be deprecated.
|
2670 | 2668 | intervals_number = relations_number
|
2671 | 2669 |
|
2672 |
| - def linear_intervals_count(self) -> List[int]: |
| 2670 | + def linear_intervals_count(self) -> list[int]: |
2673 | 2671 | """
|
2674 | 2672 | Return the enumeration of linear intervals w.r.t. their cardinality.
|
2675 | 2673 |
|
@@ -2799,10 +2797,10 @@ def is_incomparable_chain_free(self, m, n=None) -> bool:
|
2799 | 2797 | sage: Q = Poset({0:[2], 1:[2], 2:[3], 3:[4], 4:[]})
|
2800 | 2798 | sage: Q.is_incomparable_chain_free(2, 20/10)
|
2801 | 2799 | True
|
2802 |
| - sage: Q.is_incomparable_chain_free(2, pi) # needs sage.symbolic |
| 2800 | + sage: Q.is_incomparable_chain_free(2, 1.5) |
2803 | 2801 | Traceback (most recent call last):
|
2804 | 2802 | ...
|
2805 |
| - TypeError: 2 and pi must be integers |
| 2803 | + TypeError: 2 and 1.5... must be integers |
2806 | 2804 | sage: Q.is_incomparable_chain_free(2, -1)
|
2807 | 2805 | Traceback (most recent call last):
|
2808 | 2806 | ...
|
@@ -2850,9 +2848,9 @@ def is_incomparable_chain_free(self, m, n=None) -> bool:
|
2850 | 2848 | try:
|
2851 | 2849 | m, n = Integer(m), Integer(n)
|
2852 | 2850 | except TypeError:
|
2853 |
| - raise TypeError("%s and %s must be integers" % (m, n)) |
| 2851 | + raise TypeError(f"{m} and {n} must be integers") |
2854 | 2852 | if m < 1 or n < 1:
|
2855 |
| - raise ValueError("%s and %s must be positive integers" % (m, n)) |
| 2853 | + raise ValueError(f"{m} and {n} must be positive integers") |
2856 | 2854 | twochains = digraphs.TransitiveTournament(m) + digraphs.TransitiveTournament(n)
|
2857 | 2855 | if closure.subgraph_search(twochains, induced=True) is not None:
|
2858 | 2856 | return False
|
@@ -6348,7 +6346,7 @@ def graphviz_string(self, graph_string="graph", edge_string="--"):
|
6348 | 6346 | s += '"%s";' % v
|
6349 | 6347 | s += '\n'
|
6350 | 6348 | for u, v in self.cover_relations_iterator():
|
6351 |
| - s += '"%s"%s"%s";' % (v, edge_string, u) |
| 6349 | + s += f'"{v}"{edge_string}"{u}";' |
6352 | 6350 | s += "\n}"
|
6353 | 6351 | return s
|
6354 | 6352 |
|
@@ -8152,9 +8150,9 @@ def is_eulerian(self, k=None, certificate=False):
|
8152 | 8150 | try:
|
8153 | 8151 | k = Integer(k)
|
8154 | 8152 | except TypeError:
|
8155 |
| - raise TypeError("parameter 'k' must be an integer, not {0}".format(k)) |
| 8153 | + raise TypeError(f"parameter 'k' must be an integer, not {k}") |
8156 | 8154 | if k <= 0:
|
8157 |
| - raise ValueError("parameter 'k' must be positive, not {0}".format(k)) |
| 8155 | + raise ValueError(f"parameter 'k' must be positive, not {k}") |
8158 | 8156 |
|
8159 | 8157 | if not self.is_bounded():
|
8160 | 8158 | raise ValueError("the poset is not bounded")
|
@@ -8880,7 +8878,7 @@ def _macaulay2_init_(self, macaulay2=None):
|
8880 | 8878 | H = self._hasse_diagram
|
8881 | 8879 | txt = 'needsPackage "Posets";'
|
8882 | 8880 | txt += "poset({%s},{" % ','.join(str(x) for x in H)
|
8883 |
| - txt += ",".join("{%s,%s}" % (str(x), str(y)) |
| 8881 | + txt += ",".join(f"{{{str(x)},{str(y)}}}" |
8884 | 8882 | for x, y in H.cover_relations_iterator())
|
8885 | 8883 | return txt + "})"
|
8886 | 8884 |
|
@@ -8993,8 +8991,7 @@ def cardinality(self, from_iterator=False):
|
8993 | 8991 | 68275077901156, 4483130665195087]
|
8994 | 8992 | if not from_iterator and self._n < len(known_values):
|
8995 | 8993 | return Integer(known_values[self._n])
|
8996 |
| - else: |
8997 |
| - return super(FinitePosets_n, self).cardinality() |
| 8994 | + return super().cardinality() |
8998 | 8995 |
|
8999 | 8996 |
|
9000 | 8997 | # For backward compatibility of pickles of the former Posets()
|
|
0 commit comments