Skip to content

Commit c7ca6b3

Browse files
author
Release Manager
committed
gh-35940: fix and activate pycodestyle E252 <!-- ^^^^^ 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 activates the check for pycodestyle E252 warning `E252 missing whitespace around parameter equals` Also add this to vscode settings. And fix all other pycodestyle warnings in the unique modified file. <!-- 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: #35940 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 6e617a3 + 2116d3e commit c7ca6b3

File tree

3 files changed

+41
-44
lines changed

3 files changed

+41
-44
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"python.linting.enabled": true,
2828
// The following pycodestyle arguments are the same as the pycodestyle-minimal
2929
// tox environnment, see the file SAGE_ROOT/src/tox.ini
30-
"python.linting.pycodestyleArgs": ["--select= E111,E21,E222,E227,E251,E271,E303,E306,E401,E502,E701,E702,E703,E71,E72,W291,W293,W391,W605"],
30+
"python.linting.pycodestyleArgs": ["--select= E111,E21,E222,E227,E25,E271,E303,E306,E401,E502,E701,E702,E703,E71,E72,W291,W293,W391,W605"],
3131
"cSpell.words": [
3232
"furo",
3333
"Conda",

src/sage/manifolds/scalarfield.py

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from sage.tensor.modules.format_utilities import FormattedExpansion
5353
from sage.manifolds.chart import Chart
5454

55+
5556
class ScalarField(CommutativeAlgebraElement, ModuleElementWithMutability):
5657
r"""
5758
Scalar field on a topological manifold.
@@ -1133,15 +1134,19 @@ def __init__(self, parent, coord_expression=None, chart=None, name=None,
11331134
domain = parent._domain
11341135
self._domain = domain
11351136
self._manifold = domain.manifold()
1136-
self._is_zero = False # a priori, may be changed below or via
1137-
# method __bool__()
1137+
self._is_zero = False
1138+
# a priori, may be changed below or via
1139+
# method __bool__()
1140+
11381141
self._name = name
11391142
if latex_name is None:
11401143
self._latex_name = self._name
11411144
else:
11421145
self._latex_name = latex_name
1143-
self._express = {} # dict of coordinate expressions (ChartFunction
1144-
# instances) with charts as keys
1146+
self._express = {}
1147+
# dict of coordinate expressions (ChartFunction
1148+
# instances) with charts as keys
1149+
11451150
if coord_expression is not None:
11461151
if isinstance(coord_expression, dict):
11471152
for chart, expression in coord_expression.items():
@@ -1163,7 +1168,7 @@ def __init__(self, parent, coord_expression=None, chart=None, name=None,
11631168
self._express[chart] = chart.function(coord_expression)
11641169
self._init_derived() # initialization of derived quantities
11651170

1166-
####### Required methods for an algebra element (beside arithmetic) #######
1171+
# ### Required methods for an algebra element (beside arithmetic) ###
11671172

11681173
def __bool__(self):
11691174
r"""
@@ -1425,11 +1430,10 @@ def __ne__(self, other):
14251430
sage: g = M.scalar_field({X: x+y})
14261431
sage: f != g
14271432
False
1428-
14291433
"""
14301434
return not (self == other)
14311435

1432-
####### End of required methods for an algebra element (beside arithmetic) #######
1436+
# ## End of required methods for an algebra element (beside arithmetic) ##
14331437

14341438
def _init_derived(self):
14351439
r"""
@@ -1441,10 +1445,10 @@ def _init_derived(self):
14411445
sage: X.<x,y> = M.chart()
14421446
sage: f = M.scalar_field({X: x+y})
14431447
sage: f._init_derived()
1444-
14451448
"""
1446-
self._restrictions = {} # dict. of restrictions of self on subsets
1447-
# of self._domain, with the subsets as keys
1449+
self._restrictions = {}
1450+
# dict. of restrictions of self on subsets
1451+
# of self._domain, with the subsets as keys
14481452

14491453
def _del_derived(self):
14501454
r"""
@@ -1466,7 +1470,6 @@ def _del_derived(self):
14661470
sage: f._del_derived()
14671471
sage: f._restrictions # restrictions are derived quantities
14681472
{}
1469-
14701473
"""
14711474
self._restrictions.clear()
14721475

@@ -1486,7 +1489,6 @@ def _repr_(self):
14861489
'Scalar field f on the 2-dimensional topological manifold M'
14871490
sage: f
14881491
Scalar field f on the 2-dimensional topological manifold M
1489-
14901492
"""
14911493
description = "Scalar field"
14921494
if self._name is not None:
@@ -1513,12 +1515,10 @@ def _latex_(self):
15131515
'\\Phi'
15141516
sage: latex(f)
15151517
\Phi
1516-
15171518
"""
15181519
if self._latex_name is None:
15191520
return r'\text{' + str(self) + r'}'
1520-
else:
1521-
return self._latex_name
1521+
return self._latex_name
15221522

15231523
def set_name(self, name=None, latex_name=None):
15241524
r"""
@@ -1551,7 +1551,7 @@ def set_name(self, name=None, latex_name=None):
15511551
"""
15521552
if self.is_immutable():
15531553
raise ValueError("the name of an immutable element "
1554-
"cannot be changed")
1554+
"cannot be changed")
15551555
if name is not None:
15561556
self._name = name
15571557
if latex_name is None:
@@ -1787,7 +1787,7 @@ def coord_function(self, chart=None, from_chart=None):
17871787
found = True
17881788
if skchart not in self._express:
17891789
self._express[skchart] = skchart.function(
1790-
self._express[kchart].expr())
1790+
self._express[kchart].expr())
17911791
break
17921792
if found:
17931793
break
@@ -1796,8 +1796,8 @@ def coord_function(self, chart=None, from_chart=None):
17961796
"compute the expression in the {}".format(chart))
17971797
change = self._domain._coord_changes[(chart, from_chart)]
17981798
# old coordinates expressed in terms of the new ones:
1799-
coords = [ change._transf._functions[i].expr()
1800-
for i in range(self._manifold.dim()) ]
1799+
coords = [change._transf._functions[i].expr()
1800+
for i in range(self._manifold.dim())]
18011801
new_expr = self._express[from_chart](*coords)
18021802
self._express[chart] = chart.function(new_expr)
18031803
self._del_derived()
@@ -1921,7 +1921,7 @@ def set_expr(self, coord_expression, chart=None):
19211921
chart = self._domain._def_chart
19221922
self._express.clear()
19231923
self._express[chart] = chart.function(coord_expression)
1924-
self._is_zero = False # a priori
1924+
self._is_zero = False # a priori
19251925
self._del_derived()
19261926

19271927
def add_expr(self, coord_expression, chart=None):
@@ -2050,13 +2050,13 @@ def add_expr_by_continuation(self, chart, subdomain):
20502050
"""
20512051
if self.is_immutable():
20522052
raise ValueError("the expressions of an immutable element "
2053-
"cannot be changed")
2053+
"cannot be changed")
20542054
if not chart.domain().is_subset(self._domain):
20552055
raise ValueError("the chart is not defined on a subset of " +
20562056
"the scalar field domain")
20572057
schart = chart.restrict(subdomain)
20582058
self._express[chart] = chart.function(self.expr(schart))
2059-
self._is_zero = False # a priori
2059+
self._is_zero = False # a priori
20602060
self._del_derived()
20612061

