File tree Expand file tree Collapse file tree 6 files changed +8
-14
lines changed Expand file tree Collapse file tree 6 files changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -208,7 +208,7 @@ def _calculate_next_footnote_reference_id(self, p):
208
208
new_fr_id = 1
209
209
# If paragraph already contains footnotes
210
210
# append the new footnote and the end with the next reference id.
211
- if p .footnote_reference_ids is not None :
211
+ if len ( p .footnote_reference_ids ) > 0 :
212
212
new_fr_id = p .footnote_reference_ids [- 1 ] + 1
213
213
# Read the paragraphs containing footnotes and find where the
214
214
# new footnote will be. Keeping in mind that the footnotes are
@@ -224,7 +224,7 @@ def _calculate_next_footnote_reference_id(self, p):
224
224
has_passed_containing_para = True
225
225
continue
226
226
# Skip paragraphs without footnotes (they don't impact new id).
227
- if self .paragraphs [p_i ]._p .footnote_reference_ids is None :
227
+ if len ( self .paragraphs [p_i ]._p .footnote_reference_ids ) == 0 :
228
228
continue
229
229
# These footnotes are after the new footnote, so we increment them.
230
230
if not has_passed_containing_para :
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ def add_footnote(self, footnote_reference_id):
35
35
"""
36
36
elements = self ._element # for easy access
37
37
new_footnote = None
38
- if elements .get_by_id (footnote_reference_id ):
38
+ if elements .get_by_id (footnote_reference_id ) is not None :
39
39
# When adding a footnote it can be inserted
40
40
# in front of some other footnotes, so
41
41
# we need to sort footnotes by `footnote_reference_id`
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def add_footnote(self, footnote_reference_id):
24
24
return new_f
25
25
26
26
def get_by_id (self , id ):
27
- found = self .xpath ('w:footnote[@w:id="%s "]' % id )
27
+ found = self .xpath (f 'w:footnote[@w:id="{ id } "]' )
28
28
if not found :
29
29
return None
30
30
return found [0 ]
@@ -56,6 +56,4 @@ def paragraphs(self):
56
56
for child in self :
57
57
if child .tag == qn ('w:p' ):
58
58
paragraphs .append (child )
59
- if paragraphs == []:
60
- paragraphs = None
61
59
return paragraphs
Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ def footnote_number_format(self):
248
248
attribute is not present.
249
249
"""
250
250
fPr = self .footnotePr
251
- if fPr is None or fPr .numFmt :
251
+ if fPr is None or fPr .numFmt is None :
252
252
return None
253
253
return fPr .numFmt .val
254
254
@@ -266,7 +266,7 @@ def footnote_numbering_restart_location(self):
266
266
attribute is not present.
267
267
"""
268
268
fPr = self .footnotePr
269
- if fPr is None or fPr .numRestart :
269
+ if fPr is None or fPr .numRestart is None :
270
270
return None
271
271
return fPr .numRestart .val
272
272
@@ -291,7 +291,7 @@ def footnote_numbering_start_value(self):
291
291
attribute is not present.
292
292
"""
293
293
fPr = self .footnotePr
294
- if fPr is None or fPr .numStart :
294
+ if fPr is None or fPr .numStart is None :
295
295
return None
296
296
return fPr .numStart .val
297
297
Original file line number Diff line number Diff line change @@ -81,8 +81,6 @@ def footnote_reference_ids(self):
81
81
new_footnote_ids = run .footnote_reference_ids
82
82
if new_footnote_ids :
83
83
footnote_ids .extend (new_footnote_ids )
84
- if footnote_ids == []:
85
- footnote_ids = None
86
84
return footnote_ids
87
85
88
86
def set_sectPr (self , sectPr : CT_SectPr ):
Original file line number Diff line number Diff line change @@ -95,11 +95,9 @@ def footnotes(self):
95
95
Returns a list of |Footnote| instances that refers to the footnotes in this paragraph,
96
96
or |None| if none footnote is defined.
97
97
"""
98
+ footnote_list = []
98
99
reference_ids = self ._p .footnote_reference_ids
99
- if reference_ids == None :
100
- return None
101
100
footnotes = self ._parent ._parent .footnotes
102
- footnote_list = []
103
101
for ref_id in reference_ids :
104
102
footnote_list .append (footnotes [ref_id ])
105
103
return footnote_list
You can’t perform that action at this time.
0 commit comments