Skip to content

Commit 6098e73

Browse files
author
Release Manager
committed
gh-35923: some pycodestyle fixes in sets/ <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> this fixes a few pycodestyle warnings in the `sets` folder <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35923 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 59ae8fd + fd79692 commit 6098e73

12 files changed

+152
-134
lines changed

src/sage/sets/cartesian_product.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from sage.categories.rings import Rings
2929
_Rings = Rings()
3030

31+
3132
class CartesianProduct(UniqueRepresentation, Parent):
3233
"""
3334
A class implementing a raw data structure for Cartesian products
@@ -79,7 +80,7 @@ def __init__(self, sets, category, flatten=False):
7980
self._sets = tuple(sets)
8081
Parent.__init__(self, category=category)
8182

82-
def _element_constructor_(self,x):
83+
def _element_constructor_(self, x):
8384
r"""
8485
Construct an element of a Cartesian product from a list or iterable
8586
@@ -141,7 +142,7 @@ def _repr_(self):
141142
sage: cartesian_product([QQ, ZZ, ZZ]) # indirect doctest
142143
The Cartesian product of (Rational Field, Integer Ring, Integer Ring)
143144
"""
144-
return "The Cartesian product of %s"%(self._sets,)
145+
return "The Cartesian product of %s" % (self._sets,)
145146

146147
def __contains__(self, x):
147148
"""
@@ -160,8 +161,8 @@ def __contains__(self, x):
160161
return True
161162
elif not isinstance(x, tuple):
162163
return False
163-
return ( len(x) == len(self._sets)
164-
and all(elt in self._sets[i] for i,elt in enumerate(x)) )
164+
return (len(x) == len(self._sets)
165+
and all(elt in self._sets[i] for i, elt in enumerate(x)))
165166

166167
def cartesian_factors(self):
167168
"""

src/sage/sets/condition_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def __init__(self, universe, *predicates, names=None, category=None):
204204
if isinstance(universe, Parent):
205205
facade = universe
206206
super().__init__(facade=facade, category=category,
207-
names=names, normalize=False) # names already normalized by classcall
207+
names=names, normalize=False) # names already normalized by classcall
208208

209209
def _first_ngens(self, n):
210210
r"""

src/sage/sets/disjoint_union_enumerated_sets.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
- Florent Hivert (2010-03): classcall related stuff.
88
- Florent Hivert (2010-12): fixed facade element construction.
99
"""
10-
#****************************************************************************
10+
# ***************************************************************************
1111
# Copyright (C) 2009 Florent Hivert <[email protected]>
1212
#
1313
# Distributed under the terms of the GNU General Public License (GPL)
14-
# http://www.gnu.org/licenses/
15-
#****************************************************************************
14+
# https://www.gnu.org/licenses/
15+
# ***************************************************************************
1616

1717
from sage.structure.element import Element
1818
from sage.structure.parent import Parent
@@ -25,6 +25,7 @@
2525
from sage.misc.lazy_attribute import lazy_attribute
2626
from sage.structure.unique_representation import UniqueRepresentation
2727

28+
2829
class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent):
2930
"""
3031
A class for disjoint unions of enumerated sets.
@@ -311,7 +312,7 @@ def _repr_(self):
311312
sage: U
312313
Disjoint union of Finite family {1: {1, 2, 3}, 2: {4, 5, 6}}
313314
"""
314-
return "Disjoint union of %s"%self._family
315+
return "Disjoint union of %s" % self._family
315316

316317
def _is_a(self, x):
317318
"""
@@ -336,7 +337,7 @@ def _is_a(self, x):
336337
else:
337338
from warnings import warn
338339
if self._family.cardinality() == Infinity:
339-
warn("%s is an infinite union\nThe default implementation of __contains__ can loop forever. Please overload it."%(self))
340+
warn("%s is an infinite union\nThe default implementation of __contains__ can loop forever. Please overload it." % (self))
340341
return any(x in a for a in self._family)
341342

342343
def __contains__(self, x):
@@ -404,7 +405,7 @@ def __iter__(self):
404405
if self._facade:
405406
yield el
406407
else:
407-
yield self.element_class(self, el) # Bypass correctness tests
408+
yield self.element_class(self, el) # Bypass correctness tests
408409

