Skip to content

Commit 3475a8a

Browse files
author
Release Manager
committed
gh-39054: pep8 cleanup for structure/ pep8 cleanup for the directory `structure` ; nothing important ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #39054 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents b04f463 + d4cb8f1 commit 3475a8a

File tree

12 files changed

+55
-54
lines changed

12 files changed

+55
-54
lines changed

src/sage/structure/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# sage_setup: distribution = sagemath-objects
22
# Resolve a cyclic import
3-
import sage.structure.element
3+
import sage.structure.element

src/sage/structure/all.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
from sage.structure.proof import all as proof
2323

24-
from sage.misc.lazy_import import lazy_import
25-
lazy_import('sage.structure.formal_sum', ['FormalSums', 'FormalSum'])
26-
del lazy_import
27-
2824
from sage.structure.mutability import Mutability
2925

3026
from sage.structure.element_wrapper import ElementWrapper
27+
28+
from sage.misc.lazy_import import lazy_import
29+
lazy_import('sage.structure.formal_sum', ['FormalSums', 'FormalSum'])
30+
del lazy_import

src/sage/structure/formal_sum.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@
6565
#
6666
# https://www.gnu.org/licenses/
6767
# ****************************************************************************
68-
69-
from sage.misc.repr import repr_lincomb
7068
import operator
7169
from collections import OrderedDict
7270

71+
from sage.misc.persist import register_unpickle_override
72+
from sage.misc.repr import repr_lincomb
7373
from sage.modules.module import Module
7474
from sage.structure.element import ModuleElement
7575
from sage.structure.richcmp import richcmp
@@ -392,11 +392,14 @@ def _element_constructor_(self, x, check=True, reduce=True):
392392
else:
393393
x = x._data
394394
if isinstance(x, list):
395-
return self.element_class(x, check=check,reduce=reduce,parent=self)
395+
return self.element_class(x, check=check,
396+
reduce=reduce, parent=self)
396397
if x == 0:
397-
return self.element_class([], check=False, reduce=False, parent=self)
398+
return self.element_class([], check=False,
399+
reduce=False, parent=self)
398400
else:
399-
return self.element_class([(self.base_ring()(1), x)], check=False, reduce=False, parent=self)
401+
return self.element_class([(self.base_ring()(1), x)],
402+
check=False, reduce=False, parent=self)
400403

401404
def _coerce_map_from_(self, X):
402405
r"""
@@ -413,7 +416,7 @@ def _coerce_map_from_(self, X):
413416
From: Abelian Group of all Formal Finite Sums over Integer Ring
414417
To: Abelian Group of all Formal Finite Sums over Rational Field
415418
"""
416-
if isinstance(X,FormalSums):
419+
if isinstance(X, FormalSums):
417420
if self.base_ring().has_coerce_map_from(X.base_ring()):
418421
return True
419422
return False
@@ -475,13 +478,12 @@ def _an_element_(self, check=False, reduce=False):
475478
1/2
476479
"""
477480
return self.element_class([(self.base_ring().an_element(), 1)],
478-
check=check, reduce=reduce, parent=self)
481+
check=check, reduce=reduce, parent=self)
479482

480483

481484
formal_sums = FormalSums()
482485

483486
# Formal sums now derives from UniqueRepresentation, which makes the
484487
# factory function unnecessary. This is why the name was changed from
485488
# class FormalSums_generic to class FormalSums.
486-
from sage.misc.persist import register_unpickle_override
487489
register_unpickle_override('sage.structure.formal_sum', 'FormalSums_generic', FormalSums)

src/sage/structure/gens_py.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Pure python code for abstract base class for objects with generators
44
"""
55

6-
#*****************************************************************************
6+
# ****************************************************************************
77
# Copyright (C) 2005 William Stein <[email protected]>
88
#
99
# Distributed under the terms of the GNU General Public License (GPL)
@@ -15,8 +15,8 @@
1515
#
1616
# The full text of the GPL is available at:
1717
#
18-
# http://www.gnu.org/licenses/
19-
#*****************************************************************************
18+
# https://www.gnu.org/licenses/
19+
# ****************************************************************************
2020

