Skip to content

Commit 5d0d4bb

Browse files
author
Release Manager
committed
gh-39375: adding some annotations in polyhedral complex add some typing annotations in one file also some minor code changes ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #39375 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 0e3334e + 5a17f2c commit 5d0d4bb

File tree

1 file changed

+41
-42
lines changed

1 file changed

+41
-42
lines changed

src/sage/geometry/polyhedral_complex.py

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class PolyhedralComplex(GenericCellComplex):
269269
"""
270270
def __init__(self, maximal_cells=None, backend=None, maximality_check=True,
271271
face_to_face_check=False, is_mutable=True, is_immutable=False,
272-
ambient_dim=None):
272+
ambient_dim=None) -> None:
273273
r"""
274274
Define a PolyhedralComplex.
275275
@@ -341,7 +341,7 @@ def __init__(self, maximal_cells=None, backend=None, maximality_check=True,
341341
if not is_mutable or is_immutable:
342342
self.set_immutable()
343343

344-
def cells(self, subcomplex=None):
344+
def cells(self, subcomplex=None) -> dict:
345345
"""
346346
The cells of this polyhedral complex, in the form of a dictionary:
347347
the keys are integers, representing dimension, and the value
@@ -419,7 +419,7 @@ def cell_iterator(self, increasing=True):
419419
if d in cells:
420420
yield from cells[d]
421421

422-
def _n_cells_sorted(self, n, subcomplex=None):
422+
def _n_cells_sorted(self, n, subcomplex=None) -> list:
423423
"""
424424
Sorted list of cells of dimension ``n`` of this polyhedral complex.
425425
@@ -447,7 +447,7 @@ def _n_cells_sorted(self, n, subcomplex=None):
447447
return sorted(n_cells,
448448
key=lambda p: (p.vertices(), p.rays(), p.lines()))
449449

450-
def cells_sorted(self, subcomplex=None):
450+
def cells_sorted(self, subcomplex=None) -> list:
451451
"""
452452
The sorted list of the cells of this polyhedral complex
453453
in non-increasing dimensions.
@@ -469,10 +469,10 @@ def cells_sorted(self, subcomplex=None):
469469
"""
470470
cells = []
471471
for n in range(self._dim, -1, -1):
472-
cells += self._n_cells_sorted(n, subcomplex)
472+
cells.extend(self._n_cells_sorted(n, subcomplex))
473473
return cells
474474

475-
def maximal_cells(self):
475+
def maximal_cells(self) -> dict:
476476
"""
477477
The maximal cells of this polyhedral complex, in the form of a
478478
dictionary: the keys are integers, representing dimension, and the
@@ -546,7 +546,7 @@ def maximal_cell_iterator(self, increasing=False):
546546
if d in maximal_cells:
547547
yield from maximal_cells[d]
548548

549-
def n_maximal_cells(self, n):
549+
def n_maximal_cells(self, n) -> list:
550550
r"""
551551
List of maximal cells of dimension ``n`` of this polyhedral complex.
552552
@@ -584,10 +584,9 @@ def n_maximal_cells(self, n):
584584
"""
585585
if n in self.maximal_cells():
586586
return list(self.maximal_cells()[n])
587-
else:
588-
return []
587+
return []
589588

590-
def _n_maximal_cells_sorted(self, n):
589+
def _n_maximal_cells_sorted(self, n) -> list:
591590
"""
592591
Sorted list of maximal cells of dimension ``n`` of this polyhedral
593592
complex.
@@ -613,7 +612,7 @@ def _n_maximal_cells_sorted(self, n):
613612
return sorted(n_maximal_cells,
614613
key=lambda p: (p.vertices(), p.rays(), p.lines()))
615614

616-
def maximal_cells_sorted(self):
615+
def maximal_cells_sorted(self) -> list:
617616
"""
618617
Return the sorted list of the maximal cells of this polyhedral complex
619618
by non-increasing dimensions.
@@ -629,11 +628,11 @@ def maximal_cells_sorted(self):
629628
if self._maximal_cells_sorted is None:
630629
maximal_cells = []
631630
for n in range(self._dim, -1, -1):
632-
maximal_cells += self._n_maximal_cells_sorted(n)
631+
maximal_cells.extend(self._n_maximal_cells_sorted(n))
633632
self._maximal_cells_sorted = maximal_cells
634633
return self._maximal_cells_sorted
635634

636-
def is_maximal_cell(self, c):
635+
def is_maximal_cell(self, c) -> bool:
637636
"""
638637
Return whether the given cell ``c`` is a maximal cell of ``self``.
639638
@@ -664,7 +663,7 @@ def is_maximal_cell(self, c):
664663
# return (c in self.n_maximal_cells(d)) # use set instead of list
665664
return (d in self.maximal_cells()) and (c in self.maximal_cells()[d])
666665

667-
def is_cell(self, c):
666+
def is_cell(self, c) -> bool:
668667
"""
669668
Return whether the given cell ``c`` is a cell of ``self``.
670669
@@ -798,7 +797,7 @@ def plot(self, **kwds):
798797
g += cell.plot(**options)
799798
return g
800799

801-
def is_pure(self):
800+
def is_pure(self) -> bool:
802801
"""
803802
Test if this polyhedral complex is pure.
804803
@@ -828,10 +827,11 @@ def is_pure(self):
828827
"""
829828
return len(self._maximal_cells) == 1
830829

831-
def is_full_dimensional(self):
830+
def is_full_dimensional(self) -> bool:
832831
"""
833-
Return whether this polyhedral complex is full-dimensional:
834-
its dimension is equal to its ambient dimension.
832+
Return whether this polyhedral complex is full-dimensional.
833+
834+
This means that its dimension is equal to its ambient dimension.
835835
836836
EXAMPLES::
837837
@@ -846,7 +846,7 @@ def is_full_dimensional(self):
846846
"""
847847
return self._dim == self._ambient_dim
848848

849-
def __hash__(self):
849+
def __hash__(self) -> int:
850850
"""
851851
Compute the hash value of ``self`` using its ``maximal_cells_sorted``.
852852
@@ -871,7 +871,7 @@ def __hash__(self):
871871
"call set_immutable()")
872872
return hash(tuple(self.maximal_cells_sorted()))
873873

