Skip to content

Commit 7bdfb22

Browse files
author
Release Manager
committed
gh-40271: let shorthands be tuple and immutable as this is not something we want to change at runtime ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40271 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 7ced31e + 744bae2 commit 7bdfb22

File tree

11 files changed

+43
-39
lines changed

11 files changed

+43
-39
lines changed

src/sage/algebras/iwahori_hecke_algebra.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,16 +481,17 @@ def __init__(self, W, q1, q2, base_ring):
481481
# Attach the generic Hecke algebra and the basis change maps
482482
self._root = root
483483
self._generic_iwahori_hecke_algebra = IwahoriHeckeAlgebra_nonstandard(W)
484-
self._shorthands = ['C', 'Cp', 'T']
484+
self._shorthands = ('C', 'Cp', 'T')
485485
else:
486486
# Can we actually remove the bases C and Cp in this case?
487487
self._root = None
488-
self._shorthands = ['T']
488+
self._shorthands = ('T',)
489489

490490
# if 2 is a unit in the base ring then add th A and B bases
491491
try:
492492
base_ring(base_ring.one() / 2)
493-
self._shorthands.extend(['A', 'B'])
493+
sh = self._shorthands
494+
self._shorthands = (*sh, 'A', 'B')
494495
except (TypeError, ZeroDivisionError):
495496
pass
496497

@@ -2785,7 +2786,7 @@ def __init__(self, W):
27852786
self.u_inv = normalized_laurent_polynomial(base_ring, u**-1)
27862787
self.v_inv = normalized_laurent_polynomial(base_ring, v**-1)
27872788

2788-
self._shorthands = ['C', 'Cp', 'T']
2789+
self._shorthands = ('C', 'Cp', 'T')
27892790

27902791
if W.is_finite():
27912792
self._category = FiniteDimensionalAlgebrasWithBasis(base_ring)

src/sage/categories/examples/with_realizations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __init__(self, R, S):
197197
F_to_Out .register_as_coercion()
198198
(~F_to_Out).register_as_coercion()
199199

200-
_shorthands = ["F", "In", "Out"]
200+
_shorthands = ("F", "In", "Out")
201201

202202
def a_realization(self):
203203
r"""

src/sage/combinat/chas/fsym.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def __init__(self, base_ring):
495495
cat = HopfAlgebras(base_ring).Graded().Connected()
496496
Parent.__init__(self, base=base_ring, category=cat.WithRealizations())
497497

498-
_shorthands = ['G']
498+
_shorthands = ('G',)
499499

500500
def a_realization(self):
501501
r"""
@@ -790,7 +790,7 @@ class FreeSymmetricFunctions_Dual(UniqueRepresentation, Parent):
790790
sage: TF(F[[5, 1, 4, 2, 3]])
791791
F[135|2|4]
792792
"""
793-
def __init__(self, base_ring):
793+
def __init__(self, base_ring) -> None:
794794
r"""
795795
Initialize ``self``.
796796
@@ -802,7 +802,7 @@ def __init__(self, base_ring):
802802
cat = HopfAlgebras(base_ring).Graded().Connected()
803803
Parent.__init__(self, base=base_ring, category=cat.WithRealizations())
804804

805-
_shorthands = ['F']
805+
_shorthands = ('F',)
806806

807807
def a_realization(self):
808808
r"""

src/sage/combinat/chas/wqsym.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def a_realization(self):
498498
"""
499499
return self.M()
500500

501-
_shorthands = tuple(['M', 'X', 'C', 'Q', 'Phi'])
501+
_shorthands = ('M', 'X', 'C', 'Q', 'Phi')
502502

503503
# add options to class
504504
class options(GlobalOptions):

src/sage/combinat/fqsym.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def a_realization(self):
400400
"""
401401
return self.F()
402402

403-
_shorthands = tuple(['F', 'G', 'M'])
403+
_shorthands = ('F', 'G', 'M')
404404

405405
class F(FQSymBasis_abstract):
406406
r"""

src/sage/combinat/ncsf_qsym/ncsf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class NonCommutativeSymmetricFunctions(UniqueRepresentation, Parent):
403403
sage: TestSuite(complete).run()
404404
"""
405405

406-
def __init__(self, R):
406+
def __init__(self, R) -> None:
407407
r"""
408408
TESTS::
409409
@@ -445,7 +445,7 @@ def __init__(self, R):
445445
Phi.algebra_morphism(Phi._to_complete_on_generators,
446446
codomain=complete).register_as_coercion()
447447

