Skip to content

Commit c4bebb1

Browse files
author
Release Manager
committed
gh-36854: various details in categories (ruff C4 and UP02) fixing a few `ruff` suggestions in `categories` (UP02 and C4 ruff codes) ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36854 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents dd54b42 + f5fef39 commit c4bebb1

30 files changed

+36
-51
lines changed

src/sage/categories/aperiodic_semigroups.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
r"""
32
Aperiodic semigroups
43
"""

src/sage/categories/cartesian_product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sage.categories.covariant_functorial_construction import CovariantFunctorialConstruction, CovariantConstructionCategory
1717
from sage.categories.pushout import MultivariateConstructionFunctor
1818

19-
native_python_containers = set([tuple, list, set, frozenset, range])
19+
native_python_containers = {tuple, list, set, frozenset, range}
2020

2121
class CartesianProductFunctor(CovariantFunctorialConstruction, MultivariateConstructionFunctor):
2222
"""

src/sage/categories/category.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,9 +2647,8 @@ def category_graph(categories=None):
26472647
categories = category_sample()
26482648
# Include all the super categories
26492649
# Get rid of join categories
2650-
categories = set(cat
2651-
for category in categories
2652-
for cat in category.all_super_categories(proper=isinstance(category, JoinCategory)))
2650+
categories = {cat for category in categories
2651+
for cat in category.all_super_categories(proper=isinstance(category, JoinCategory))}
26532652
g = graphs.digraph.DiGraph()
26542653
for cat in categories:
26552654
g.add_vertex(cat._repr_object_names())
@@ -2859,7 +2858,7 @@ def _make_named_class_key(self, name):
28592858
<class 'sage.categories.posets.Posets.element_class'>)
28602859
"""
28612860

2862-
_make_named_class_cache = dict()
2861+
_make_named_class_cache = {}
28632862

28642863
_cmp_key = _cmp_key_named
28652864

src/sage/categories/commutative_rings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def cyclotomic_cosets(self, q, cosets=None):
354354
if cosets is None:
355355
rest = set(self)
356356
else:
357-
rest = set(self(x) for x in cosets)
357+
rest = {self(x) for x in cosets}
358358

359359
orbits = []
360360
while rest:

src/sage/categories/covariant_functorial_construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def category_from_parents(self, parents):
145145
# But then this would impose that, for any constructor, the
146146
# category of the result does not depend on the order/repetition
147147
# of the categories of the parents
148-
return self.category_from_categories(tuple(set(parent.category() for parent in parents)))
148+
return self.category_from_categories(tuple({parent.category() for parent in parents}))
149149

150150
@cached_method
151151
def category_from_categories(self, categories):

src/sage/categories/coxeter_groups.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
r"""
32
Coxeter Groups
43
"""
@@ -633,8 +632,8 @@ class is not unique and we only obtain one such class.
633632
if not self.is_irreducible() or not self.is_well_generated():
634633
raise ValueError("this method is available for irreducible, well-generated complex reflection groups")
635634
from sage.combinat.permutation import Permutations
636-
return set(self.from_reduced_word(w)
637-
for w in Permutations(self.index_set()))
635+
return {self.from_reduced_word(w)
636+
for w in Permutations(self.index_set())}
638637

639638
def grassmannian_elements(self, side="right"):
640639
"""
@@ -1061,7 +1060,7 @@ def bruhat_interval_poset(self, x, y, facade=False):
10611060
return Poset([[x], []])
10621061
if not x.bruhat_le(y):
10631062
return Poset()
1064-
curlayer = set([y])
1063+
curlayer = {y}
10651064
d = {}
10661065
while curlayer:
10671066
nextlayer = set()
@@ -1263,8 +1262,8 @@ def _test_simple_projections(self, **options):
12631262
tester.assertEqual(opi[i](w), w.apply_simple_projection(i, side=side, length_increasing=False))
12641263
tester.assertTrue(pi[i](w).has_descent(i, side=side))
12651264
tester.assertFalse(opi[i](w).has_descent(i, side=side))
1266-
tester.assertEqual(set([pi[i](w), opi[i](w)]),
1267-
set([w, w.apply_simple_reflection(i, side=side)]))
1265+
tester.assertEqual({pi[i](w), opi[i](w)},
1266+
{w, w.apply_simple_reflection(i, side=side)})
12681267

12691268
def _test_has_descent(self, **options):
12701269
"""

src/sage/categories/crystals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ def __init__(self, parent, on_gens, cartan_type=None,
20822082
elif isinstance(on_gens, collections.abc.Sequence):
20832083
if len(self._gens) != len(on_gens):
20842084
raise ValueError("invalid generator images")
2085-
d = {x: y for x, y in zip(self._gens, on_gens)}
2085+
d = dict(zip(self._gens, on_gens))
20862086
f = lambda x: d[x]
20872087
else:
20882088
f = on_gens
@@ -2239,7 +2239,7 @@ def to_module_generator(self, x):
22392239
return self._path_mg_cache[x]
22402240

22412241
mg = set(self._path_mg_cache.keys())
2242-
visited = set([None, x])
2242+
visited = {None, x}
22432243
index_set = self._cartan_type.index_set()
22442244
todo = [x]
22452245
ef = [[]]

src/sage/categories/examples/commutative_additive_semigroups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ def __init__(self, parent, iterable):
164164
sage: x.value
165165
{'a': 2, 'b': 0, 'c': 1, 'd': 5}
166166
"""
167-
d = dict( (a,0) for a in parent.alphabet )
168-
for (a, c) in iterable:
167+
d = {a: 0 for a in parent.alphabet}
168+
for a, c in iterable:
169169
d[a] = c
170170
ElementWrapper.__init__(self, parent, d)
171171

src/sage/categories/examples/with_realizations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def supsets(self, set):
269269
[{1, 2, 3}, {2, 3}, {1, 2}, {2}]
270270
"""
271271
S = self.base_set()
272-
return list(S.difference(s) for s in Subsets(S.difference(set)))
272+
return [S.difference(s) for s in Subsets(S.difference(set))]
273273

274274
def _repr_(self):
275275
r"""

src/sage/categories/fields.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
r"""
32
Fields
43
"""

0 commit comments

Comments
 (0)