2121

2222
def multiplicative_iterator(M):

src/sage/structure/indexed_generators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def _parse_names(self, m, use_latex):
316316
return names[m]
317317
except KeyError:
318318
return None
319-
else: # treat it like a list
319+
else: # treat it like a list
320320
try:
321321
i = self._indices.rank(m)
322322
except (AttributeError, TypeError, KeyError, ValueError):
@@ -458,7 +458,7 @@ def _repr_generator(self, m):
458458
return self.prefix() + left + (', '.join(repr(val) for val in m)) + right
459459
if not quotes and isinstance(m, str):
460460
return self.prefix() + left + m + right
461-
return self.prefix() + left + repr(m) + right # mind the (m), to accept a tuple for m
461+
return self.prefix() + left + repr(m) + right # mind the (m), to accept a tuple for m
462462

463463
def _ascii_art_generator(self, m):
464464
r"""

src/sage/structure/list_clone_timings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@
7373
cy_add1_mutable(e) : 625 loops, best of 3: 14.1 µs per loop
7474
cy_add1_with(e) : 625 loops, best of 3: 17.5 µs per loop
7575
"""
76-
#*****************************************************************************
76+
# ****************************************************************************
7777
# Copyright (C) 2009-2010 Florent Hivert <[email protected]>
7878
#
7979
# Distributed under the terms of the GNU General Public License (GPL)
80-
# http://www.gnu.org/licenses/
81-
#*****************************************************************************
80+
# https://www.gnu.org/licenses/
81+
# ****************************************************************************
8282

8383
from sage.structure.list_clone import ClonableArray
8484
from sage.structure.list_clone_demo import IncreasingArrays
@@ -116,7 +116,7 @@ def check(self):
116116

117117

118118
#####################################################################
119-
###### Timings functions ######
119+
# Timings functions #
120120
#####################################################################
121121
def add1_internal(bla):
122122
"""

src/sage/structure/proof/all.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# sage_setup: distribution = sagemath-objects
2+
from sage.structure.proof.proof import WithProof
23

34

45
def arithmetic(t=None):
@@ -240,6 +241,3 @@ def all(t=None):
240241
return _proof_prefs._require_proof.copy()
241242
for s in _proof_prefs._require_proof:
242243
_proof_prefs._require_proof[s] = bool(t)
243-
244-
245-
from sage.structure.proof.proof import WithProof

src/sage/structure/proof/proof.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ def get_flag(t=None, subsystem=None):
225225
False
226226
"""
227227
if t is None:
228-
if subsystem in ["arithmetic", "elliptic_curve", "linear_algebra", "number_field","polynomial"]:
228+
if subsystem in ["arithmetic", "elliptic_curve",
229+
"linear_algebra", "number_field", "polynomial"]:
229230
return _proof_prefs._require_proof[subsystem]
230231
else:
231232
return _proof_prefs._require_proof["other"]

src/sage/structure/sequence.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
# https://www.gnu.org/licenses/
7171
# ****************************************************************************
7272

73-
73+
from sage.misc.persist import register_unpickle_override
7474
import sage.structure.sage_object
7575
import sage.structure.coerce
7676

@@ -239,7 +239,7 @@ def Sequence(x, universe=None, check=True, immutable=False, cr=False, cr_str=Non
239239
# start the pairwise coercion
240240
for i in range(len(x) - 1):
241241
try:
242-
x[i], x[i+1] = sage.structure.element.canonical_coercion(x[i],x[i+1])
242+
x[i], x[i+1] = sage.structure.element.canonical_coercion(x[i], x[i+1])
243243
except TypeError:
244244
from sage.categories.objects import Objects
245245
universe = Objects()
@@ -515,16 +515,16 @@ def __getitem__(self, n):
515515
check=False,
516516
immutable=False,
517517
cr=self.__cr)
518-
else:
519-
return list.__getitem__(self,n)
518+
519+
return list.__getitem__(self, n)
520520

521521
# We have to define the *slice functions as long as Sage uses Python 2.*
522522
# otherwise the inherited *slice functions from list are called
523523
def __getslice__(self, i, j):
524-
return self.__getitem__(slice(i,j))
524+
return self.__getitem__(slice(i, j))
525525