874-
def __eq__(self, right):
874+
def __eq__(self, right) -> bool:
875875
"""
876876
Two polyhedral complexes are equal iff their maximal cells are equal.
877877
@@ -889,7 +889,7 @@ def __eq__(self, right):
889889
return isinstance(right, PolyhedralComplex) and (
890890
self.maximal_cells_sorted() == right.maximal_cells_sorted())
891891

892-
def __ne__(self, right):
892+
def __ne__(self, right) -> bool:
893893
"""
894894
Return ``True`` if ``self`` and ``right`` are not equal.
895895
@@ -943,7 +943,7 @@ def _an_element_(self):
943943
from sage.categories.sets_cat import EmptySetError
944944
raise EmptySetError("the complex is empty")
945945

946-
def __contains__(self, x):
946+
def __contains__(self, x) -> bool:
947947
"""
948948
Return ``True`` if ``x`` is a polyhedron which is contained in this complex.
949949
@@ -1031,7 +1031,7 @@ def face_poset(self):
10311031
self.cells() # poset is obtained and cached in cells()
10321032
return self._face_poset
10331033

1034-
def is_subcomplex(self, other):
1034+
def is_subcomplex(self, other) -> bool:
10351035
r"""
10361036
Return whether ``self`` is a subcomplex of ``other``.
10371037
@@ -1059,7 +1059,7 @@ def is_subcomplex(self, other):
10591059
return False
10601060
return True
10611061

1062-
def is_compact(self):
1062+
def is_compact(self) -> bool:
10631063
"""
10641064
Test for boundedness of the polyhedral complex.
10651065
@@ -1128,7 +1128,7 @@ def graph(self):
11281128
d[v] = []
11291129
return Graph(d)
11301130

1131-
def is_connected(self):
1131+
def is_connected(self) -> bool:
11321132
"""
11331133
Return whether ``self`` is connected.
11341134
@@ -1252,7 +1252,7 @@ def connected_component(self, cell=None):
12521252
is_immutable=self._is_immutable,
12531253
backend=self._backend)
12541254

