Skip to content
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

chore: cleanup flake8 #527

Merged
merged 10 commits into from
Jul 9, 2022
15 changes: 10 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,24 @@ repos:
rev: v1.20.1
hooks:
- id: setup-cfg-fmt
args: ["--min-py3-version", "3.5"]

- repo: https://github.com/mgedmin/check-manifest
rev: "0.48"
hooks:
- id: check-manifest
stages: [manual]

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa
additional_dependencies: &flake8-dependencies
- flake8-bugbear==22.4.25
- flake8-docstrings==1.6.0
- flake8-print==5.0.0

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-docstrings
- flake8-print
additional_dependencies: *flake8-dependencies
18 changes: 9 additions & 9 deletions dev/make-models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

for classname, class_version in superclasses:
cls = f.file.class_named(classname, class_version)
print(cls.class_code) # noqa: T201
print( # noqa: T201
print(cls.class_code)
henryiii marked this conversation as resolved.
Show resolved Hide resolved
print(
f"""
writable = True

Expand All @@ -93,8 +93,8 @@ class {uproot.model.classname_encode(classname)}(uproot.model.DispatchByVersion)

for key in keys:
obj = f[key]
print(type(obj).class_code) # noqa: T201
print( # noqa: T201
print(type(obj).class_code)
print(
"""
class_rawstreamers = ("""
)
Expand All @@ -108,15 +108,15 @@ class {uproot.model.classname_encode(classname)}(uproot.model.DispatchByVersion)
).tobytes()
preamble = b"\xff\xff\xff\xffTStreamerInfo\x00"
full = header + preamble + inner + b"\x00"
print( # noqa: T201
print(
f""" uproot._writing.RawStreamerInfo(
None,
{full},
{streamer_name!r},
{streamer_version},
),"""
)
print( # noqa: T201
print(
f""" )
writable = True

Expand All @@ -132,7 +132,7 @@ def _serialize(self, out, header, name):
"""
)

print( # noqa: T201
print(
f"""
class {uproot.model.classname_encode(obj.classname)}(uproot.model.DispatchByVersion):
\"\"\"
Expand All @@ -144,12 +144,12 @@ class {uproot.model.classname_encode(obj.classname)}(uproot.model.DispatchByVers
)

for classname, _ in superclasses:
print( # noqa: T201
print(
f"uproot.classes[{classname!r}] = {uproot.model.classname_encode(classname)}"
)

for key in keys:
obj = f[key]
print( # noqa: T201
print(
f"uproot.classes[{obj.classname!r}] = {uproot.model.classname_encode(obj.classname)}"
)
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ profile = black
multi_line_output = 3

[flake8]
ignore = E203, W503, E501, E266, N, D200, D102, D105, D107, D401, D402, D205, D400, D301
extend-ignore = E203, E501, E722, B950, E266, D
extend-select = B9, E711, D103
max-complexity = 100
exclude = tests/*.py, setup.py, src/uproot/__init__.py, docs-sphinx/*.py
per-file-ignores =
dev/*: T
30 changes: 14 additions & 16 deletions src/uproot/behaviors/TBranch.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ def show(
+ "\n"
)

for name, branch in self.iteritems( # noqa: B301 (not a dict)
for name, branch in self.iteritems(
henryiii marked this conversation as resolved.
Show resolved Hide resolved
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -1379,7 +1379,7 @@ def keys(
Returns the names of the subbranches as a list of strings.
"""
return list(
self.iterkeys( # noqa: B301 (not a dict)
self.iterkeys(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -1416,7 +1416,7 @@ def values(
:ref:`uproot.behaviors.TBranch.HasBranches.branches`.)
"""
return list(
self.itervalues( # noqa: B301 (not a dict)
self.itervalues(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def items(
of (str, :doc:`uproot.behaviors.TBranch.TBranch`).
"""
return list(
self.iteritems( # noqa: B301 (not a dict)
self.iteritems(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -1527,7 +1527,7 @@ def iterkeys(

Returns the names of the subbranches as an iterator over strings.
"""
for k, _ in self.iteritems( # noqa: B301 (not a dict)
for k, _ in self.iteritems(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -1563,7 +1563,7 @@ def itervalues(
(Note: with ``recursive=False``, this is the same as
:ref:`uproot.behaviors.TBranch.HasBranches.branches`.)
"""
for _, v in self.iteritems( # noqa: B301 (not a dict)
for _, v in self.iteritems(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -1625,7 +1625,7 @@ def iteritems(
yield branch.name, branch

if recursive:
for k1, v in branch.iteritems( # noqa: B301 (not a dict)
for k1, v in branch.iteritems(
recursive=recursive,
filter_name=no_filter,
filter_typename=filter_typename,
Expand Down Expand Up @@ -1669,7 +1669,7 @@ def itertypenames(
Returns (name, typename) pairs of the subbranches as an iterator over
2-tuples of (str, str).
"""
for k, v in self.iteritems( # noqa: B301 (not a dict)
for k, v in self.iteritems(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand All @@ -1682,7 +1682,7 @@ def _ipython_key_completions_(self):
"""
Supports key-completion in an IPython or Jupyter kernel.
"""
return self.iterkeys() # noqa: B301 (not a dict)
return self.iterkeys()

def num_entries_for(
self,
Expand Down Expand Up @@ -1800,7 +1800,7 @@ def common_entry_offsets(
:ref:`uproot.behaviors.TBranch.TBranch.entry_offsets`.
"""
common_offsets = None
for branch in self.itervalues( # noqa: B301 (not a dict)
for branch in self.itervalues(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -1834,9 +1834,7 @@ def __getitem__(self, where):

if "/" in where:
where = "/".join([x for x in where.split("/") if x != ""])
for k, v in self.iteritems( # noqa: B301 (not a dict)
recursive=True, full_paths=True
):
for k, v in self.iteritems(recursive=True, full_paths=True):
if where == k:
self._lookup[original_where] = v
return v
Expand Down Expand Up @@ -2787,7 +2785,7 @@ def _filter_name_deep(filter_name, hasbranches, branch):

def _keys_deep(hasbranches):
out = set()
for branch in hasbranches.itervalues(recursive=True): # noqa: B301 (not a dict)
for branch in hasbranches.itervalues(recursive=True):
name = branch.name
out.add(name)
while branch is not hasbranches:
Expand Down Expand Up @@ -3049,7 +3047,7 @@ def _regularize_expressions(
branchid_interpretation = {}

if expressions is None:
for branchname, branch in hasbranches.iteritems( # noqa: B301 (not a dict)
for branchname, branch in hasbranches.iteritems(
filter_name=filter_name,
filter_typename=filter_typename,
filter_branch=filter_branch,
Expand Down Expand Up @@ -3342,7 +3340,7 @@ def _hasbranches_num_entries_for(
hasbranches, target_num_bytes, entry_start, entry_stop, branchid_interpretation
):
total_bytes = 0.0
for branch in hasbranches.itervalues(recursive=True): # noqa: B301 (not a dict)
for branch in hasbranches.itervalues(recursive=True):
if branch.cache_key in branchid_interpretation:
entry_offsets = branch.entry_offsets
start = entry_offsets[0]
Expand Down
16 changes: 8 additions & 8 deletions src/uproot/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ def keys(
Note that this does not read any data from the file.
"""
return list(
self.iterkeys( # noqa: B301 (not a dict)
self.iterkeys(
recursive=recursive,
cycle=cycle,
filter_name=filter_name,
Expand Down Expand Up @@ -1651,7 +1651,7 @@ def values(
and ``filter_classname``.
"""
return list(
self.itervalues( # noqa: B301 (not a dict)
self.itervalues(
recursive=recursive,
filter_name=filter_name,
filter_classname=filter_classname,
Expand Down Expand Up @@ -1683,7 +1683,7 @@ def items(
and ``filter_classname``.
"""
return list(
self.iteritems( # noqa: B301 (not a dict)
self.iteritems(
recursive=recursive,
cycle=cycle,
filter_name=filter_name,
Expand Down Expand Up @@ -1759,7 +1759,7 @@ def iterkeys(
seen.add(out)

if recursive and key.fClassName in ("TDirectory", "TDirectoryFile"):
for k1 in key.get().iterkeys( # noqa: B301 (not a dict)
for k1 in key.get().iterkeys(
recursive=recursive,
cycle=cycle,
filter_name=no_filter,
Expand Down Expand Up @@ -1794,7 +1794,7 @@ def itervalues(
Note that this reads all objects that are selected by ``filter_name``
and ``filter_classname``.
"""
for _, v in self.iteritems( # noqa: B301 (not a dict)
for _, v in self.iteritems(
recursive=recursive,
cycle=False,
filter_name=filter_name,
Expand Down Expand Up @@ -1839,7 +1839,7 @@ def iteritems(
seen.add(out)

if recursive and key.fClassName in ("TDirectory", "TDirectoryFile"):
for k1, v in key.get().iteritems( # noqa: B301 (not a dict)
for k1, v in key.get().iteritems(
recursive=recursive,
cycle=cycle,
filter_name=no_filter,
Expand Down Expand Up @@ -1905,7 +1905,7 @@ def _ipython_key_completions_(self):
"""
Supports key-completion in an IPython or Jupyter kernel.
"""
return self.iterkeys() # noqa: B301 (not a dict)
return self.iterkeys()

def __len__(self):
if self._len is None:
Expand All @@ -1925,7 +1925,7 @@ def __contains__(self, where):
return True

def __iter__(self):
return self.iterkeys() # noqa: B301 (not a dict)
return self.iterkeys()

def title_of(self, where):
"""
Expand Down
22 changes: 9 additions & 13 deletions src/uproot/writing/writable.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,13 @@ def __contains__(self, where):
return False

def __iter__(self):
return self.iterkeys() # noqa B301 (not a dict)
return self.iterkeys()

def _ipython_key_completions_(self):
"""
Supports key-completion in an IPython or Jupyter kernel.
"""
return self.iterkeys() # noqa: B301 (not a dict)
return self.iterkeys()

def keys(
self,
Expand All @@ -633,7 +633,7 @@ def keys(
Note that this does not read any data from the file.
"""
return list(
self.iterkeys( # noqa: B301 (not a dict)
self.iterkeys(
recursive=recursive,
cycle=cycle,
filter_name=filter_name,
Expand Down Expand Up @@ -664,7 +664,7 @@ def values(
and ``filter_classname``.
"""
return list(
self.itervalues( # noqa: B301 (not a dict)
self.itervalues(
recursive=recursive,
filter_name=filter_name,
filter_classname=filter_classname,
Expand Down Expand Up @@ -696,7 +696,7 @@ def items(
and ``filter_classname``.
"""
return list(
self.iteritems( # noqa: B301 (not a dict)
self.iteritems(
recursive=recursive,
cycle=cycle,
filter_name=filter_name,
Expand Down Expand Up @@ -771,9 +771,7 @@ def iterkeys(
yield keyname

if recursive and classname in ("TDirectory", "TDirectoryFile"):
for k1 in self._get( # noqa: B301 (not a dict)
keyname, cyclenum
).iterkeys(
for k1 in self._get(keyname, cyclenum).iterkeys(
recursive=recursive,
cycle=cycle,
filter_name=filter_name,
Expand Down Expand Up @@ -806,7 +804,7 @@ def itervalues(
Note that this reads all objects that are selected by ``filter_name``
and ``filter_classname``.
"""
for keyname in self.iterkeys( # noqa: B301 (not a dict)
for keyname in self.iterkeys(
recursive=recursive,
cycle=True,
filter_name=filter_name,
Expand Down Expand Up @@ -838,7 +836,7 @@ def iteritems(
Note that this reads all objects that are selected by ``filter_name``
and ``filter_classname``.
"""
for keyname in self.iterkeys( # noqa: B301 (not a dict)
for keyname in self.iterkeys(
recursive=recursive,
cycle=True,
filter_name=filter_name,
Expand Down Expand Up @@ -884,9 +882,7 @@ def iterclassnames(
yield keyname, classname

if recursive and classname in ("TDirectory", "TDirectoryFile"):
for k1, c1 in self._get(
keyname, cyclenum
).iterclassnames( # noqa: B301 (not a dict)
for k1, c1 in self._get(keyname, cyclenum).iterclassnames(
recursive=recursive,
cycle=cycle,
filter_name=filter_name,
Expand Down
Loading