526526
def __setslice__(self, i, j, value):
527-
return self.__setitem__(slice(i,j), value)
527+
return self.__setitem__(slice(i, j), value)
528528

529529
def append(self, x):
530530
"""
@@ -863,26 +863,25 @@ def __getattr__(self, name):
863863
sage: hash(S)
864864
34
865865
"""
866-
if name == "_Sequence_generic__cr" and hasattr(self,"_Sequence__cr"):
866+
if name == "_Sequence_generic__cr" and hasattr(self, "_Sequence__cr"):
867867
self.__cr = self._Sequence__cr
868868
return self.__cr
869-
elif name == "_Sequence_generic__cr_str" and hasattr(self,"_Sequence__cr_str"):
869+
if name == "_Sequence_generic__cr_str" and hasattr(self, "_Sequence__cr_str"):
870870
self.__cr_str = self._Sequence__cr_str
871871
return self.__cr_str
872-
elif name == "_Sequence_generic__immutable" and hasattr(self,"_Sequence__immutable"):
872+
if name == "_Sequence_generic__immutable" and hasattr(self, "_Sequence__immutable"):
873873
self.__immutable = self._Sequence__immutable
874874
return self.__immutable
875-
elif name == "_Sequence_generic__universe" and hasattr(self,"_Sequence__universe"):
875+
if name == "_Sequence_generic__universe" and hasattr(self, "_Sequence__universe"):
876876
self.__universe = self._Sequence__universe
877877
return self.__universe
878-
elif name == "_Sequence_generic__hash" and hasattr(self,"_Sequence__hash"):
878+
if name == "_Sequence_generic__hash" and hasattr(self, "_Sequence__hash"):
879879
self.__hash = self._Sequence__hash
880880
return self.__hash
881-
else:
882-
raise AttributeError("'Sequence_generic' object has no attribute '%s'" % name)
881+
882+
raise AttributeError("'Sequence_generic' object has no attribute '%s'" % name)
883883

884884

885885
seq = Sequence
886886

887-
from sage.misc.persist import register_unpickle_override
888887
register_unpickle_override('sage.structure.sequence', 'Sequence', Sequence_generic)

src/sage/structure/set_factories.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@
306306
307307
- Florent Hivert (2011-2012): initial revision
308308
"""
309-
#*****************************************************************************
309+
# ****************************************************************************
310310
# Copyright (C) 2012 Florent Hivert <florent.hivert at lri.fr>
311311
#
312312
# Distributed under the terms of the GNU General Public License (GPL)
313-
# http://www.gnu.org/licenses/
314-
#*****************************************************************************
313+
# https://www.gnu.org/licenses/
314+
# ****************************************************************************
315315

316316

317317
from sage.structure.sage_object import SageObject
@@ -846,7 +846,8 @@ def element_constructor_attributes(self, constraints):
846846
sage: pol.element_constructor_attributes(())
847847
{'_element_constructor_': <... 'tuple'>, '_parent_for': None}
848848
"""
849-
return {'_element_constructor_' : self._constructor, '_parent_for' : None}
849+
return {'_element_constructor_': self._constructor,
850+
'_parent_for': None}
850851

851852
def _repr_(self):
852853
r"""
@@ -1107,7 +1108,7 @@ def __contains__(self, x):
11071108
False
11081109
"""
11091110
if (isinstance(x, self.element_class) and
1110-
x.parent() == self._parent_for): # TODO: is_parent_of ???
1111+
x.parent() == self._parent_for): # TODO: is_parent_of ???
11111112
try:
11121113
self.check_element(x, True)
11131114
except ValueError:
@@ -1140,7 +1141,7 @@ def __call__(self, *args, **keywords):
11401141
# Ensure idempotence of element construction
11411142
if (len(args) == 1 and
11421143
isinstance(args[0], self.element_class) and
1143-
args[0].parent() == self._parent_for):
1144+
args[0].parent() == self._parent_for):
11441145
check = keywords.get("check", True)
11451146
if check:
11461147
self.check_element(args[0], check)

0 commit comments

Comments
 (0)