448-
def _repr_(self): # could be taken care of by the category
448+
def _repr_(self) -> str: # could be taken care of by the category
449449
r"""
450450
EXAMPLES::
451451
@@ -472,7 +472,8 @@ def a_realization(self):
472472
"""
473473
return self.complete()
474474

475-
_shorthands = tuple(['S', 'R', 'L', 'Phi', 'Psi', 'nM', 'I', 'dQS', 'dYQS', 'ZL', 'ZR'])
475+
_shorthands = ('S', 'R', 'L', 'Phi', 'Psi', 'nM', 'I',
476+
'dQS', 'dYQS', 'ZL', 'ZR')
476477

477478
def dual(self):
478479
r"""

src/sage/combinat/ncsf_qsym/qsym.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ class QuasiSymmetricFunctions(UniqueRepresentation, Parent):
546546
True
547547
"""
548548

549-
def __init__(self, R):
549+
def __init__(self, R) -> None:
550550
"""
551551
The Hopf algebra of quasi-symmetric functions.
552552
See ``QuasiSymmetricFunctions`` for full documentation.
@@ -609,7 +609,7 @@ def __init__(self, R):
609609
codomain=Fundamental, category=category)
610610
Sym_s_to_F.register_as_coercion()
611611

612-
def _repr_(self):
612+
def _repr_(self) -> str:
613613
r"""
614614
EXAMPLES::
615615
@@ -632,7 +632,7 @@ def a_realization(self):
632632
"""
633633
return self.Monomial()
634634

635-
_shorthands = tuple(['M', 'F', 'E', 'dI', 'QS', 'YQS', 'phi', 'psi'])
635+
_shorthands = ('M', 'F', 'E', 'dI', 'QS', 'YQS', 'phi', 'psi')
636636

637637
def dual(self):
638638
r"""

src/sage/combinat/ncsym/ncsym.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class SymmetricFunctionsNonCommutingVariables(UniqueRepresentation, Parent):
293293
-4*p[] + 2*p[1] + p[2, 2]
294294
"""
295295

296-
def __init__(self, R):
296+
def __init__(self, R) -> None:
297297
"""
298298
Initialize ``self``.
299299
@@ -309,7 +309,7 @@ def __init__(self, R):
309309
category = GradedHopfAlgebras(R).Cocommutative()
310310
Parent.__init__(self, category=category.WithRealizations())
311311

312-
def _repr_(self):
312+
def _repr_(self) -> str:
313313
r"""
314314
EXAMPLES::
315315
@@ -331,7 +331,7 @@ def a_realization(self):
331331
"""
332332
return self.powersum()
333333

334-
_shorthands = tuple(['chi', 'cp', 'm', 'e', 'h', 'p', 'rho', 'x'])
334+
_shorthands = ('chi', 'cp', 'm', 'e', 'h', 'p', 'rho', 'x')
335335