409410
def an_element(self):
410411
"""
@@ -515,7 +516,7 @@ def _element_constructor_default(self, el):
515516
if self._is_a(el):
516517
return self.element_class(self, el)
517518
else:
518-
raise ValueError("value %s does not belong to %s"%(el, self))
519+
raise ValueError("value %s does not belong to %s" % (el, self))
519520

520521
def _element_constructor_facade(self, el):
521522
"""
@@ -568,19 +569,19 @@ def _element_constructor_facade(self, el):
568569
try:
569570
return (el[0], P(el[1]))
570571
except Exception:
571-
raise ValueError("cannot coerce `%s` in the parent `%s`"%(el[1], P))
572+
raise ValueError("cannot coerce `%s` in the parent `%s`" % (el[1], P))
572573

573574
# Check first to see if the parent of el is in the family
574575
if (isinstance(el, Element) and self._facade_for is not True
575-
and el.parent() in self._facade_for):
576+
and el.parent() in self._facade_for):
576577
return el
577578

578579
for P in self._family:
579580
try:
580581
return P(el)
581582
except Exception:
582583
pass
583-
raise ValueError("cannot coerce `%s` in any parent in `%s`"%(el, self._family))
584+
raise ValueError("cannot coerce `%s` in any parent in `%s`" % (el, self._family))
584585

585586
@lazy_attribute
586587
def Element(self):

src/sage/sets/family.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Category of finite enumerated sets
2323
"""
2424

25-
#*****************************************************************************
25+
# ****************************************************************************
2626
# Copyright (C) 2008 Nicolas Thiery <nthiery at users.sf.net>,
2727
# Mike Hansen <[email protected]>,
2828
# Florent Hivert <[email protected]>
@@ -32,7 +32,7 @@
3232
# the Free Software Foundation, either version 2 of the License, or
3333
# (at your option) any later version.
3434
# https://www.gnu.org/licenses/
35-
#*****************************************************************************
35+
# ****************************************************************************
3636
import types
3737
from copy import copy
3838
from pprint import pformat, saferepr
@@ -48,8 +48,11 @@
4848
from sage.misc.lazy_import import lazy_import
4949
from sage.rings.integer import Integer
5050
from sage.misc.call import AttrCallObject
51+
from sage.sets.non_negative_integers import NonNegativeIntegers
52+
from sage.rings.infinity import Infinity
5153
lazy_import('sage.combinat.combinat', 'CombinatorialClass')
5254

55+
5356
def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=False, name=None):
5457
r"""
5558
A Family is an associative container which models a family
@@ -389,19 +392,19 @@ def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=Fa
389392
raise ValueError("lazy keyword only makes sense together with function keyword")
390393
if isinstance(indices, dict):
391394
return FiniteFamily(indices)
392-
if isinstance(indices, (list, tuple) ):
395+
if isinstance(indices, (list, tuple)):
393396
return TrivialFamily(indices)
394-
if isinstance(indices, (FiniteFamily, LazyFamily, TrivialFamily) ):
397+
if isinstance(indices, (FiniteFamily, LazyFamily, TrivialFamily)):
395398
return indices
396399
if (indices in EnumeratedSets()
397-
or isinstance(indices, CombinatorialClass)):
400+
or isinstance(indices, CombinatorialClass)):
398401
return EnumeratedFamily(indices)
399402
if isinstance(indices, Iterable):
400403
return TrivialFamily(indices)
401404

402405
raise NotImplementedError
403406
if (isinstance(indices, (list, tuple, FiniteEnumeratedSet))
404-
and not lazy):
407+
and not lazy):
405408
return FiniteFamily({i: function(i) for i in indices},
406409
keys=indices)
407410

@@ -528,9 +531,9 @@ def inverse_family(self):
528531
529532
sage: Family((3,4,7)).inverse_family()
530533
Finite family {3: 0, 4: 1, 7: 2}
531-
532534
"""
533-
return Family( dict( (self[k], k) for k in self.keys()) )
535+
return Family({self[k]: k for k in self.keys()})
536+
534537

535538
class FiniteFamily(AbstractFamily):
536539
r"""
@@ -654,7 +657,7 @@ def keys(self):
654657
['c', 'a', 'b']
655658
"""
656659
return (self._keys if self._keys is not None
657-
else list(self._dictionary))
660+
else list(self._dictionary))
658661

659662
def values(self):
660663
"""
@@ -709,7 +712,7 @@ def __eq__(self, other):
709712
False
710713
"""
711714
return (isinstance(other, self.__class__) and
712-
self._keys == other._keys and
715+
self._keys == other._keys and
713716
self._dictionary == other._dictionary)
714717

715718
def _repr_(self):
@@ -825,6 +828,7 @@ def __setstate__(self, state):
825828
"""
826829
self.__init__(state['dictionary'], keys=state.get("keys"))
827830