20622062
def set_restriction(self, rst):
@@ -2101,7 +2101,7 @@ def set_restriction(self, rst):
21012101
self._express[chart.restrict(intersection)] = expr
21022102
self._is_zero = False # a priori
21032103

2104-
def display(self, chart: Optional[Chart]=None) -> FormattedExpansion:
2104+
def display(self, chart: Optional[Chart] = None) -> FormattedExpansion:
21052105
r"""
21062106
Display the expression of the scalar field in a given chart.
21072107
@@ -2155,11 +2155,12 @@ def display(self, chart: Optional[Chart]=None) -> FormattedExpansion:
21552155
on U: (x, y) ↦ y^2
21562156
sage: latex(f.display())
21572157
\begin{array}{llcl} f:& M & \longrightarrow & \mathbb{R} \\ \text{on}\ U : & \left(x, y\right) & \longmapsto & y^{2} \end{array}
2158-
21592158
"""
21602159
from sage.misc.latex import latex
21612160
from sage.typeset.unicode_characters import (unicode_to,
2162-
unicode_mapsto, unicode_mathbbR, unicode_mathbbC)
2161+
unicode_mapsto,
2162+
unicode_mathbbR,
2163+
unicode_mathbbC)
21632164
from sage.tensor.modules.format_utilities import FormattedExpansion
21642165

21652166
def _display_expression(self, chart, result):
@@ -2184,9 +2185,9 @@ def _display_expression(self, chart, result):
21842185
result._latex += r"\text{on}\ " + latex(chart.domain()) \
21852186
+ r": & "
21862187
result._txt += repr(coords) + " " + unicode_mapsto + " " \
2187-
+ repr(expression) + "\n"
2188+
+ repr(expression) + "\n"
21882189
result._latex += latex(coords) + r"& \longmapsto & " \
2189-
+ latex(expression) + r"\\"
2190+
+ latex(expression) + r"\\"
21902191

