You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/02/10 22:44:56 UTC
[allura] 25/41: [#8349] python-modernize -n -w --no-diffs -f idioms
.
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch db/8349
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 158a4722e6542a52f07e44ca47406a448525032f
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Feb 10 14:46:15 2020 -0500
[#8349] python-modernize -n -w --no-diffs -f idioms .
---
Allura/allura/controllers/repository.py | 2 +-
Allura/allura/lib/AsciiDammit.py | 2 +-
Allura/allura/lib/helpers.py | 2 +-
Allura/allura/lib/mail_util.py | 4 ++--
Allura/allura/lib/widgets/project_list.py | 10 +++++-----
Allura/allura/scripts/trac_export.py | 2 +-
Allura/allura/tests/model/test_artifact.py | 2 +-
Allura/allura/tests/model/test_filesystem.py | 4 ++--
Allura/allura/tests/test_helpers.py | 2 +-
ForgeBlog/forgeblog/main.py | 2 +-
ForgeTracker/forgetracker/model/ticket.py | 2 +-
ForgeTracker/forgetracker/tests/functional/test_root.py | 2 +-
ForgeWiki/forgewiki/wiki_main.py | 3 +--
scripts/trac_import.py | 2 +-
14 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 1465b12..da8b834 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -699,7 +699,7 @@ class CommitBrowser(BaseController):
# ('removed', u'bbb.txt', 'tree', None),
# ('removed', u'ddd.txt', 'tree', None),
# ('changed', u'ccc.txt', 'blob', True)]
- result['artifacts'].sort(key=lambda x: x[1]['old'] if(type(x[1]) == dict) else x[1])
+ result['artifacts'].sort(key=lambda x: x[1]['old'] if(isinstance(x[1], dict)) else x[1])
return result
@expose('jinja:allura:templates/repo/commit_basic.html')
diff --git a/Allura/allura/lib/AsciiDammit.py b/Allura/allura/lib/AsciiDammit.py
index df0effa..db0604c 100644
--- a/Allura/allura/lib/AsciiDammit.py
+++ b/Allura/allura/lib/AsciiDammit.py
@@ -176,7 +176,7 @@ def _repl(match, html=0):
"Replace the matched character with its HTML or ASCII equivalent."
g = match.group(0)
a = CHARS.get(g, g)
- if type(a) == types.TupleType:
+ if isinstance(a, types.TupleType):
a = a[html]
if html:
a = '&' + a + ';'
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 1efbc39..8f075eb 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -322,7 +322,7 @@ def set_context(project_shortname_or_id, mount_point=None, app_config_id=None, n
p = model.Project.query.get(_id=ObjectId(str(project_shortname_or_id)))
except InvalidId:
p = None
- if p is None and type(project_shortname_or_id) != ObjectId:
+ if p is None and not isinstance(project_shortname_or_id, ObjectId):
if neighborhood is None:
raise TypeError('neighborhood is required; it must not be None')
if not isinstance(neighborhood, model.Neighborhood):
diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index b00019e..cce61a9 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -55,11 +55,11 @@ def Header(text, *more_text):
# email.header.Header handles str vs unicode differently
# see
# http://docs.python.org/library/email.header.html#email.header.Header.append
- if type(text) != six.text_type:
+ if not isinstance(text, six.text_type):
raise TypeError('This must be unicode: %r' % text)
head = header.Header(text)
for m in more_text:
- if type(m) != six.text_type:
+ if not isinstance(m, six.text_type):
raise TypeError('This must be unicode: %r' % text)
head.append(m)
return head
diff --git a/Allura/allura/lib/widgets/project_list.py b/Allura/allura/lib/widgets/project_list.py
index 71a6b78..1c53cf0 100644
--- a/Allura/allura/lib/widgets/project_list.py
+++ b/Allura/allura/lib/widgets/project_list.py
@@ -52,21 +52,21 @@ class ProjectSummary(ew_core.Widget):
if response['accolades'] is None:
response['accolades'] = value.accolades
- if type(response['columns']) == six.text_type:
+ if isinstance(response['columns'], six.text_type):
response['columns'] = int(response['columns'])
true_list = ['true', 't', '1', 'yes', 'y']
- if type(response['show_proj_icon']) == six.text_type:
+ if isinstance(response['show_proj_icon'], six.text_type):
if response['show_proj_icon'].lower() in true_list:
response['show_proj_icon'] = True
else:
response['show_proj_icon'] = False
- if type(response['show_download_button']) == six.text_type:
+ if isinstance(response['show_download_button'], six.text_type):
if response['show_download_button'].lower() in true_list:
response['show_download_button'] = True
else:
response['show_download_button'] = False
- if type(response['show_awards_banner']) == six.text_type:
+ if isinstance(response['show_awards_banner'], six.text_type):
if response['show_awards_banner'].lower() in true_list:
response['show_awards_banner'] = True
else:
@@ -104,7 +104,7 @@ class ProjectList(ew_core.Widget):
if response['accolades_index'] is None and response['show_awards_banner']:
response['accolades_index'] = M.Project.accolades_index(projects)
- if type(response['columns']) == six.text_type:
+ if isinstance(response['columns'], six.text_type):
response['columns'] = int(response['columns'])
return response
diff --git a/Allura/allura/scripts/trac_export.py b/Allura/allura/scripts/trac_export.py
index c9b411b..9d6a991 100644
--- a/Allura/allura/scripts/trac_export.py
+++ b/Allura/allura/scripts/trac_export.py
@@ -212,7 +212,7 @@ class TracExport(object):
text=re.compile('added by')).nextSibling.renderContents()
d['description'] = ''
# Skip whitespace
- while attach.nextSibling and type(attach.nextSibling) is NavigableString:
+ while attach.nextSibling and isinstance(attach.nextSibling, NavigableString):
attach = attach.nextSibling
# if there's a description, there will be a <dd> element, other
# immediately next <dt>
diff --git a/Allura/allura/tests/model/test_artifact.py b/Allura/allura/tests/model/test_artifact.py
index e0d15d9..cec7804 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -197,7 +197,7 @@ def test_messages_unknown_lookup():
from bson import ObjectId
m = Checkmessage()
m.author_id = ObjectId() # something new
- assert type(m.author()) == M.User, type(m.author())
+ assert isinstance(m.author(), M.User), type(m.author())
assert m.author() == M.User.anonymous()
diff --git a/Allura/allura/tests/model/test_filesystem.py b/Allura/allura/tests/model/test_filesystem.py
index 104267a..d757a4f 100644
--- a/Allura/allura/tests/model/test_filesystem.py
+++ b/Allura/allura/tests/model/test_filesystem.py
@@ -199,7 +199,7 @@ class TestFile(TestCase):
c.app.config._id = None
attachment = M.BaseAttachment.save_attachment('user.png', fp,
save_original=True)
- assert type(attachment) != tuple # tuple is for (img, thumb) pairs
+ assert not isinstance(attachment, tuple) # tuple is for (img, thumb) pairs
assert_equal(attachment.length, 500)
assert_equal(attachment.filename, 'user.png')
@@ -211,7 +211,7 @@ class TestFile(TestCase):
attachment = M.BaseAttachment.save_attachment(
b'Strukturpr\xfcfung.dvi', fp,
save_original=True)
- assert type(attachment) != tuple # tuple is for (img, thumb) pairs
+ assert not isinstance(attachment, tuple) # tuple is for (img, thumb) pairs
assert_equal(attachment.filename, 'Strukturpr\xfcfung.dvi')
def _assert_content(self, f, content):
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index ecb265c..d5ea156 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -187,7 +187,7 @@ def test_context_setters():
def test_encode_keys():
kw = h.encode_keys({'foo': 5})
- assert type(list(kw.keys())[0]) != six.text_type
+ assert not isinstance(list(kw.keys())[0], six.text_type)
def test_ago():
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 89d7ebd..98544b3 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -545,7 +545,7 @@ class BlogAdminController(DefaultAdminController):
@require_post()
def set_exfeed(self, new_exfeed=None, **kw):
exfeed_val = kw.get('exfeed', [])
- if type(exfeed_val) == six.text_type:
+ if isinstance(exfeed_val, six.text_type):
tmp_exfeed_list = []
tmp_exfeed_list.append(exfeed_val)
else:
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 99061c3..62f85c9 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -1176,7 +1176,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
def __json__(self, posts_limit=None, is_export=False):
parents_json = {}
for parent in reversed(type(self).mro()):
- if parent != type(self) and hasattr(parent, '__json__'):
+ if not isinstance(self, parent) and hasattr(parent, '__json__'):
kwargs = {}
if parent == VersionedArtifact:
kwargs['posts_limit'] = posts_limit
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 294b01e..32b3942 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -87,7 +87,7 @@ class TrackerTestController(TestController):
extra_environ=extra_environ)
form = self._find_new_ticket_form(response)
for k, v in six.iteritems(kw):
- if type(v) == bool:
+ if isinstance(v, bool):
form['ticket_form.%s' % k] = v
else:
form['ticket_form.%s' % k].force_value(v)
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 0c4f0de..75f289a 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -488,8 +488,7 @@ class RootController(BaseController, DispatchIndex, FeedController):
page_tags[label] = []
page_tags[label].append(page)
count = len(page_tags)
- name_labels = list(page_tags)
- name_labels.sort()
+ name_labels = sorted(page_tags)
return dict(labels=page_tags,
limit=limit,
count=count,
diff --git a/scripts/trac_import.py b/scripts/trac_import.py
index e9eed3c..5f14de7 100644
--- a/scripts/trac_import.py
+++ b/scripts/trac_import.py
@@ -42,7 +42,7 @@ def main():
f = open(options.user_map_file)
try:
user_map = json.load(f)
- if type(user_map) is not type({}):
+ if not isinstance(user_map, type({})):
raise ValueError
for k, v in six.iteritems(user_map):
print(k, v)