336336
def dual(self):
337337
r"""

src/sage/combinat/sf/sf.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
Symmetric functions, with their multiple realizations
44
"""
5-
#*****************************************************************************
5+
# ***************************************************************************
66
# Copyright (C) 2007 Mike Hansen <[email protected]>
77
# 2009-2012 Jason Bandlow <[email protected]>
88
# 2012 Anne Schilling <anne at math.ucdavis.edu>
@@ -18,8 +18,8 @@
1818
#
1919
# The full text of the GPL is available at:
2020
#
21-
# http://www.gnu.org/licenses/
22-
#*****************************************************************************
21+
# https://www.gnu.org/licenses/
22+
# ***************************************************************************
2323
from sage.categories.fields import Fields
2424
from sage.categories.graded_hopf_algebras import GradedHopfAlgebras
2525
from sage.categories.principal_ideal_domains import PrincipalIdealDomains
@@ -885,7 +885,7 @@ def a_realization(self):
885885
"""
886886
return self.schur()
887887

888-
def _repr_(self): # could be taken care of by the category
888+
def _repr_(self): # could be taken care of by the category
889889
r"""
890890
Representation of ``self``
891891
@@ -907,7 +907,7 @@ def schur(self):
907907
"""
908908
return schur.SymmetricFunctionAlgebra_schur(self)
909909
s = schur
910-
Schur = schur # Currently needed by SymmetricFunctions.__init_extra__
910+
Schur = schur # Currently needed by SymmetricFunctions.__init_extra__
911911

912912
def powersum(self):
913913
r"""
@@ -920,7 +920,8 @@ def powersum(self):
920920
"""
921921
return powersum.SymmetricFunctionAlgebra_power(self)
922922
p = powersum
923-
power = powersum # Todo: get rid of this one when it won't be needed anymore
923+
power = powersum
924+
# Todo: get rid of the line above when it won't be needed anymore
924925

925926
def complete(self):
926927
r"""
@@ -1321,7 +1322,7 @@ def jack(self, t='t'):
13211322
sage: JQp = Sym.jack().Qp(); JQp
13221323
Symmetric Functions over Fraction Field of Univariate Polynomial Ring in t over Rational Field in the Jack Qp basis
13231324
"""
1324-
return jack.Jack( self, t=t )
1325+
return jack.Jack(self, t=t)
13251326

13261327
def abreu_nigro(self, q='q'):
13271328
"""
@@ -1345,7 +1346,7 @@ def zonal(self):
13451346
sage: SymmetricFunctions(QQ).zonal()
13461347
Symmetric Functions over Rational Field in the zonal basis
13471348
"""
1348-
return jack.SymmetricFunctionAlgebra_zonal( self )
1349+
return jack.SymmetricFunctionAlgebra_zonal(self)
13491350

13501351
def llt(self, k, t='t'):
13511352
"""
@@ -1369,7 +1370,7 @@ def llt(self, k, t='t'):
13691370
sage: llt3.hcospin()
13701371
Symmetric Functions over Fraction Field of Univariate Polynomial Ring in t over Rational Field in the level 3 LLT cospin basis
13711372
"""
1372-
return llt.LLT_class( self, k, t=t )
1373+
return llt.LLT_class(self, k, t=t)
13731374

13741375
def from_polynomial(self, f):
13751376
"""
@@ -1430,8 +1431,9 @@ def register_isomorphism(self, morphism, only_conversion=False):
14301431
else:
14311432
morphism.codomain().register_coercion(morphism)
14321433

1433-
_shorthands = ['e', 'f', 'h', 'm', 'p', 's']
1434-
_shorthands_all = sorted(_shorthands + ['ht', 'o', 'sp', 'st', 'w'])
1434+
# keep them sorted in alphabetic order
1435+
_shorthands = ('e', 'f', 'h', 'm', 'p', 's')
1436+
_shorthands_all = ('e', 'f', 'h', 'ht', 'm', 'o', 'p', 's', 'sp', 'st', 'w')
14351437

14361438
def __init_extra__(self):
14371439
"""
@@ -1452,11 +1454,11 @@ def __init_extra__(self):
14521454
sage: f(p.an_element()) == p.an_element()
14531455
True
14541456
"""
1455-
#powersum = self.powersum ()
1456-
#complete = self.complete ()
1457-
#elementary = self.elementary()
1458-
#schur = self.schur ()
1459-
#monomial = self.monomial ()
1457+
# powersum = self.powersum ()
1458+
# complete = self.complete ()
1459+
# elementary = self.elementary()
1460+
# schur = self.schur ()
1461+
# monomial = self.monomial ()
14601462

14611463
iso = self.register_isomorphism
14621464

@@ -1465,7 +1467,7 @@ def __init_extra__(self):
14651467
for (basis1_name, basis2_name) in conversion_functions:
14661468
basis1 = getattr(self, basis1_name)()
14671469
basis2 = getattr(self, basis2_name)()
1468-
on_basis = SymmetricaConversionOnBasis(t=conversion_functions[basis1_name,basis2_name], domain=basis1, codomain=basis2)
1470+
on_basis = SymmetricaConversionOnBasis(t=conversion_functions[basis1_name, basis2_name], domain=basis1, codomain=basis2)
14691471
from sage.rings.rational_field import RationalField
14701472
if basis2_name != "powersum" or self._base.has_coerce_map_from(RationalField()):
14711473
iso(basis1._module_morphism(on_basis, codomain=basis2))

src/sage/rings/polynomial/integer_valued_polynomials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class IntegerValuedPolynomialRing(UniqueRepresentation, Parent):
7575
...
7676
TypeError: argument R must be a commutative ring
7777
"""
78-
def __init__(self, R):
78+
def __init__(self, R) -> None:
7979
"""
8080
TESTS::
8181
@@ -88,7 +88,7 @@ def __init__(self, R):
8888
cat = Algebras(R).Commutative().WithBasis()
8989
Parent.__init__(self, base=R, category=cat.WithRealizations())
9090

91-
_shorthands = ["B", "S"]
91+
_shorthands = ("B", "S")
9292

9393
def _repr_(self) -> str:
9494
r"""

0 commit comments

Comments
 (0)