Skip to content

Commit 1b261dd

Browse files
Matthew HoroszowskiMatthew Horoszowski
authored andcommitted
lint: clear ruff debt + repair CI lint job's pyproject config
The new lint job in ci.yml (added in 1b53585) surfaces ruff debt that predates this branch — the project's previous CI never ran ruff. Most of it is mechanical: SIM* return-direct rewrites, C4* comprehension simplifications, I001 import sorts, F401 unused imports, UP015/UP032 modernizations. What was changed ---------------- - Auto-applied ruff --fix --unsafe-fixes (109 fixes). Reverted one unsafe fix in src/pptx/opc/serialized.py (SIM401 wanted blob_reader.get(uri, None), but _blob_reader is a Container, not a Mapping — has no .get()). Added a noqa with explanation. - Manually broke a long _GUID_RE line in tests/parts/test_custom_xml.py to fit the 100-char limit (E501). - pyproject.toml [tool.ruff.lint]: * Renamed TCH001 -> TC001 (ruff renamed the rule). * Removed PT005 from ignore list — ruff removed the rule. Verified -------- - ruff check src tests -> All checks passed - pytest tests/ -> 2986 passed - behave --stop -> 54 features, 981 scenarios, 0 failed Out of scope ------------ - ruff format would reformat 48 files. The lint job has 'continue-on-error: true' on the format check, so that stays advisory for now. A repo-wide format pass is a separate dedicated PR.
1 parent 1b53585 commit 1b261dd

44 files changed

