Skip to content

Commit 10d214d

Browse files
Apply ruff/flake8-import-conventions rule ICN001
ICN001 `xml.etree.ElementTree` should be imported as `ET`
1 parent 1a3e22b commit 10d214d

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

asv/feed.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import datetime
77
import hashlib
8-
import xml.etree.ElementTree as etree
8+
import xml.etree.ElementTree as ET
99

1010
from . import util
1111

@@ -50,7 +50,7 @@ def __init__(self, title, updated, link=None, content=None, id_context=None, id_
5050
self.id_date = id_date
5151

5252
def get_atom(self, id_prefix, language):
53-
item = etree.Element(ATOM_NS + 'entry')
53+
item = ET.Element(f'{ATOM_NS}entry')
5454

5555
id_context = ["entry"]
5656
if self.id_context is None:
@@ -63,29 +63,29 @@ def get_atom(self, id_prefix, language):
6363
else:
6464
id_date = self.id_date
6565

66-
el = etree.Element(ATOM_NS + 'id')
66+
el = ET.Element(f'{ATOM_NS}id')
6767
el.text = _get_id(id_prefix, id_date, id_context)
6868
item.append(el)
6969

70-
el = etree.Element(ATOM_NS + 'title')
71-
el.attrib[XML_NS + 'lang'] = language
70+
el = ET.Element(f'{ATOM_NS}title')
71+
el.attrib[f'{XML_NS}lang'] = language
7272
el.text = self.title
7373
item.append(el)
7474

75-
el = etree.Element(ATOM_NS + 'updated')
75+
el = ET.Element(f'{ATOM_NS}updated')
7676
el.text = self.updated.strftime('%Y-%m-%dT%H:%M:%SZ')
7777
item.append(el)
7878

7979
if self.link:
80-
el = etree.Element(ATOM_NS + 'link')
81-
el.attrib[ATOM_NS + 'href'] = self.link
80+
el = ET.Element(f'{ATOM_NS}link')
81+
el.attrib[f'{ATOM_NS}href'] = self.link
8282
item.append(el)
8383

84-
el = etree.Element(ATOM_NS + 'content')
85-
el.attrib[XML_NS + 'lang'] = language
84+
el = ET.Element(f'{ATOM_NS}content')
85+
el.attrib[f'{XML_NS}lang'] = language
8686
if self.content:
8787
el.text = self.content
88-
el.attrib[ATOM_NS + 'type'] = 'html'
88+
el.attrib[f'{ATOM_NS}type'] = 'html'
8989
else:
9090
el.text = ' '
9191
item.append(el)
@@ -124,42 +124,42 @@ def write_atom(dest, entries, author, title, address, updated=None, link=None, l
124124
else:
125125
updated = datetime.datetime.now(datetime.timezone.utc)
126126

127-
root = etree.Element(ATOM_NS + 'feed')
127+
root = ET.Element(f'{ATOM_NS}feed')
128128

129129
# id (obligatory)
130-
el = etree.Element(ATOM_NS + 'id')
130+
el = ET.Element(f'{ATOM_NS}id')
131131
el.text = _get_id(address, None, ["feed", author, title])
132132
root.append(el)
133133

134134
# author (obligatory)
135-
el = etree.Element(ATOM_NS + 'author')
136-
el2 = etree.Element(ATOM_NS + 'name')
135+
el = ET.Element(f'{ATOM_NS}author')
136+
el2 = ET.Element(f'{ATOM_NS}name')
137137
el2.text = author
138138
el.append(el2)
139139
root.append(el)
140140

141141
# title (obligatory)
142-
el = etree.Element(ATOM_NS + 'title')
143-
el.attrib[XML_NS + 'lang'] = language
142+
el = ET.Element(f'{ATOM_NS}title')
143+
el.attrib[f'{XML_NS}lang'] = language
144144
el.text = title
145145
root.append(el)
146146

147147
# updated (obligatory)
148-
el = etree.Element(ATOM_NS + 'updated')
148+
el = ET.Element(f'{ATOM_NS}updated')
149149
el.text = updated.strftime('%Y-%m-%dT%H:%M:%SZ')
150150
root.append(el)
151151

152152
# link
153153
if link is not None:
154-
el = etree.Element(ATOM_NS + 'link')
155-
el.attrib[ATOM_NS + 'href'] = link
154+
el = ET.Element(f'{ATOM_NS}link')
155+
el.attrib[f'{ATOM_NS}href'] = link
156156
root.append(el)
157157

158158
# entries
159159
for entry in entries:
160160
root.append(entry.get_atom(address, language))
161161

162-
tree = etree.ElementTree(root)
162+
tree = ET.ElementTree(root)
163163

164164
def write(f):
165165
tree.write(f, xml_declaration=True, default_namespace=ATOM_NS[1:-1], encoding="utf-8")

test/test_publish.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import shutil
55
import subprocess
6-
import xml.etree.ElementTree as etree
6+
import xml.etree.ElementTree as ET
77
from os.path import abspath, dirname, isdir, isfile, join
88

99
import json5
@@ -453,7 +453,7 @@ def test_regression_atom_feed(generate_result_dir):
453453

454454
commits = list(reversed(repo.get_branch_commits(None)))
455455

456-
tree = etree.parse(join(conf.html_dir, "regressions.xml"))
456+
tree = ET.parse(join(conf.html_dir, "regressions.xml"))
457457
root = tree.getroot()
458458

459459
assert root.tag == '{http://www.w3.org/2005/Atom}feed'
@@ -505,7 +505,7 @@ def test_regression_atom_feed_update(dvcs_type, tmpdir):
505505

506506
tools.run_asv_with_conf(conf, "publish")
507507

508-
old_tree = etree.parse(join(conf.html_dir, "regressions.xml"))
508+
old_tree = ET.parse(join(conf.html_dir, "regressions.xml"))
509509

510510
# New results (values change, regressing revisions stay same)
511511
for commit, value in zip(commits, values):
@@ -522,7 +522,7 @@ def test_regression_atom_feed_update(dvcs_type, tmpdir):
522522

523523
tools.run_asv_with_conf(conf, "publish")
524524

525-
new_tree = etree.parse(join(conf.html_dir, "regressions.xml"))
525+
new_tree = ET.parse(join(conf.html_dir, "regressions.xml"))
526526

527527
# Check ids didn't change
528528
old_root = old_tree.getroot()

0 commit comments

Comments
 (0)