From a91aac9b57e26826308843b018e103fcad959518 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Wed, 13 Mar 2024 17:01:33 +0100 Subject: [PATCH 1/4] Update to latest versions of black & co, use black's stable style --- .devcontainer/dev-requirements.txt | 10 +++++----- .pre-commit-config.yaml | 10 +++++----- pyproject.toml | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.devcontainer/dev-requirements.txt b/.devcontainer/dev-requirements.txt index fca42130a..135b5f4a3 100644 --- a/.devcontainer/dev-requirements.txt +++ b/.devcontainer/dev-requirements.txt @@ -4,8 +4,8 @@ matplotlib >= 2.0 jupyterlab ipympl pre-commit == 3.3.* -black == 22.10.0 -isort == 5.12.0 -pyupgrade == 3.4.0 -flake8 == 6.0.0 -flake8-bugbear == 23.5.9 +black == 24.2.0 +isort == 5.13.2 +pyupgrade == 3.15.1 +flake8 == 7.0.0 +flake8-bugbear == 24.2.6 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index facf98809..a411f77be 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,26 +4,26 @@ repos: - id: check-hooks-apply - id: check-useless-excludes - repo: https://github.com/asottile/pyupgrade - rev: v3.4.0 + rev: v3.15.1 hooks: - id: pyupgrade args: [--py39-plus] files: '^brian2/.*\.pyi?$' - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 7.0.0 hooks: - id: flake8 # We exclude all __init__.py files, since we use wildcard imports, etc. exclude: '^brian2/tests/.*$|^brian2/.*__init__[.]py$' files: '^brian2/.*\.pyi?$' - additional_dependencies: ['flake8-bugbear==23.5.9'] + additional_dependencies: ['flake8-bugbear==24.2.6'] - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort files: '^brian2/.*\.pyi?$' - repo: https://github.com/psf/black - rev: '22.10.0' + rev: '24.2.0' hooks: - id: black files: '^brian2/.*\.pyi?$' diff --git a/pyproject.toml b/pyproject.toml index 8c2b9069b..b480565fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,7 +71,6 @@ build-backend = "setuptools.build_meta" [tool.black] target-version = ['py39'] include = '^/brian2/.*\.pyi?$' -preview = true [tool.isort] atomic = true From f930041feb043ae0d3ab08a399e20b6989b20595 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Wed, 13 Mar 2024 17:03:07 +0100 Subject: [PATCH 2/4] Do not return from __init__ --- brian2/utils/filelock.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/brian2/utils/filelock.py b/brian2/utils/filelock.py index d820624d9..7627021ed 100644 --- a/brian2/utils/filelock.py +++ b/brian2/utils/filelock.py @@ -95,7 +95,6 @@ def __init__(self, lock_file): """ """ #: The path of the file lock. self.lock_file = lock_file - return None def __str__(self): temp = f"The file lock '{self.lock_file}' could not be acquired." @@ -105,6 +104,7 @@ def __str__(self): # Classes # ------------------------------------------------ + # This is a helper class which is returned by :meth:`BaseFileLock.acquire` # and wraps the lock to make sure __enter__ is not called twice when entering # the with statement. @@ -116,7 +116,6 @@ def __str__(self): class _Acquire_ReturnProxy: def __init__(self, lock): self.lock = lock - return None def __enter__(self): return self.lock @@ -152,7 +151,6 @@ def __init__(self, lock_file, timeout=-1): # mechanism. Whenever the lock is acquired, the counter is increased and # the lock is only released, when this value is 0 again. self._lock_counter = 0 - return None @property def lock_file(self): From 0d015a50d641edc7709bd89e0ed389e54f1dcab0 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Wed, 13 Mar 2024 17:06:44 +0100 Subject: [PATCH 3/4] Style changes with latest black/isort versions --- brian2/__init__.py | 1 + brian2/codegen/__init__.py | 1 + brian2/codegen/_prefs.py | 1 + brian2/codegen/codeobject.py | 1 + brian2/codegen/cpp_prefs.py | 8 +++-- brian2/codegen/generators/GSL_generator.py | 13 +++----- brian2/codegen/generators/base.py | 3 +- brian2/codegen/get_cpu_flags.py | 1 - .../runtime/cython_rt/extension_manager.py | 1 - brian2/codegen/templates.py | 1 + brian2/conftest.py | 1 + brian2/core/base.py | 4 +-- brian2/core/clocks.py | 1 - brian2/core/network.py | 32 ++++++++++++------- brian2/core/operations.py | 1 + brian2/core/preferences.py | 3 +- brian2/core/variables.py | 1 + brian2/devices/__init__.py | 1 + brian2/devices/cpp_standalone/device.py | 11 +++---- brian2/equations/__init__.py | 1 + brian2/equations/equations.py | 1 + brian2/equations/refractory.py | 1 - brian2/groups/group.py | 1 + brian2/groups/neurongroup.py | 1 + brian2/hears.py | 1 - brian2/importexport/dictlike.py | 3 +- brian2/input/poissongroup.py | 1 + brian2/input/poissoninput.py | 1 + brian2/input/timedarray.py | 1 - brian2/monitors/__init__.py | 1 + brian2/monitors/ratemonitor.py | 1 + brian2/monitors/spikemonitor.py | 1 + brian2/only.py | 1 + brian2/parsing/bast.py | 1 + brian2/parsing/expressions.py | 1 + brian2/parsing/rendering.py | 8 ++--- brian2/spatialneuron/morphology.py | 6 ++-- brian2/spatialneuron/spatialneuron.py | 1 + brian2/sphinxext/briandoc.py | 1 + brian2/sphinxext/docscrape.py | 1 - brian2/sphinxext/examplefinder.py | 1 - brian2/sphinxext/generate_reference.py | 1 - brian2/stateupdaters/__init__.py | 1 + brian2/stateupdaters/base.py | 1 + brian2/stateupdaters/explicit.py | 1 + brian2/synapses/synapses.py | 7 ++-- brian2/tests/__init__.py | 7 ++-- brian2/tests/features/base.py | 12 +++---- brian2/tests/features/input.py | 1 - brian2/tests/features/monitors.py | 1 - brian2/tests/features/synapses.py | 1 + brian2/tests/test_parsing.py | 1 + brian2/tests/test_spikegenerator.py | 1 + brian2/tests/test_synapses.py | 6 ++-- brian2/tests/test_units.py | 4 +-- brian2/units/allunits.py | 1 + brian2/units/fundamentalunits.py | 1 + brian2/utils/environment.py | 1 + brian2/utils/filetools.py | 1 - brian2/utils/stringtools.py | 1 + 60 files changed, 93 insertions(+), 79 deletions(-) diff --git a/brian2/__init__.py b/brian2/__init__.py index fc854a62f..f914325f6 100644 --- a/brian2/__init__.py +++ b/brian2/__init__.py @@ -1,6 +1,7 @@ """ Brian 2 """ + import logging diff --git a/brian2/codegen/__init__.py b/brian2/codegen/__init__.py index 9ecf36a06..4f75b39f8 100644 --- a/brian2/codegen/__init__.py +++ b/brian2/codegen/__init__.py @@ -1,6 +1,7 @@ """ Package providing the code generation framework. """ + # Import the runtime packages so that they can register their preferences # isort:skip_file diff --git a/brian2/codegen/_prefs.py b/brian2/codegen/_prefs.py index f19dd3449..6e3273246 100644 --- a/brian2/codegen/_prefs.py +++ b/brian2/codegen/_prefs.py @@ -5,6 +5,7 @@ ----------- .. document_brian_prefs:: codegen """ + from brian2.core.preferences import BrianPreference, prefs from .codeobject import CodeObject diff --git a/brian2/codegen/codeobject.py b/brian2/codegen/codeobject.py index 4af1e6230..bb6c71029 100644 --- a/brian2/codegen/codeobject.py +++ b/brian2/codegen/codeobject.py @@ -1,6 +1,7 @@ """ Module providing the base `CodeObject` and related functions. """ + import collections import copy import platform diff --git a/brian2/codegen/cpp_prefs.py b/brian2/codegen/cpp_prefs.py index 2dd4299b0..653dd777b 100644 --- a/brian2/codegen/cpp_prefs.py +++ b/brian2/codegen/cpp_prefs.py @@ -6,6 +6,7 @@ .. document_brian_prefs:: codegen.cpp """ + import distutils import json import os @@ -266,9 +267,10 @@ def _determine_flag_compatibility(compiler, flagname): import tempfile from distutils.errors import CompileError - with tempfile.TemporaryDirectory( - prefix="brian_flag_test_" - ) as temp_dir, std_silent(): + with ( + tempfile.TemporaryDirectory(prefix="brian_flag_test_") as temp_dir, + std_silent(), + ): fname = os.path.join(temp_dir, "flag_test.cpp") with open(fname, "w") as f: f.write("int main (int argc, char **argv) { return 0; }") diff --git a/brian2/codegen/generators/GSL_generator.py b/brian2/codegen/generators/GSL_generator.py index 29e3ddb4a..f5b281e50 100644 --- a/brian2/codegen/generators/GSL_generator.py +++ b/brian2/codegen/generators/GSL_generator.py @@ -642,9 +642,9 @@ def to_replace_vector_vars(self, variables_in_vector, ignore=frozenset()): continue if isinstance(var_obj, ArrayVariable): pointer_name = self.get_array_name(var_obj, access_data=True) - to_replace[ - pointer_name - ] = f"_GSL_dataholder{access_pointer}{pointer_name}" + to_replace[pointer_name] = ( + f"_GSL_dataholder{access_pointer}{pointer_name}" + ) else: to_replace[var] = f"_GSL_dataholder{access_pointer}{var}" @@ -933,8 +933,7 @@ def translate( "well-defined: the outcome may depend on the " "order of execution. You can ignore this warning if " "you are sure that the order of operations does not " - "matter. " - + error_msg + "matter. " + error_msg ) # save function names because self.generator.translate_statement_sequence @@ -1019,9 +1018,7 @@ def translate( ) # rewrite scalar code, keep variables that are needed in scalar code normal # and add variables to _dataholder for vector_code - GSL_main_code += ( - f"\n{self.translate_scalar_code(scalar_func_code, variables_in_scalar, variables_in_vector)}" - ) + GSL_main_code += f"\n{self.translate_scalar_code(scalar_func_code, variables_in_scalar, variables_in_vector)}" if len(self.variables_to_be_processed) > 0: raise AssertionError( "Not all variables that will be used in the vector " diff --git a/brian2/codegen/generators/base.py b/brian2/codegen/generators/base.py index 86acda133..42ac8e065 100644 --- a/brian2/codegen/generators/base.py +++ b/brian2/codegen/generators/base.py @@ -297,8 +297,7 @@ def translate(self, code, dtype): "well-defined: the outcome may depend on the " "order of execution. You can ignore this warning if " "you are sure that the order of operations does not " - "matter. " - + error_msg + "matter. " + error_msg ) translated = self.translate_statement_sequence( diff --git a/brian2/codegen/get_cpu_flags.py b/brian2/codegen/get_cpu_flags.py index b3363cabb..7d9020896 100644 --- a/brian2/codegen/get_cpu_flags.py +++ b/brian2/codegen/get_cpu_flags.py @@ -7,7 +7,6 @@ The CPU flags are printed to stdout encoded as JSON. """ - import json if __name__ == "__main__": diff --git a/brian2/codegen/runtime/cython_rt/extension_manager.py b/brian2/codegen/runtime/cython_rt/extension_manager.py index 59e04317b..b2a56b2d2 100644 --- a/brian2/codegen/runtime/cython_rt/extension_manager.py +++ b/brian2/codegen/runtime/cython_rt/extension_manager.py @@ -5,7 +5,6 @@ https://github.com/ipython/ipython/blob/master/IPython/extensions/cythonmagic.py """ - import glob import hashlib import importlib.util diff --git a/brian2/codegen/templates.py b/brian2/codegen/templates.py index 32f562c31..31a6693ba 100644 --- a/brian2/codegen/templates.py +++ b/brian2/codegen/templates.py @@ -1,6 +1,7 @@ """ Handles loading templates from a directory. """ + import re from collections.abc import Mapping diff --git a/brian2/conftest.py b/brian2/conftest.py index 59f4611b7..1c6f25949 100644 --- a/brian2/conftest.py +++ b/brian2/conftest.py @@ -1,6 +1,7 @@ """ Module containing fixtures and hooks used by the pytest test suite. """ + import re import numpy as np diff --git a/brian2/core/base.py b/brian2/core/base.py index f32e1541d..72cf5f217 100644 --- a/brian2/core/base.py +++ b/brian2/core/base.py @@ -1,6 +1,7 @@ """ All Brian objects should derive from `BrianObject`. """ + import functools import os import sys @@ -81,8 +82,7 @@ def __init__( #: A string indicating where this object was created (traceback with any parts of Brian code removed) self._creation_stack = ( "Object was created here (most recent call only, full details in " - "debug log):\n" - + creation_stack[-1] + "debug log):\n" + creation_stack[-1] ) self._full_creation_stack = "Object was created here:\n" + "\n".join( creation_stack diff --git a/brian2/core/clocks.py b/brian2/core/clocks.py index 2749c4796..40cdd8d11 100644 --- a/brian2/core/clocks.py +++ b/brian2/core/clocks.py @@ -2,7 +2,6 @@ Clocks for the simulator. """ - __docformat__ = "restructuredtext en" import numpy as np diff --git a/brian2/core/network.py b/brian2/core/network.py index e54073fc6..3aaf01f76 100644 --- a/brian2/core/network.py +++ b/brian2/core/network.py @@ -217,14 +217,18 @@ def __repr__(self): [ [ f"{entry.name} ({entry.type})", - f"{entry.owner_name} ({entry.owner_type})" - if entry.owner_name is not None - else "--", + ( + f"{entry.owner_name} ({entry.owner_type})" + if entry.owner_name is not None + else "--" + ), "{} (every {})".format( str(entry.dt), - "step" - if self.steps[float(entry.dt)] == 1 - else f"{self.steps[float(entry.dt)]} steps", + ( + "step" + if self.steps[float(entry.dt)] == 1 + else f"{self.steps[float(entry.dt)]} steps" + ), ), entry.when, entry.order, @@ -248,14 +252,18 @@ def _repr_html_(self): """.format( f"{entry.name} ({entry.type})", - f"{entry.owner_name} ({entry.owner_type})" - if entry.owner_name is not None - else "–", + ( + f"{entry.owner_name} ({entry.owner_type})" + if entry.owner_name is not None + else "–" + ), "{} (every {})".format( str(entry.dt), - "step" - if self.steps[float(entry.dt)] == 1 - else f"{self.steps[float(entry.dt)]} steps", + ( + "step" + if self.steps[float(entry.dt)] == 1 + else f"{self.steps[float(entry.dt)]} steps" + ), ), entry.when, entry.order, diff --git a/brian2/core/operations.py b/brian2/core/operations.py index 83a4f880b..da7fbffad 100644 --- a/brian2/core/operations.py +++ b/brian2/core/operations.py @@ -170,6 +170,7 @@ def f(): NetworkOperation, Network, BrianObject """ + # Notes on this decorator: # Normally, a decorator comes in two types, with or without arguments. If # it has no arguments, e.g. diff --git a/brian2/core/preferences.py b/brian2/core/preferences.py index fc47be5a9..682536ac8 100644 --- a/brian2/core/preferences.py +++ b/brian2/core/preferences.py @@ -611,8 +611,7 @@ def check_all_validated(self): "The following preferences values have been set but " "are not registered preferences:\n%s\nThis is usually " "because of a spelling mistake or missing library " - "import." - % ", ".join(self.prefs_unvalidated), + "import." % ", ".join(self.prefs_unvalidated), once=True, ) diff --git a/brian2/core/variables.py b/brian2/core/variables.py index c969b8db6..9c8cf2ceb 100644 --- a/brian2/core/variables.py +++ b/brian2/core/variables.py @@ -2,6 +2,7 @@ Classes used to specify the type of a function, variable or common sub-expression. """ + import collections import functools import numbers diff --git a/brian2/devices/__init__.py b/brian2/devices/__init__.py index 6a5332b01..71e41153c 100644 --- a/brian2/devices/__init__.py +++ b/brian2/devices/__init__.py @@ -1,5 +1,6 @@ """ Package providing the "devices" infrastructure. """ + from . import device as device_module from .device import * diff --git a/brian2/devices/cpp_standalone/device.py b/brian2/devices/cpp_standalone/device.py index 90a406a1e..7cb100b98 100644 --- a/brian2/devices/cpp_standalone/device.py +++ b/brian2/devices/cpp_standalone/device.py @@ -1,6 +1,7 @@ """ Module implementing the C++ "standalone" device. """ + import inspect import itertools import numbers @@ -233,9 +234,7 @@ def __init__(self): self.run_environment_variables = {} if sys.platform.startswith("darwin"): if "DYLD_LIBRARY_PATH" in os.environ: - dyld_library_path = ( - f"{os.environ['DYLD_LIBRARY_PATH']}:{os.path.join(sys.prefix, 'lib')}" - ) + dyld_library_path = f"{os.environ['DYLD_LIBRARY_PATH']}:{os.path.join(sys.prefix, 'lib')}" else: dyld_library_path = os.path.join(sys.prefix, "lib") self.run_environment_variables["DYLD_LIBRARY_PATH"] = dyld_library_path @@ -387,9 +386,9 @@ def add_array(self, var): # use the same name in the two dictionaries, not for example # ``_dynamic_array_source_name_2`` and ``_array_source_name_1`` # (this would work fine, but it would make the code harder to read). - orig_dynamic_name = ( - dynamic_name - ) = f"_dynamic_array_{var.owner.name}_{var.name}" + orig_dynamic_name = dynamic_name = ( + f"_dynamic_array_{var.owner.name}_{var.name}" + ) orig_array_name = array_name = f"_array_{var.owner.name}_{var.name}" suffix = 0 diff --git a/brian2/equations/__init__.py b/brian2/equations/__init__.py index 79d0467c7..7736e9103 100644 --- a/brian2/equations/__init__.py +++ b/brian2/equations/__init__.py @@ -2,6 +2,7 @@ Module handling equations and "code strings", expressions or statements, used for example for the reset and threshold definition of a neuron. """ + from .codestrings import Expression, Statements from .equations import Equations diff --git a/brian2/equations/equations.py b/brian2/equations/equations.py index 2d8d58651..61f8bdd21 100644 --- a/brian2/equations/equations.py +++ b/brian2/equations/equations.py @@ -1,6 +1,7 @@ """ Differential equations for Brian models. """ + import keyword import re import string diff --git a/brian2/equations/refractory.py b/brian2/equations/refractory.py index ad9f169c3..32faf2741 100644 --- a/brian2/equations/refractory.py +++ b/brian2/equations/refractory.py @@ -2,7 +2,6 @@ Module implementing Brian's refractory mechanism. """ - from brian2.units.allunits import second from brian2.units.fundamentalunits import DIMENSIONLESS diff --git a/brian2/groups/group.py b/brian2/groups/group.py index 973198e9b..9a867e471 100644 --- a/brian2/groups/group.py +++ b/brian2/groups/group.py @@ -5,6 +5,7 @@ objects such as `NeuronGroup` or `StateMonitor` but not `Clock`, and finally `CodeRunner`, a class to run code in the context of a `Group`. """ + import inspect import numbers import weakref diff --git a/brian2/groups/neurongroup.py b/brian2/groups/neurongroup.py index 63f7207d8..3d3da727f 100644 --- a/brian2/groups/neurongroup.py +++ b/brian2/groups/neurongroup.py @@ -1,6 +1,7 @@ """ This model defines the `NeuronGroup`, the core of most simulations. """ + import numbers import string from collections.abc import MutableMapping, Sequence diff --git a/brian2/hears.py b/brian2/hears.py index 59e2467b4..0ba39c9b5 100644 --- a/brian2/hears.py +++ b/brian2/hears.py @@ -16,7 +16,6 @@ * time_varying_filter1 (care with units) """ - try: import brian as b1 import brian.hears as b1h diff --git a/brian2/importexport/dictlike.py b/brian2/importexport/dictlike.py index 17c498896..57626c948 100644 --- a/brian2/importexport/dictlike.py +++ b/brian2/importexport/dictlike.py @@ -53,8 +53,7 @@ def export_data(group, variables, units=True, level=0): except ImportError as ex: raise ImportError( "Exporting to pandas needs a working installation" - " of pandas. Importing pandas failed: " - + str(ex) + " of pandas. Importing pandas failed: " + str(ex) ) if units: raise NotImplementedError( diff --git a/brian2/input/poissongroup.py b/brian2/input/poissongroup.py index 8267f316e..50e48acfb 100644 --- a/brian2/input/poissongroup.py +++ b/brian2/input/poissongroup.py @@ -1,6 +1,7 @@ """ Implementation of `PoissonGroup`. """ + import numpy as np from brian2.core.spikesource import SpikeSource diff --git a/brian2/input/poissoninput.py b/brian2/input/poissoninput.py index 72da062f1..51e3845fa 100644 --- a/brian2/input/poissoninput.py +++ b/brian2/input/poissoninput.py @@ -1,6 +1,7 @@ """ Implementation of `PoissonInput`. """ + from brian2.core.variables import Variables from brian2.groups.group import CodeRunner from brian2.units.fundamentalunits import ( diff --git a/brian2/input/timedarray.py b/brian2/input/timedarray.py index 447b92703..03cf473de 100644 --- a/brian2/input/timedarray.py +++ b/brian2/input/timedarray.py @@ -2,7 +2,6 @@ Implementation of `TimedArray`. """ - import numpy as np from brian2.core.clocks import defaultclock diff --git a/brian2/monitors/__init__.py b/brian2/monitors/__init__.py index 88d8e4308..f5f607ce7 100644 --- a/brian2/monitors/__init__.py +++ b/brian2/monitors/__init__.py @@ -2,6 +2,7 @@ Base package for all monitors, i.e. objects to record activity during a simulation run. """ + from .ratemonitor import * from .spikemonitor import * from .statemonitor import * diff --git a/brian2/monitors/ratemonitor.py b/brian2/monitors/ratemonitor.py index ffbde5fe7..3a0a74576 100644 --- a/brian2/monitors/ratemonitor.py +++ b/brian2/monitors/ratemonitor.py @@ -1,6 +1,7 @@ """ Module defining `PopulationRateMonitor`. """ + import numpy as np from brian2.core.variables import Variables diff --git a/brian2/monitors/spikemonitor.py b/brian2/monitors/spikemonitor.py index 8f568825c..424807776 100644 --- a/brian2/monitors/spikemonitor.py +++ b/brian2/monitors/spikemonitor.py @@ -1,6 +1,7 @@ """ Module defining `EventMonitor` and `SpikeMonitor`. """ + import numpy as np from brian2.core.names import Nameable diff --git a/brian2/only.py b/brian2/only.py index 5fb5a567d..6bcaed48e 100644 --- a/brian2/only.py +++ b/brian2/only.py @@ -5,6 +5,7 @@ Usage: ``from brian2.only import *`` """ + # To minimize the problems with imports, import the packages in a sensible # order diff --git a/brian2/parsing/bast.py b/brian2/parsing/bast.py index 682590c23..e3debcc60 100644 --- a/brian2/parsing/bast.py +++ b/brian2/parsing/bast.py @@ -3,6 +3,7 @@ This is a standard Python AST representation with additional information added. """ + import ast import weakref diff --git a/brian2/parsing/expressions.py b/brian2/parsing/expressions.py index 559532422..2003ef4a7 100644 --- a/brian2/parsing/expressions.py +++ b/brian2/parsing/expressions.py @@ -1,6 +1,7 @@ """ AST parsing based analysis of expressions """ + import ast from brian2.core.functions import Function diff --git a/brian2/parsing/rendering.py b/brian2/parsing/rendering.py index 20542a81a..122311df5 100644 --- a/brian2/parsing/rendering.py +++ b/brian2/parsing/rendering.py @@ -103,9 +103,7 @@ def render_Call(self, node): args = node.args + [vectorisation_idx] else: args = node.args - return ( - f"{self.render_func(node.func)}({', '.join(self.render_node(arg) for arg in args)})" - ) + return f"{self.render_func(node.func)}({', '.join(self.render_node(arg) for arg in args)})" def render_element_parentheses(self, node): """ @@ -162,9 +160,7 @@ def render_Compare(self, node): ) def render_UnaryOp(self, node): - return ( - f"{self.expression_ops[node.op.__class__.__name__]} {self.render_element_parentheses(node.operand)}" - ) + return f"{self.expression_ops[node.op.__class__.__name__]} {self.render_element_parentheses(node.operand)}" def render_Assign(self, node): if len(node.targets) > 1: diff --git a/brian2/spatialneuron/morphology.py b/brian2/spatialneuron/morphology.py index 55c88ad02..9063c1fb9 100644 --- a/brian2/spatialneuron/morphology.py +++ b/brian2/spatialneuron/morphology.py @@ -2,6 +2,7 @@ Neuronal morphology module. This module defines classes to load and build neuronal morphologies. """ + import abc import numbers import os @@ -1988,10 +1989,7 @@ def area(self): d_1 = self.start_diameter d_2 = self.end_diameter return ( - np.pi - / 2 - * (d_1 + d_2) - * np.sqrt(((d_1 - d_2) ** 2) / 4 + self._length**2) + np.pi / 2 * (d_1 + d_2) * np.sqrt(((d_1 - d_2) ** 2) / 4 + self._length**2) ) @property diff --git a/brian2/spatialneuron/spatialneuron.py b/brian2/spatialneuron/spatialneuron.py index 609509216..f23840629 100644 --- a/brian2/spatialneuron/spatialneuron.py +++ b/brian2/spatialneuron/spatialneuron.py @@ -3,6 +3,7 @@ This module defines the `SpatialNeuron` class, which defines multicompartmental models. """ + import copy import weakref diff --git a/brian2/sphinxext/briandoc.py b/brian2/sphinxext/briandoc.py index a9adbc5fc..e1a398b5e 100644 --- a/brian2/sphinxext/briandoc.py +++ b/brian2/sphinxext/briandoc.py @@ -16,6 +16,7 @@ .. [1] https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt """ + import inspect import pydoc import re diff --git a/brian2/sphinxext/docscrape.py b/brian2/sphinxext/docscrape.py index fb5ba793f..98ecdbcc5 100644 --- a/brian2/sphinxext/docscrape.py +++ b/brian2/sphinxext/docscrape.py @@ -2,7 +2,6 @@ """ - import inspect import pydoc import re diff --git a/brian2/sphinxext/examplefinder.py b/brian2/sphinxext/examplefinder.py index 193837989..038b3a301 100644 --- a/brian2/sphinxext/examplefinder.py +++ b/brian2/sphinxext/examplefinder.py @@ -2,7 +2,6 @@ Automatically find examples of a Brian object or function. """ - import os from collections import defaultdict diff --git a/brian2/sphinxext/generate_reference.py b/brian2/sphinxext/generate_reference.py index 0fc28297b..081d068c8 100644 --- a/brian2/sphinxext/generate_reference.py +++ b/brian2/sphinxext/generate_reference.py @@ -4,7 +4,6 @@ Based on sphinx-apidoc, published under a BSD license: http://sphinx-doc.org/ """ - import inspect import os import sys diff --git a/brian2/stateupdaters/__init__.py b/brian2/stateupdaters/__init__.py index cba878a39..662d5cdca 100644 --- a/brian2/stateupdaters/__init__.py +++ b/brian2/stateupdaters/__init__.py @@ -2,6 +2,7 @@ Module for transforming model equations into "abstract code" that can be then be further translated into executable code by the `codegen` module. """ + from .base import * from .exact import * from .explicit import * diff --git a/brian2/stateupdaters/base.py b/brian2/stateupdaters/base.py index 95304c413..aaf1b9a60 100644 --- a/brian2/stateupdaters/base.py +++ b/brian2/stateupdaters/base.py @@ -4,6 +4,7 @@ return a suitable stateupdater object for a given set of equations. This is used for example in `NeuronGroup` when no state updater is given explicitly. """ + import time from abc import ABCMeta, abstractmethod from collections.abc import Iterable diff --git a/brian2/stateupdaters/explicit.py b/brian2/stateupdaters/explicit.py index 2616b6bd4..06f5a022c 100644 --- a/brian2/stateupdaters/explicit.py +++ b/brian2/stateupdaters/explicit.py @@ -1,6 +1,7 @@ """ Numerical integration functions. """ + import operator import string from functools import reduce diff --git a/brian2/synapses/synapses.py b/brian2/synapses/synapses.py index 9acce79e9..f443b264c 100644 --- a/brian2/synapses/synapses.py +++ b/brian2/synapses/synapses.py @@ -1,6 +1,7 @@ """ Module providing the `Synapses` class and related helper classes/functions. """ + import functools import numbers import re @@ -402,8 +403,7 @@ def initialise_queue(self): "it has not created synapses with 'connect'. " "Set its active attribute to False if you " "intend to do only do this for a subsequent" - " run." - % self.synapses.name + " run." % self.synapses.name ) # Update the dt (might have changed between runs) @@ -1639,8 +1639,7 @@ def connect( except IndexError as e: raise IndexError( "Tried to create synapse indices outside valid " - "range. Original error message: " - + str(e) + "range. Original error message: " + str(e) ) # Helper functions for Synapses.connect ↑ diff --git a/brian2/tests/__init__.py b/brian2/tests/__init__.py index 6e094f470..af8c2a3bf 100644 --- a/brian2/tests/__init__.py +++ b/brian2/tests/__init__.py @@ -1,6 +1,7 @@ """ Package contain all unit/integration tests for the `brian2` package. """ + import os import sys import tempfile @@ -68,9 +69,9 @@ def pytest_configure_node(self, node): if isinstance(v, type): prefs[k] = ("TYPE", repr(v)) node.workerinput["brian_prefs"] = prefs - node.workerinput[ - "fail_for_not_implemented" - ] = self._pref_plugin.fail_for_not_implemented + node.workerinput["fail_for_not_implemented"] = ( + self._pref_plugin.fail_for_not_implemented + ) node.workerinput["device"] = self._pref_plugin.device node.workerinput["device_options"] = self._pref_plugin.device_options diff --git a/brian2/tests/features/base.py b/brian2/tests/features/base.py index d8a830419..1f19da868 100644 --- a/brian2/tests/features/base.py +++ b/brian2/tests/features/base.py @@ -560,12 +560,12 @@ def run_speed_tests( suffixtime[suffix] += proftime overheadstime -= float(proftime) for suffix, proftime in list(suffixtime.items()): - full_results[ - configuration.name, ft.fullname(), n, suffix - ] = proftime - full_results[ - configuration.name, ft.fullname(), n, "Overheads" - ] = overheadstime + full_results[configuration.name, ft.fullname(), n, suffix] = ( + proftime + ) + full_results[configuration.name, ft.fullname(), n, "Overheads"] = ( + overheadstime + ) if verbose: print("]", end=" ") if verbose: diff --git a/brian2/tests/features/input.py b/brian2/tests/features/input.py index 2fdba5ef6..f23215aa5 100644 --- a/brian2/tests/features/input.py +++ b/brian2/tests/features/input.py @@ -2,7 +2,6 @@ Tests of input features """ - from brian2 import * from brian2.tests.features import FeatureTest, InaccuracyError diff --git a/brian2/tests/features/monitors.py b/brian2/tests/features/monitors.py index 27ee341df..e4f46f27f 100644 --- a/brian2/tests/features/monitors.py +++ b/brian2/tests/features/monitors.py @@ -2,7 +2,6 @@ Check that various monitors work correctly. """ - from brian2 import * from brian2.tests.features import FeatureTest, InaccuracyError diff --git a/brian2/tests/features/synapses.py b/brian2/tests/features/synapses.py index baf9f8a8c..7b5c5ca32 100644 --- a/brian2/tests/features/synapses.py +++ b/brian2/tests/features/synapses.py @@ -1,6 +1,7 @@ """ Check that the features of `Synapses` are available and correct. """ + import numpy from brian2 import * diff --git a/brian2/tests/test_parsing.py b/brian2/tests/test_parsing.py index edcbf2119..dfe0f8271 100644 --- a/brian2/tests/test_parsing.py +++ b/brian2/tests/test_parsing.py @@ -400,6 +400,7 @@ def test_value_from_expression(): # This function is used to get the value of an exponent, necessary for unit checking constants = {"c": 3} + # dummy class class C: pass diff --git a/brian2/tests/test_spikegenerator.py b/brian2/tests/test_spikegenerator.py index 245d52549..50aa7f7d9 100644 --- a/brian2/tests/test_spikegenerator.py +++ b/brian2/tests/test_spikegenerator.py @@ -1,6 +1,7 @@ """ Tests for `SpikeGeneratorGroup` """ + import os import tempfile diff --git a/brian2/tests/test_synapses.py b/brian2/tests/test_synapses.py index c63232cdd..fd37f6145 100644 --- a/brian2/tests/test_synapses.py +++ b/brian2/tests/test_synapses.py @@ -2300,8 +2300,7 @@ def test_permutation_analysis(): raise AssertionError( "Test unexpectedly raised a numerical " "OrderDependenceError on these " - "statements:\n" - + example + "statements:\n" + example ) try: check_permutation_code(example) @@ -2309,8 +2308,7 @@ def test_permutation_analysis(): raise AssertionError( "Test unexpectedly raised an " "OrderDependenceError on these " - "statements:\n" - + example + "statements:\n" + example ) for example in permutation_analysis_bad_examples: diff --git a/brian2/tests/test_units.py b/brian2/tests/test_units.py index 9f138fa81..a6ed5b71a 100644 --- a/brian2/tests/test_units.py +++ b/brian2/tests/test_units.py @@ -697,9 +697,7 @@ def test_power(): for value in values: assert_quantity(value**3, np.asarray(value) ** 3, kilogram**3) # Test raising to a dimensionless quantity - assert_quantity( - value ** (3 * volt / volt), np.asarray(value) ** 3, kilogram**3 - ) + assert_quantity(value ** (3 * volt / volt), np.asarray(value) ** 3, kilogram**3) with pytest.raises(DimensionMismatchError): # FIXME: Not that if float(exponent) is a special value such as 1 or 2 # numpy will actually use a ufunc such as identity or square, which will diff --git a/brian2/units/allunits.py b/brian2/units/allunits.py index aaa487801..3f2ebfc13 100644 --- a/brian2/units/allunits.py +++ b/brian2/units/allunits.py @@ -6,6 +6,7 @@ dev/tools/static_codegen/units_template.py """ + # fmt: off # flake8: noqa import itertools diff --git a/brian2/units/fundamentalunits.py b/brian2/units/fundamentalunits.py index d850539ef..c5e37bdd8 100644 --- a/brian2/units/fundamentalunits.py +++ b/brian2/units/fundamentalunits.py @@ -1879,6 +1879,7 @@ class Unit(Quantity): 3. * joule """ + __slots__ = ["dim", "scale", "_dispname", "_name", "_latexname", "iscompound"] __array_priority__ = 100 diff --git a/brian2/utils/environment.py b/brian2/utils/environment.py index 9e6eff3ee..8a54c997e 100644 --- a/brian2/utils/environment.py +++ b/brian2/utils/environment.py @@ -1,6 +1,7 @@ """ Utility functions to get information about the environment Brian is running in. """ + import builtins diff --git a/brian2/utils/filetools.py b/brian2/utils/filetools.py index 04ff23d3d..2d8696905 100644 --- a/brian2/utils/filetools.py +++ b/brian2/utils/filetools.py @@ -2,7 +2,6 @@ File system tools """ - import os __all__ = [ diff --git a/brian2/utils/stringtools.py b/brian2/utils/stringtools.py index 0034cd0f7..a2d8928b7 100644 --- a/brian2/utils/stringtools.py +++ b/brian2/utils/stringtools.py @@ -1,6 +1,7 @@ """ A collection of tools for string formatting tasks. """ + import re import string From b70488cde5f65c14ebcfd409884d22dd331d2bd9 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Wed, 13 Mar 2024 17:08:34 +0100 Subject: [PATCH 4/4] Ignore previous commit for git blame --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 82bd438fb..54b799673 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -14,3 +14,5 @@ 28b02c51545298cb9a76d8295e64a5df391b9207 # Fix a number of issues flagged by flake8 0344b005e6ffd232f55e69621630ef01876bc0fb +# Update to black 24.2.0 and isort 5.13.2 +0d015a50d641edc7709bd89e0ed389e54f1dcab0