Lines changed: 131 additions & 174 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ select = [
129129
"PLR0402", # -- Name compared with itself like `foo == foo` --
130130
"PT", # -- flake8-pytest-style --
131131
"SIM", # -- flake8-simplify --
132-
"TCH001", # -- detect typing-only imports not under `if TYPE_CHECKING` --
132+
"TC001", # -- detect typing-only imports not under `if TYPE_CHECKING` (formerly TCH001) --
133133
"UP015", # -- redundant `open()` mode parameter (like "r" is default) --
134134
"UP018", # -- Unnecessary {literal_type} call like `str("abc")`. (rewrite as a literal) --
135135
"UP032", # -- Use f-string instead of `.format()` call --
@@ -139,7 +139,6 @@ select = [
139139
ignore = [
140140
"COM812", # -- over aggressively insists on trailing commas where not desireable --
141141
"PT001", # -- wants empty parens on @pytest.fixture where not used (essentially always) --
142-
"PT005", # -- flags mock fixtures with names intentionally matching private method name --
143142
"PT011", # -- pytest.raises({exc}) too broad, use match param or more specific exception --
144143
"PT012", # -- pytest.raises() block should contain a single simple statement --
145144
"SIM117", # -- merge `with` statements for context managers that have same scope --

src/pptx/chart/axis.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ def has_major_gridlines(self):
5151
causes major gridlines to be displayed. Assigning |False| causes them
5252
to be removed.
5353
"""
54-
if self._element.majorGridlines is None:
55-
return False
56-
return True
54+
return self._element.majorGridlines is not None
5755

5856
@has_major_gridlines.setter
5957
def has_major_gridlines(self, value):
@@ -70,9 +68,7 @@ def has_minor_gridlines(self):
7068
causes minor gridlines to be displayed. Assigning |False| causes them
7169
to be removed.
7270
"""
73-
if self._element.minorGridlines is None:
74-
return False
75-
return True
71+
return self._element.minorGridlines is not None
7672

7773
@has_minor_gridlines.setter
7874
def has_minor_gridlines(self, value):
@@ -89,9 +85,7 @@ def has_title(self):
8985
causes an axis title to be added if not already present. Assigning
9086
|False| causes any existing title to be deleted.
9187
"""
92-
if self._element.title is None:
93-
return False
94-
return True
88+
return self._element.title is not None
9589

9690
@has_title.setter
9791
def has_title(self, value):
@@ -232,7 +226,7 @@ def visible(self):
232226
delete = self._element.delete_
233227
if delete is None:
234228
return False
235-
return False if delete.val else True
229+
return not delete.val
236230

237231
@visible.setter
238232
def visible(self, value):
@@ -267,9 +261,7 @@ def has_text_frame(self):
267261
already present. Assigning |False| causes any existing text frame to
268262
be removed along with any text contained in the text frame.
269263
"""
270-
if self._title.tx_rich is None:
271-
return False
272-
return True
264+
return self._title.tx_rich is not None
273265

274266
@has_text_frame.setter
275267
def has_text_frame(self, value):
@@ -441,9 +433,8 @@ def crosses(self):
441433
@crosses.setter
442434
def crosses(self, value):
443435
cross_xAx = self._cross_xAx
444-
if value == XL_AXIS_CROSSES.CUSTOM:
445-
if cross_xAx.crossesAt is not None:
446-
return
436+
if value == XL_AXIS_CROSSES.CUSTOM and cross_xAx.crossesAt is not None:
437+
return
447438
cross_xAx._remove_crosses()
448439
cross_xAx._remove_crossesAt()
449440
if value == XL_AXIS_CROSSES.CUSTOM:

src/pptx/chart/chart.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def has_title(self):
115115
settings.
116116
"""
117117
title = self._chartSpace.chart.title
118-
if title is None:
119-
return False
120-
return True
118+
return title is not None
121119

122120
@has_title.setter
123121
def has_title(self, value):
@@ -229,9 +227,7 @@ def has_text_frame(self):
229227
already present. Assigning |False| causes any existing text frame to
230228
be removed along with its text and formatting.
231229
"""
232-
if self._title.tx_rich is None:
233-
return False
234-
return True
230+
return self._title.tx_rich is not None
235231

236232
@has_text_frame.setter
237233
def has_text_frame(self, value):

src/pptx/chart/data.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ def are_dates(self):
391391
return False
392392
first_cat_label = self[0].label
393393
date_types = (datetime.date, datetime.datetime)
394-
if isinstance(first_cat_label, date_types):
395-
return True
396-
return False
394+
return bool(isinstance(first_cat_label, date_types))
397395

398396
@property
399397
def are_numeric(self):
@@ -414,9 +412,7 @@ def are_numeric(self):
414412
# the caller's input.
415413
first_cat_label = self[0].label
416414
numeric_types = (Number, datetime.date, datetime.datetime)
417-
if isinstance(first_cat_label, numeric_types):
418-
return True
419-
return False
415+
return bool(isinstance(first_cat_label, numeric_types))
420416

421417
@property
422418
def depth(self):

src/pptx/chart/datalabel.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ def has_text_frame(self):
177177
dLbl = self._dLbl
178178
if dLbl is None:
179179
return False
180-
if dLbl.xpath("c:tx/c:rich"):
181-
return True
182-
return False
180+
return bool(dLbl.xpath("c:tx/c:rich"))
183181

184182
@has_text_frame.setter
185183
def has_text_frame(self, value):

src/pptx/chart/plot.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ def _differentiate_line_chart_type(cls, plot):
340340

341341
def has_line_markers():
342342
matches = lineChart.xpath('c:ser/c:marker/c:symbol[@val="none"]')
343-
if matches:
344-
return False
345-
return True
343+
return not matches
346344

347345
if has_line_markers():
348346
return {
@@ -370,9 +368,7 @@ def _differentiate_radar_chart_type(cls, plot):
370368

371369
def noMarkers():
372370
matches = radarChart.xpath("c:ser/c:marker/c:symbol")
373-
if matches and matches[0].get("val") == "none":
374-
return True
375-
return False
371+
return bool(matches and matches[0].get("val") == "none")
376372

377373
if radar_style is None:
378374
return XL.RADAR
@@ -391,9 +387,7 @@ def noLine():
391387

392388
def noMarkers():
393389
symbols = scatterChart.xpath("c:ser/c:marker/c:symbol")
394-
if symbols and symbols[0].get("val") == "none":
395-
return True
396-
return False
390+
return bool(symbols and symbols[0].get("val") == "none")
397391

398392
scatter_style = scatterChart.xpath("c:scatterStyle")[0].get("val")
399393

src/pptx/chart/xmlwriter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def pt_xml(self, values):
140140
in the overall data point sequence of the chart and is started at
141141
*offset*.
142142
"""
143-
xml = (' <c:ptCount val="{pt_count}"/>\n').format(pt_count=len(values))
143+
xml = (f' <c:ptCount val="{len(values)}"/>\n')
144144

145145
pt_tmpl = (
146146
' <c:pt idx="{idx}">\n'

src/pptx/custom_xml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
from typing import TYPE_CHECKING, Iterable, Iterator, Literal, Sequence, Union, cast
1414

1515
from pptx.opc.constants import RELATIONSHIP_TYPE as RT
16-
from pptx.opc.package import Part
1716
from pptx.oxml import parse_xml
18-
from pptx.oxml.xmlchemy import BaseOxmlElement
1917
from pptx.parts.custom_xml import CustomXmlPart, XmlPayload
2018

2119
if TYPE_CHECKING:
20+
from pptx.opc.package import Part
21+
from pptx.oxml.xmlchemy import BaseOxmlElement
2222
from pptx.parts.presentation import PresentationPart
2323

2424

src/pptx/dml/effect.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def inherit(self):
100100
Assigning |False| causes the inheritance link to be broken and **no**
101101
effects to appear on the shape.
102102
"""
103-
if self._element.effectLst is None:
104-
return True
105-
return False
103+
return self._element.effectLst is None
106104

107105
@inherit.setter
108106
def inherit(self, value):

src/pptx/opc/serialized.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def rels_xml_for(self, partname: PackURI) -> bytes | None:
4444
instance.
4545
"""
4646
blob_reader, uri = self._blob_reader, partname.rels_uri
47-
return blob_reader[uri] if uri in blob_reader else None
47+
# `_blob_reader` is a Container, not a Mapping — it has no `.get()`,
48+
# so SIM401's "use blob_reader.get(uri, None)" rewrite would break.
49+
return blob_reader[uri] if uri in blob_reader else None # noqa: SIM401
4850

4951
@lazyproperty
5052
def _blob_reader(self) -> _PhysPkgReader:

0 commit comments

Comments
 (0)