21912192
# Name of the base field:
21922193
field = self._domain.base_field()
@@ -2207,7 +2208,7 @@ def _display_expression(self, chart, result):
22072208
else:
22082209
symbol = self._name + ": "
22092210
result._txt = symbol + self._domain._name + " " + unicode_to + " " \
2210-
+ field_name + "\n"
2211+
+ field_name + "\n"
22112212
if self._latex_name is None:
22122213
symbol = ""
22132214
else:
@@ -2311,7 +2312,7 @@ def restrict(self, subdomain):
23112312
self._restrictions[subdomain] = rst.restrict(subdomain)
23122313
break
23132314
else:
2314-
# If this fails, the restriction must be created from scratch:
2315+
# If this fails, the restriction must be created from scratch:
23152316
sexpress = {}
23162317
for chart, funct in self._express.items():
23172318
for schart in subdomain.atlas():
@@ -2515,7 +2516,7 @@ def __call__(self, p, chart=None):
25152516
(-3, 7)
25162517
25172518
"""
2518-
#!# it should be "if p not in self_domain:" instead, but this test is
2519+
# ! # it should be "if p not in self_domain:" instead, but this test is
25192520
# skipped for efficiency
25202521
if p not in self._manifold:
25212522
raise ValueError("the {} ".format(p) + "does not belong " +
@@ -2657,7 +2658,7 @@ def __neg__(self):
26572658
result._latex_name = '-' + self._latex_name
26582659
return result
26592660

2660-
######### CommutativeAlgebraElement arithmetic operators ########
2661+
# ### CommutativeAlgebraElement arithmetic operators ###
26612662

26622663
def _add_(self, other):
26632664
r"""
@@ -2810,7 +2811,7 @@ def _mul_(self, other):
28102811
result._express[chart] = self._express[chart] * other._express[chart]
28112812
result._name = format_mul_txt(self._name, '*', other._name)
28122813
result._latex_name = format_mul_latex(self._latex_name, r' \cdot ',
2813-
other._latex_name)
2814+
other._latex_name)
28142815
return result
28152816

28162817
def _div_(self, other):
@@ -2843,10 +2844,9 @@ def _div_(self, other):
28432844
Traceback (most recent call last):
28442845
...
28452846
ZeroDivisionError: division of a scalar field by zero
2846-
28472847
"""
28482848
from sage.tensor.modules.format_utilities import format_mul_txt, \
2849-
format_mul_latex
2849+
format_mul_latex
28502850
# Trivial cases:
28512851
if other.is_trivial_zero():
28522852
raise ZeroDivisionError("division of a scalar field by zero")
@@ -2862,7 +2862,7 @@ def _div_(self, other):
28622862
result._express[chart] = self._express[chart] / other._express[chart]
28632863
result._name = format_mul_txt(self._name, '/', other._name)
28642864
result._latex_name = format_mul_latex(self._latex_name, '/',
2865-
other._latex_name)
2865+
other._latex_name)
28662866
return result
28672867

28682868
def _lmul_(self, number):
@@ -2966,7 +2966,7 @@ def _lmul_(self, number):
29662966
result._express[chart] = number * expr
29672967
return result
29682968

2969-
######### End of CommutativeAlgebraElement arithmetic operators ########
2969+
# ### End of CommutativeAlgebraElement arithmetic operators ###
29702970

29712971
def _function_name(self, func, func_latex, parentheses=True):
29722972
r"""
@@ -2985,20 +2985,17 @@ def _function_name(self, func, func_latex, parentheses=True):
29852985
sage: f = M.scalar_field({X: x+y}) # no name given to f
29862986
sage: f._function_name("cos", r"\cos")
29872987
(None, None)
2988-
29892988
"""
29902989
if self._name is None:
29912990
name = None
29922991
else:
29932992
name = func + "(" + self._name + ")"
29942993
if self._latex_name is None:
29952994
latex_name = None
2995+
elif parentheses:
2996+
latex_name = func_latex + r"\left(" + self._latex_name + r"\right)"
29962997
else:
2997-
if parentheses:
2998-
latex_name = func_latex + r"\left(" + self._latex_name + \
2999-
r"\right)"
3000-
else:
3001-
latex_name = func_latex + r"{" + self._latex_name + r"}"
2998+
latex_name = func_latex + r"{" + self._latex_name + r"}"
30022999
return name, latex_name
30033000

30043001
def exp(self):

src/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ description =
126126
# W605: invalid escape sequence ‘x’
127127
# See https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
128128
deps = pycodestyle
129-
commands = pycodestyle --select E111,E21,E222,E227,E251,E271,E303,E306,E401,E502,E701,E702,E703,E71,E72,W291,W293,W391,W605 {posargs:{toxinidir}/sage/}
129+
commands = pycodestyle --select E111,E21,E222,E227,E25,E271,E303,E306,E401,E502,E701,E702,E703,E71,E72,W291,W293,W391,W605 {posargs:{toxinidir}/sage/}
130130
pycodestyle --select E111,E271,E306,E401,E703,E712,E713,E714,E72,W29,W391,W605, --filename *.pyx {posargs:{toxinidir}/sage/}
131131
132132
[pycodestyle]

0 commit comments

Comments
 (0)