1255-
def connected_components(self):
1255+
def connected_components(self) -> list:
12561256
"""
12571257
Return the connected components of this polyhedral complex,
12581258
as list of (sub-)PolyhedralComplexes.
@@ -1303,11 +1303,10 @@ def connected_components(self):
13031303
lists_of_facets = [
13041304
[f for f in self.maximal_cell_iterator() if f in faces]
13051305
for faces in lists_of_faces]
1306-
results = [PolyhedralComplex(facets, maximality_check=False,
1307-
is_immutable=self._is_immutable,
1308-
backend=self._backend)
1309-
for facets in lists_of_facets]
1310-
return results
1306+
return [PolyhedralComplex(facets, maximality_check=False,
1307+
is_immutable=self._is_immutable,
1308+
backend=self._backend)
1309+
for facets in lists_of_facets]
13111310

13121311
def n_skeleton(self, n):
13131312
r"""
@@ -1445,7 +1444,7 @@ def boundary_subcomplex(self):
14451444
ans.set_immutable()
14461445
return ans
14471446

1448-
def relative_boundary_cells(self):
1447+
def relative_boundary_cells(self) -> list:
14491448
r"""
14501449
Return the maximal cells of the relative-boundary sub-complex.
14511450
@@ -1501,10 +1500,10 @@ def relative_boundary_cells(self):
15011500
faces = self.n_cells(d - 1)
15021501
ans = [face for face in faces if len(poset.upper_covers(face)) == 1]
15031502
if not self.is_pure():
1504-
ans += [p for p in poset.maximal_elements() if p.dimension() < d]
1503+
ans.extend(p for p in poset.maximal_elements() if p.dimension() < d)
15051504
return ans
15061505

1507-
def is_convex(self):
1506+
def is_convex(self) -> bool:
15081507
r"""
15091508
Return whether the set of points in ``self`` is a convex set.
15101509
@@ -1863,7 +1862,7 @@ def alexander_whitney(self, cell, dim_left):
18631862
# this function overrides the standard one for GenericCellComplex,
18641863
# this one counts the number of maximal cells, not all cells, to
18651864
# avoid calling and computing self.cells()
1866-
def _repr_(self):
1865+
def _repr_(self) -> str:
18671866
"""
18681867
Print representation.
18691868
@@ -1891,7 +1890,7 @@ def _repr_(self):
18911890
else:
18921891
return "Polyhedral complex with %s maximal cells" % num
18931892

1894-
def set_immutable(self):
1893+
def set_immutable(self) -> None:
18951894
"""
18961895
Make this polyhedral complex immutable.
18971896
@@ -1906,7 +1905,7 @@ def set_immutable(self):
19061905
"""
19071906
self._is_immutable = True
19081907

1909-
def is_mutable(self):
1908+
def is_mutable(self) -> bool:
19101909
"""
19111910
Return whether ``self`` is mutable.
19121911
@@ -1930,7 +1929,7 @@ def is_mutable(self):
19301929
"""
19311930
return not self._is_immutable
19321931

1933-
def is_immutable(self):
1932+
def is_immutable(self) -> bool:
19341933
"""
19351934
Return whether ``self`` is immutable.
19361935
@@ -2224,7 +2223,7 @@ def remove_cell(self, cell, check=False):
22242223
self._is_convex = None
22252224
self._polyhedron = None
22262225

2227-
def is_simplicial_complex(self):
2226+
def is_simplicial_complex(self) -> bool:
22282227
"""
22292228
Test if this polyhedral complex is a simplicial complex.
22302229
@@ -2243,7 +2242,7 @@ def is_simplicial_complex(self):
22432242
"""
22442243
return all(p.is_simplex() for p in self.maximal_cell_iterator())
22452244

2246-
def is_polyhedral_fan(self):
2245+
def is_polyhedral_fan(self) -> bool:
22472246
"""
22482247
Test if this polyhedral complex is a polyhedral fan.
22492248
@@ -2266,7 +2265,7 @@ def is_polyhedral_fan(self):
22662265
vector(p.vertices_list()[0]) == p.ambient_space().zero())
22672266
for p in self.maximal_cell_iterator())
22682267

2269-
def is_simplicial_fan(self):
2268+
def is_simplicial_fan(self) -> bool:
22702269
"""
22712270
Test if this polyhedral complex is a simplicial fan.
22722271
@@ -2470,7 +2469,7 @@ def subdivide(self, make_simplicial=False,
24702469
############################################################
24712470

24722471

2473-
def cells_list_to_cells_dict(cells_list):
2472+
def cells_list_to_cells_dict(cells_list) -> dict:
24742473
r"""
24752474
Helper function that returns the dictionary whose keys are the dimensions,
24762475
and the value associated to an integer `d` is the set of `d`-dimensional

0 commit comments

Comments
 (0)