Skip to content

Simplify using flake8-simplify #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: check-added-large-files
args: ["--maxkb=128"]
Expand All @@ -33,7 +33,7 @@ repos:
args: ["--autofix", "--no-sort-keys", "--indent=4"]
- id: trailing-whitespace
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
Expand Down
18 changes: 4 additions & 14 deletions pysolr.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,7 @@ def _from_python(self, value):
else:
value = "%sT00:00:00Z" % value.isoformat()
elif isinstance(value, bool):
if value:
value = "true"
else:
value = "false"
value = "true" if value else "false"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would disable this. It’s harder to read, generates more diff noise if you change either branch, and vertical height isn’t a strictly limited resource.

else:
if IS_PY3:
# Python 3.X
Expand Down Expand Up @@ -986,16 +983,12 @@ def _build_xml_doc(self, doc, boost=None, fieldUpdates=None):

# To avoid multiple code-paths we'd like to treat all of our values
# as iterables:
if isinstance(value, (list, tuple, set)):
values = value
else:
values = (value,)
values = value if isinstance(value, (list, tuple, set)) else (value,)

use_field_updates = fieldUpdates and key in fieldUpdates
if use_field_updates and not values:
values = ("",)
for bit in values:

attrs = {"name": key}

if self._is_null_value(bit):
Expand Down Expand Up @@ -1633,13 +1626,10 @@ def getHosts(self, collname, only_leader=False, seen_aliases=None):
raise SolrError("Unknown collection: %s" % collname)
collection = self.collections[collname]
shards = collection[ZooKeeper.SHARDS]
for shardname in shards.keys():
shard = shards[shardname]
for shard in shards.values():
if shard[ZooKeeper.STATE] == ZooKeeper.ACTIVE:
replicas = shard[ZooKeeper.REPLICAS]
for replicaname in replicas.keys():
replica = replicas[replicaname]

for replica in replicas.values():
if replica[ZooKeeper.STATE] == ZooKeeper.ACTIVE:
if not only_leader or (
replica.get(ZooKeeper.LEADER, None) == ZooKeeper.TRUE
Expand Down
18 changes: 9 additions & 9 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,14 +833,14 @@ def test_field_update_inc(self):

updatedDocs = self.solr.search("doc")
self.assertEqual(len(updatedDocs), 3)
for (originalDoc, updatedDoc) in zip(originalDocs, updatedDocs):
for originalDoc, updatedDoc in zip(originalDocs, updatedDocs):
self.assertEqual(len(updatedDoc.keys()), len(originalDoc.keys()))
self.assertEqual(updatedDoc["popularity"], originalDoc["popularity"] + 5)
# TODO: change this to use assertSetEqual:
self.assertTrue(
all(
updatedDoc[k] == originalDoc[k]
for k in updatedDoc.keys()
v == originalDoc[k]
for k, v in updatedDoc.items()
if k not in ["_version_", "popularity"]
)
)
Expand All @@ -856,14 +856,14 @@ def test_field_update_set(self):

updatedDocs = self.solr.search("doc")
self.assertEqual(len(updatedDocs), 3)
for (originalDoc, updatedDoc) in zip(originalDocs, updatedDocs):
for originalDoc, updatedDoc in zip(originalDocs, updatedDocs):
self.assertEqual(len(updatedDoc.keys()), len(originalDoc.keys()))
self.assertEqual(updatedDoc["popularity"], updated_popularity)
# TODO: change this to use assertSetEqual:
self.assertTrue(
all(
updatedDoc[k] == originalDoc[k]
for k in updatedDoc.keys()
v == originalDoc[k]
for k, v in updatedDoc.items()
if k not in ["_version_", "popularity"]
)
)
Expand Down Expand Up @@ -894,16 +894,16 @@ def test_field_update_add(self):

updatedDocs = self.solr.search("multivalued")
self.assertEqual(len(updatedDocs), 2)
for (originalDoc, updatedDoc) in zip(originalDocs, updatedDocs):
for originalDoc, updatedDoc in zip(originalDocs, updatedDocs):
self.assertEqual(len(updatedDoc.keys()), len(originalDoc.keys()))
self.assertEqual(
updatedDoc["word_ss"], originalDoc["word_ss"] + ["epsilon", "gamma"]
)
# TODO: change this to use assertSetEqual:
self.assertTrue(
all(
updatedDoc[k] == originalDoc[k]
for k in updatedDoc.keys()
v == originalDoc[k]
for k, v in updatedDoc.items()
if k not in ["_version_", "word_ss"]
)
)
Expand Down