Skip to content

Commit

Permalink
Add ruff rules C4 and PERF for comprehensions and performance (#62)
Browse files Browse the repository at this point in the history
# Description

Please include:
* relevant motivation
* a summary of the change
* which issue is fixed.
* any additional dependencies that are required for this change.

* https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
* https://docs.astral.sh/ruff/rules/#perflint-perf

# Checklist:

- [x] I have performed a self-review of my own code
- [ ] I have commented my code in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
  • Loading branch information
ZeroCool940711 authored Feb 9, 2024
2 parents 059137a + 5e0a11d commit 8020025
Show file tree
Hide file tree
Showing 22 changed files with 424 additions and 431 deletions.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ select = [
"AIR", # Airflow
"ASYNC", # flake8-async
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # McCabe cyclomatic complexity
"DJ", # flake8-django
"DTZ", # flake8-datetimez
"EXE", # flake8-executable
"F", # Pyflakes
"FA", # flake8-future-annotations
Expand All @@ -17,6 +19,7 @@ select = [
"INT", # flake8-gettext
"LOG", # flake8-logging
"NPY", # NumPy-specific rules
"PERF", # Perflint
"PLC", # Pylint conventions
"PLE", # Pylint errors
"PLR091", # Pylint Refactor just for max-args, max-branches, etc.
Expand All @@ -33,11 +36,9 @@ select = [
# "ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
# "B", # flake8-bugbear
# "C4", # flake8-comprehensions
# "COM", # flake8-commas
# "CPY", # flake8-copyright
# "D", # pydocstyle
# "DTZ", # flake8-datetimez
# "E", # pycodestyle
# "EM", # flake8-errmsg
# "ERA", # eradicate
Expand All @@ -49,7 +50,6 @@ select = [
# "ISC", # flake8-implicit-str-concat
# "N", # pep8-naming
# "PD", # pandas-vet
# "PERF", # Perflint
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PL", # Pylint
Expand All @@ -71,6 +71,7 @@ ignore = [
"F401",
"F811",
"F841",
"PERF203",
"UP031",
]

Expand Down
2 changes: 1 addition & 1 deletion src/whoosh/analysis/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class CharsetFilter(Filter):
http://www.sphinxsearch.com/docs/current.html#conf-charset-table.
"""

__inittypes__ = dict(charmap=dict)
__inittypes__ = {"charmap": dict}

def __init__(self, charmap):
"""
Expand Down
14 changes: 7 additions & 7 deletions src/whoosh/analysis/intraword.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ class IntraWordFilter(Filter):

is_morph = True

__inittypes__ = dict(
delims=text_type,
splitwords=bool,
splitnums=bool,
mergewords=bool,
mergenums=bool,
)
__inittypes__ = {
"delims": text_type,
"splitwords": bool,
"splitnums": bool,
"mergewords": bool,
"mergenums": bool,
}

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/whoosh/analysis/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class StemFilter(Filter):
stemmers in that library.
"""

__inittypes__ = dict(stemfn=object, ignore=list)
__inittypes__ = {"stemfn": object, "ignore": list}

is_morph = True

Expand Down
4 changes: 2 additions & 2 deletions src/whoosh/analysis/ngrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class NgramTokenizer(Tokenizer):
could combine a RegexTokenizer with NgramFilter instead.
"""

__inittypes__ = dict(minsize=int, maxsize=int)
__inittypes__ = {"minsize": int, "maxsize": int}

def __init__(self, minsize, maxsize=None):
"""
Expand Down Expand Up @@ -135,7 +135,7 @@ class NgramFilter(Filter):
["hell", "ello", "ther", "here"]
"""

__inittypes__ = dict(minsize=int, maxsize=int)
__inittypes__ = {"minsize": int, "maxsize": int}

def __init__(self, minsize, maxsize=None, at=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/whoosh/analysis/tokenizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class CharsetTokenizer(Tokenizer):
http://www.sphinxsearch.com/docs/current.html#conf-charset-table.
"""

__inittype__ = dict(charmap=str)
__inittype__ = {"charmap": str}

def __init__(self, charmap):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/whoosh/automata/fst.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ def find_arc(self, address, label, arc=None):
# Convenience methods

def list_arcs(self, address):
return list(arc.copy() for arc in self.iter_arcs(address))
return [arc.copy() for arc in self.iter_arcs(address)]

def arc_dict(self, address):
return {arc.label: arc.copy() for arc in self.iter_arcs(address)}
Expand Down
2 changes: 1 addition & 1 deletion src/whoosh/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def u(s):
return s

def with_metaclass(meta, base=object):
ns = dict(base=base, meta=meta)
ns = {"base": base, "meta": meta}
exec_(
"""class _WhooshBase(base, metaclass=meta):
pass""",
Expand Down
5 changes: 1 addition & 4 deletions src/whoosh/filedb/gae.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ def open_index(self, indexname=_DEF_INDEX_NAME, schema=None):

def list(self):
query = DatastoreFile.all()
keys = []
for file in query:
keys.append(file.key().id_or_name())
return keys
return [file.key().id_or_name() for file in query]

def clean(self):
pass
Expand Down
6 changes: 3 additions & 3 deletions src/whoosh/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Format:

posting_size = -1
textual = True
__inittypes__ = dict(field_boost=float)
__inittypes__ = {"field_boost": float}

def __init__(self, field_boost=1.0, **options):
"""
Expand Down Expand Up @@ -144,7 +144,7 @@ class Existence(Format):
"""

posting_size = 0
__inittypes__ = dict(field_boost=float)
__inittypes__ = {"field_boost": float}

def __init__(self, field_boost=1.0, **options):
self.field_boost = field_boost
Expand Down Expand Up @@ -175,7 +175,7 @@ class Frequency(Format):
"""

posting_size = _INT_SIZE
__inittypes__ = dict(field_boost=float, boost_as_freq=bool)
__inittypes__ = {"field_boost": float, "boost_as_freq": bool}

def __init__(self, field_boost=1.0, boost_as_freq=False, **options):
"""
Expand Down
Loading

0 comments on commit 8020025

Please sign in to comment.