Skip to content

Commit d509784

Browse files
committed
lint: fix C4xx comprehension errors
Also any Python 2 clean-up that was handy.
1 parent 163cfc1 commit d509784

File tree

19 files changed

+39
-74
lines changed

19 files changed

+39
-74
lines changed

features/steps/styles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ def then_I_can_access_a_style_by_style_id(context):
318318

319319
@then("I can iterate over its styles")
320320
def then_I_can_iterate_over_its_styles(context):
321-
styles = [s for s in context.document.styles]
321+
styles = list(context.document.styles)
322322
assert len(styles) > 0
323323
assert all(isinstance(s, BaseStyle) for s in styles)
324324

325325

326326
@then("I can iterate over the latent styles")
327327
def then_I_can_iterate_over_the_latent_styles(context):
328-
latent_styles = [ls for ls in context.latent_styles]
328+
latent_styles = list(context.latent_styles)
329329
assert len(latent_styles) == 137
330330
assert all(isinstance(ls, _LatentStyle) for ls in latent_styles)
331331

features/steps/tabstops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def then_I_can_access_a_tab_stop_by_index(context):
9696

9797
@then("I can iterate the TabStops object")
9898
def then_I_can_iterate_the_TabStops_object(context):
99-
items = [ts for ts in context.tab_stops]
99+
items = list(context.tab_stops)
100100
assert len(items) == 3
101101
assert all(isinstance(item, TabStop) for item in items)
102102

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ignore = [
6060
"COM812", # -- over-aggressively insists on trailing commas where not desired --
6161
]
6262
select = [
63-
# "C4", # -- flake8-comprehensions --
63+
"C4", # -- flake8-comprehensions --
6464
"COM", # -- flake8-commas --
6565
"E", # -- pycodestyle errors --
6666
"F", # -- pyflakes --

src/docx/document.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
# encoding: utf-8
2-
31
"""|Document| and closely related objects"""
42

5-
from __future__ import absolute_import, division, print_function, unicode_literals
6-
73
from docx.blkcntnr import BlockItemContainer
84
from docx.enum.section import WD_SECTION
95
from docx.enum.text import WD_BREAK

src/docx/enum/base.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# encoding: utf-8
2-
3-
"""
4-
Base classes and other objects used by enumerations
5-
"""
6-
7-
from __future__ import absolute_import, print_function
1+
"""Base classes and other objects used by enumerations."""
82

93
import sys
104
import textwrap
@@ -358,7 +352,7 @@ def _get_or_add_member_to_xml(clsdict):
358352
Add the enum -> xml value mapping to the enumeration class state
359353
"""
360354
if "_member_to_xml" not in clsdict:
361-
clsdict["_member_to_xml"] = dict()
355+
clsdict["_member_to_xml"] = {}
362356
return clsdict["_member_to_xml"]
363357

364358
@staticmethod
@@ -367,5 +361,5 @@ def _get_or_add_xml_to_member(clsdict):
367361
Add the xml -> enum value mapping to the enumeration class state
368362
"""
369363
if "_xml_to_member" not in clsdict:
370-
clsdict["_xml_to_member"] = dict()
364+
clsdict["_xml_to_member"] = {}
371365
return clsdict["_xml_to_member"]

src/docx/image/png.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function
4-
51
from .constants import MIME_TYPE, PNG_CHUNK_TYPE
62
from .exceptions import InvalidImageStreamError
73
from .helpers import BIG_ENDIAN, StreamReader
@@ -127,7 +123,7 @@ def from_stream(cls, stream):
127123
Return a |_Chunks| instance containing the PNG chunks in *stream*.
128124
"""
129125
chunk_parser = _ChunkParser.from_stream(stream)
130-
chunks = [chunk for chunk in chunk_parser.iter_chunks()]
126+
chunks = list(chunk_parser.iter_chunks())
131127
return cls(chunks)
132128

133129
@property

src/docx/image/tiff.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# encoding: utf-8
2-
3-
from __future__ import absolute_import, division, print_function
4-
51
from .constants import MIME_TYPE, TIFF_FLD, TIFF_TAG
62
from .helpers import BIG_ENDIAN, LITTLE_ENDIAN, StreamReader
73
from .image import BaseImageHeader
@@ -177,7 +173,7 @@ def from_stream(cls, stream, offset):
177173
*offset*.
178174
"""
179175
ifd_parser = _IfdParser(stream, offset)
180-
entries = dict((e.tag, e.value) for e in ifd_parser.iter_entries())
176+
entries = {e.tag: e.value for e in ifd_parser.iter_entries()}
181177
return cls(entries)
182178

183179
def get(self, tag_code, default=None):

src/docx/opc/package.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
# encoding: utf-8
2-
31
"""Objects that implement reading and writing OPC packages."""
42

5-
from __future__ import absolute_import, division, print_function, unicode_literals
6-
73
from docx.opc.constants import RELATIONSHIP_TYPE as RT
84
from docx.opc.packuri import PACKAGE_URI, PackURI
95
from docx.opc.part import PartFactory
@@ -70,7 +66,7 @@ def iter_parts(self):
7066
performing a depth-first traversal of the rels graph.
7167
"""
7268

73-
def walk_parts(source, visited=list()):
69+
def walk_parts(source, visited=[]):
7470
for rel in source.rels.values():
7571
if rel.is_external:
7672
continue
@@ -146,7 +142,7 @@ def parts(self):
146142
Return a list containing a reference to each of the parts in this
147143
package.
148144
"""
149-
return [part for part in self.iter_parts()]
145+
return list(self.iter_parts())
150146

151147
def relate_to(self, part, reltype):
152148
"""

src/docx/opc/pkgwriter.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
# encoding: utf-8
1+
"""Provides low-level, write-only API to serialized (OPC) package.
22
3+
OPC stands for Open Packaging Convention. This is e, essentially an implementation of
4+
OpcPackage.save().
35
"""
4-
Provides a low-level, write-only API to a serialized Open Packaging
5-
Convention (OPC) package, essentially an implementation of OpcPackage.save()
6-
"""
7-
8-
from __future__ import absolute_import
96

10-
from .constants import CONTENT_TYPE as CT
11-
from .oxml import CT_Types, serialize_part_xml
12-
from .packuri import CONTENT_TYPES_URI, PACKAGE_URI
13-
from .phys_pkg import PhysPkgWriter
14-
from .shared import CaseInsensitiveDict
15-
from .spec import default_content_types
7+
from docx.opc.constants import CONTENT_TYPE as CT
8+
from docx.opc.oxml import CT_Types, serialize_part_xml
9+
from docx.opc.packuri import CONTENT_TYPES_URI, PACKAGE_URI
10+
from docx.opc.phys_pkg import PhysPkgWriter
11+
from docx.opc.shared import CaseInsensitiveDict
12+
from docx.opc.spec import default_content_types
1613

1714

1815
class PackageWriter(object):
@@ -75,7 +72,7 @@ class _ContentTypesItem(object):
7572

7673
def __init__(self):
7774
self._defaults = CaseInsensitiveDict()
78-
self._overrides = dict()
75+
self._overrides = {}
7976

8077
@property
8178
def blob(self):

src/docx/oxml/ns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"xsi": "http://www.w3.org/2001/XMLSchema-instance",
2020
}
2121

22-
pfxmap = dict((value, key) for key, value in nsmap.items())
22+
pfxmap = {value: key for key, value in nsmap.items()}
2323

2424

2525
class NamespacePrefixedTag(str):
@@ -94,7 +94,7 @@ def nspfxmap(*nspfxs):
9494
*nspfxs*. Any number of namespace prefixes can be supplied, e.g.
9595
namespaces('a', 'r', 'p').
9696
"""
97-
return dict((pfx, nsmap[pfx]) for pfx in nspfxs)
97+
return {pfx: nsmap[pfx] for pfx in nspfxs}
9898

9999

100100
def qn(tag):

0 commit comments

Comments
 (0)