Skip to content

Commit

Permalink
sagemathgh-38977: minor details in some pyx files in sets
Browse files Browse the repository at this point in the history
    
just fxing a few suggestions of pycodestyle there

### 📝 Checklist

- [x] The title is concise and informative.
- [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 and checked the documentation
preview.
    
URL: sagemath#38977
Reported by: Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Dec 5, 2024
2 parents 3969687 + a693333 commit 142adb0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
5 changes: 4 additions & 1 deletion src/sage/sets/family.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=Fa
sage: f = Family(list(range(1,27)), lambda i: chr(i+96))
sage: f
Finite family {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
Finite family {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g',
8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o',
16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w',
24: 'x', 25: 'y', 26: 'z'}
sage: f[2]
'b'
Expand Down
10 changes: 4 additions & 6 deletions src/sage/sets/finite_set_map_cy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,10 @@ cdef class FiniteSetEndoMap_N(FiniteSetMap_MN):
sage: F([1, 0, 2]) * F([2, 1, 0])
[1, 2, 0]
"""
assert(self._parent is other._parent), "Parent mismatch"
assert (self._parent is other._parent), "Parent mismatch"
if self._parent._action == "right":
return self._compose_internal_(other, self._parent)
else:
return other._compose_internal_(self, self._parent)
return other._compose_internal_(self, self._parent)

def __pow__(self, n, dummy):
"""
Expand Down Expand Up @@ -679,11 +678,10 @@ cdef class FiniteSetEndoMap_Set(FiniteSetMap_Set):
sage: g * f
map: a -> c, b -> c, c -> c
"""
assert(self._parent is other._parent), "Parent mismatch"
assert (self._parent is other._parent), "Parent mismatch"
if self._parent._action == "right":
return self._compose_internal_(other, self._parent)
else:
return other._compose_internal_(self, self._parent)
return other._compose_internal_(self, self._parent)

def __pow__(self, n, dummy):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/sage/sets/pythonclass.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Set of all objects of a given Python class
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2018 Jeroen Demeyer <J.Demeyer@UGent.be>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from cpython.object cimport Py_EQ, Py_NE
from sage.structure.richcmp cimport rich_to_bool
Expand Down
44 changes: 22 additions & 22 deletions src/sage/sets/recursively_enumerated_set.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ from collections import deque


def RecursivelyEnumeratedSet(seeds, successors, structure=None,
enumeration=None, max_depth=float("inf"), post_process=None,
facade=None, category=None):
enumeration=None, max_depth=float("inf"),
post_process=None,
facade=None, category=None):
r"""
Return a recursively enumerated set.
Expand Down Expand Up @@ -470,7 +471,7 @@ cdef class RecursivelyEnumeratedSet_generic(Parent):
A recursively enumerated set (breadth first search)
"""
assert enumeration in ['naive', 'depth', 'breadth'], \
"unknown enumeration(={})".format(enumeration)
"unknown enumeration(={})".format(enumeration)

self._seeds = seeds
self.successors = successors
Expand All @@ -480,7 +481,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent):
if post_process is not None:
self.post_process = post_process
self._graded_component = None
Parent.__init__(self, facade=facade, category=EnumeratedSets().or_subcategory(category))
Parent.__init__(self, facade=facade,
category=EnumeratedSets().or_subcategory(category))

def __reduce__(self):
r"""
Expand Down Expand Up @@ -1532,10 +1534,7 @@ def search_forest_iterator(roots, children, algorithm='depth'):
# (you ask the children for the last node you met). Setting
# position on 0 results in a breadth search (enumerate all the
# descendants of a node before going on to the next father)
if algorithm == 'depth':
position = -1
else:
position = 0
position = -1 if algorithm == 'depth' else 0

# Invariant:
# - for breadth first search: stack[i] contains an iterator over the nodes
Expand All @@ -1555,7 +1554,7 @@ def search_forest_iterator(roots, children, algorithm='depth'):
continue

yield node
stack.append( iter(children(node)) )
stack.append(iter(children(node)))


class RecursivelyEnumeratedSet_forest(Parent):
Expand Down Expand Up @@ -1742,8 +1741,8 @@ class RecursivelyEnumeratedSet_forest(Parent):
sage: loads(dumps(S))
An enumerated set with a forest structure
"""
def __init__(self, roots = None, children = None, post_process = None,
algorithm = 'depth', facade = None, category=None):
def __init__(self, roots=None, children=None, post_process=None,
algorithm='depth', facade=None, category=None):
r"""
TESTS::
Expand All @@ -1759,7 +1758,8 @@ class RecursivelyEnumeratedSet_forest(Parent):
if post_process is not None:
self.post_process = post_process
self._algorithm = algorithm
Parent.__init__(self, facade = facade, category = EnumeratedSets().or_subcategory(category))
Parent.__init__(self, facade=facade,
category=EnumeratedSets().or_subcategory(category))

__len__ = None

Expand Down Expand Up @@ -1833,7 +1833,7 @@ class RecursivelyEnumeratedSet_forest(Parent):
"""
iter = search_forest_iterator(self.roots(),
self.children,
algorithm = self._algorithm)
algorithm=self._algorithm)
if hasattr(self, "post_process"):
iter = _imap_and_filter_none(self.post_process, iter)
return iter
Expand Down Expand Up @@ -2016,7 +2016,7 @@ class RecursivelyEnumeratedSet_forest(Parent):
"""
stack = [iter(self.roots())]
while stack:
position = randint(0,len(stack)-1)
position = randint(0, len(stack) - 1)
try:
node = next(stack[position])
except StopIteration:
Expand All @@ -2025,12 +2025,12 @@ class RecursivelyEnumeratedSet_forest(Parent):

if node == elt:
return True
stack.append( iter(self.children(node)) )
stack.append(iter(self.children(node)))
return False

def map_reduce(self, map_function = None,
reduce_function = None,
reduce_init = None):
def map_reduce(self, map_function=None,
reduce_function=None,
reduce_init=None):
r"""
Apply a Map/Reduce algorithm on ``self``.
Expand Down Expand Up @@ -2084,7 +2084,7 @@ class RecursivelyEnumeratedSet_forest(Parent):
"""
import sage.parallel.map_reduce
return sage.parallel.map_reduce.RESetMapReduce(
forest = self,
map_function = map_function,
reduce_function = reduce_function,
reduce_init = reduce_init).run()
forest=self,
map_function=map_function,
reduce_function=reduce_function,
reduce_init=reduce_init).run()

0 comments on commit 142adb0

Please sign in to comment.