831+
828832
class FiniteFamilyWithHiddenKeys(FiniteFamily):
829833
r"""
830834
A close variant of :class:`FiniteFamily` where the family contains some
@@ -849,7 +853,7 @@ def __init__(self, dictionary, hidden_keys, hidden_function, keys=None):
849853

850854
# would be better to define as usual method
851855
# any better to unset the def of __getitem__ by FiniteFamily?
852-
#self.__getitem__ = lambda i: dictionary[i] if dictionary.has_key(i) else hidden_dictionary[i]
856+
# self.__getitem__ = lambda i: dictionary[i] if dictionary.has_key(i) else hidden_dictionary[i]
853857

854858
def __getitem__(self, i):
855859
"""
@@ -919,7 +923,7 @@ def __setstate__(self, d):
919923
"""
920924
hidden_function = d['hidden_function']
921925
if isinstance(hidden_function, str):
922-
# Let's assume that hidden_function is an unpickled function.
926+
# Let's assume that hidden_function is an unpickled function.
923927
from sage.misc.fpickle import unpickle_function
924928
hidden_function = unpickle_function(hidden_function)
925929
self.__init__(d['dictionary'], d['hidden_keys'], hidden_function)
@@ -1070,15 +1074,15 @@ def _repr_(self):
10701074
"""
10711075
if self.function_name is not None:
10721076
name = self.function_name + "(i)"
1073-
elif isinstance(self.function, type(lambda x:1)):
1077+
elif isinstance(self.function, type(lambda x: 1)):
10741078
name = self.function.__name__
1075-
name = name+"(i)"
1079+
name = name + "(i)"
10761080
else:
10771081
name = repr(self.function)
10781082
if isinstance(self.function, AttrCallObject):
1079-
name = "i"+name[1:]
1083+
name = "i" + name[1:]
10801084
else:
1081-
name = name+"(i)"
1085+
name = name + "(i)"
10821086
return "Lazy family ({})_{{i in {}}}".format(name, self.set)
10831087

10841088
def keys(self):
@@ -1217,7 +1221,7 @@ def __setstate__(self, d):
12171221
"""
12181222
function = d['function']
12191223
if isinstance(function, bytes):
1220-
# Let's assume that function is an unpickled function.
1224+
# Let's assume that function is an unpickled function.
12211225
from sage.misc.fpickle import unpickle_function
12221226
function = unpickle_function(function)
12231227

@@ -1295,7 +1299,7 @@ def _repr_(self):
12951299
sage: f = TrivialFamily([3,4,7]); f # indirect doctest
12961300
Family (3, 4, 7)
12971301
"""
1298-
return "Family %s"%((self._enumeration),)
1302+
return "Family %s" % ((self._enumeration),)
12991303

13001304
def keys(self):
13011305
"""
@@ -1399,9 +1403,6 @@ def map(self, f, name=None):
13991403
return Family(tuple([f(x) for x in self._enumeration]), name=name)
14001404

14011405

1402-
from sage.sets.non_negative_integers import NonNegativeIntegers
1403-
from sage.rings.infinity import Infinity
1404-
14051406
class EnumeratedFamily(LazyFamily):
14061407
r"""
14071408
:class:`EnumeratedFamily` turns an enumerated set ``c`` into a family
@@ -1468,8 +1469,8 @@ def __repr__(self):
14681469
"""
14691470
# return "Family ((%s)[i])_(i=1...%s)"%(self.enumset, self.enumset.cardinality())
14701471
if isinstance(self.enumset, FiniteEnumeratedSet):
1471-
return "Family %s"%(self.enumset._elements,)
1472-
return "Family (%s)"%(self.enumset)
1472+
return "Family %s" % (self.enumset._elements,)
1473+
return "Family (%s)" % (self.enumset)
14731474

14741475
def __contains__(self, x):
14751476
"""

src/sage/sets/finite_enumerated_set.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from sage.categories.sets_cat import EmptySetError
2424
from sage.rings.integer import Integer
2525

26-
#################################################################
26+
2727
class FiniteEnumeratedSet(UniqueRepresentation, Parent):
2828
"""
2929
A class for finite enumerated set.
@@ -271,7 +271,7 @@ def rank(self, x):
271271

272272
index = rank
273273

274-
def unrank(self,i):
274+
def unrank(self, i):
275275
r"""
276276
Return the element at position ``i``.
277277
@@ -402,5 +402,5 @@ def _element_constructor_(self, el):
402402
"""
403403
try:
404404
return self._elements[self.rank(el)]
405-
except (ValueError,KeyError):
406-
raise ValueError("%s not in %s"%(el, self))
405+
except (ValueError, KeyError):
406+
raise ValueError("%s not in %s" % (el, self))

0 commit comments

Comments
 (0)