From a7e0244bd8ece5c1ea2c6a943d5d002f4427f25a Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 10 Nov 2025 15:55:43 -0700 Subject: [PATCH 1/5] apply E741: ambiguous variable name check --- .../protocols/openmm_afe/equil_binding_afe_method.py | 2 +- .../openmm_afe/equil_solvation_afe_method.py | 2 +- openfe/setup/ligand_network_planning.py | 6 +++--- openfe/tests/setup/test_network_planning.py | 8 ++++---- openfe/utils/system_probe.py | 2 +- openfecli/utils.py | 12 ++++++------ pyproject.toml | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/openfe/protocols/openmm_afe/equil_binding_afe_method.py b/openfe/protocols/openmm_afe/equil_binding_afe_method.py index 1dc1231f7..dc12f1a8e 100644 --- a/openfe/protocols/openmm_afe/equil_binding_afe_method.py +++ b/openfe/protocols/openmm_afe/equil_binding_afe_method.py @@ -727,7 +727,7 @@ def _validate_lambda_schedule( lambda_components = [lambda_vdw, lambda_elec, lambda_restraints] it = iter(lambda_components) the_len = len(next(it)) - if not all(len(l) == the_len for l in it): + if not all(len(lambda_comp) == the_len for lambda_comp in it): errmsg = ( "Components elec, vdw, and restraints must have equal amount" f" of lambda windows. Got {len(lambda_elec)} elec lambda" diff --git a/openfe/protocols/openmm_afe/equil_solvation_afe_method.py b/openfe/protocols/openmm_afe/equil_solvation_afe_method.py index dc56e13bb..4ffb94770 100644 --- a/openfe/protocols/openmm_afe/equil_solvation_afe_method.py +++ b/openfe/protocols/openmm_afe/equil_solvation_afe_method.py @@ -619,7 +619,7 @@ def _validate_lambda_schedule( lambda_components = [lambda_vdw, lambda_elec, lambda_restraints] it = iter(lambda_components) the_len = len(next(it)) - if not all(len(l) == the_len for l in it): + if not all(len(lambda_comp) == the_len for lambda_comp in it): errmsg = ( "Components elec, vdw, and restraints must have equal amount" f" of lambda windows. Got {len(lambda_elec)} elec lambda" diff --git a/openfe/setup/ligand_network_planning.py b/openfe/setup/ligand_network_planning.py index a002c35d0..4643349f8 100644 --- a/openfe/setup/ligand_network_planning.py +++ b/openfe/setup/ligand_network_planning.py @@ -406,8 +406,8 @@ def load_orion_network( with open(network_file, "r") as f: network_lines = [ - l.strip().split(" ") for l in f - if not l.startswith("#") + line.strip().split(" ") for line in f + if not line.startswith("#") ] # fmt: skip names = [] @@ -451,7 +451,7 @@ def load_fepplus_network( """ with open(network_file, "r") as f: - network_lines = [l.split() for l in f.readlines()] + network_lines = [line.split() for line in f.readlines()] names = [] for entry in network_lines: diff --git a/openfe/tests/setup/test_network_planning.py b/openfe/tests/setup/test_network_planning.py index d63bd7880..0449b0985 100644 --- a/openfe/tests/setup/test_network_planning.py +++ b/openfe/tests/setup/test_network_planning.py @@ -691,7 +691,7 @@ def test_network_from_external(file_fixture, loader, request, benzene_modificati network_file = request.getfixturevalue(file_fixture) network = loader( - ligands=[l for l in benzene_modifications.values()], + ligands=[lig for lig in benzene_modifications.values()], mapper=openfe.LomapAtomMapper(), network_file=network_file, ) @@ -721,7 +721,7 @@ def test_network_from_external(file_fixture, loader, request, benzene_modificati ) def test_network_from_external_unknown_edge(file_fixture, loader, request, benzene_modifications): network_file = request.getfixturevalue(file_fixture) - ligands = [l for l in benzene_modifications.values() if l.name != "phenol"] + ligands = [lig for lig in benzene_modifications.values() if lig.name != "phenol"] with pytest.raises(KeyError, match="Invalid name"): _ = loader( @@ -750,7 +750,7 @@ def test_bad_orion_network(benzene_modifications, tmpdir): with pytest.raises(KeyError, match="line does not match"): _ = openfe.setup.ligand_network_planning.load_orion_network( - ligands=[l for l in benzene_modifications.values()], + ligands=[lig for lig in benzene_modifications.values()], mapper=openfe.LomapAtomMapper(), network_file="bad_orion_net.dat", ) @@ -773,7 +773,7 @@ def test_bad_edges_network(benzene_modifications, tmpdir): with pytest.raises(KeyError, match="line does not match"): _ = openfe.setup.ligand_network_planning.load_fepplus_network( - ligands=[l for l in benzene_modifications.values()], + ligands=[lig for lig in benzene_modifications.values()], mapper=openfe.LomapAtomMapper(), network_file="bad_edges.edges", ) diff --git a/openfe/utils/system_probe.py b/openfe/utils/system_probe.py index c7f5ad625..bb2b2cf7a 100644 --- a/openfe/utils/system_probe.py +++ b/openfe/utils/system_probe.py @@ -513,7 +513,7 @@ def log_system_probe(level=logging.DEBUG, paths: Optional[Iterable[os.PathLike]] gpu = logging.getLogger(basename + ".gpu") hostname = logging.getLogger(basename + ".hostname") loggers = [base, gpu, hostname] - if any(l.isEnabledFor(level) for l in loggers): + if any(logger.isEnabledFor(level) for logger in loggers): sysinfo = _probe_system(pl_paths)["system information"] base.log(level, "SYSTEM CONFIG DETAILS:") hostname.log(level, f"hostname: '{sysinfo['hostname']}'") diff --git a/openfecli/utils.py b/openfecli/utils.py index a84a53b03..6e7570c83 100644 --- a/openfecli/utils.py +++ b/openfecli/utils.py @@ -58,15 +58,15 @@ def _should_configure_logger(logger: logging.Logger): return False # walk up the logging tree to see if any parent loggers are not default - l = logger + _logger = logger while ( - l.parent is not None # not the root logger - and l.level == logging.NOTSET # level not already set - and l.propagate # configured to use parent when not set + _logger.parent is not None # not the root logger + and _logger.level == logging.NOTSET # level not already set + and _logger.propagate # configured to use parent when not set ): - l = l.parent + _logger = _logger.parent - is_default = (l == logging.root and l.level == logging.WARNING) # fmt: skip + is_default = (_logger == logging.root and _logger.level == logging.WARNING) # fmt: skip return is_default diff --git a/pyproject.toml b/pyproject.toml index be9bc4404..e2fb13b6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ lint.select = [ "F", # Pyflakes "I", # isort "W", # pycodestyle warnings - # "E", # pycodestyle errors + "E", # pycodestyle errors # "C901" # mccabe complexity TODO: add this back in # "UP", # TODO: add this in ] From 2b419bebad853eeb30c6e8d3430632af3819aced Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 10 Nov 2025 16:00:15 -0700 Subject: [PATCH 2/5] apply E713: 'not in' fixes --- openfe/__init__.py | 4 ++-- openfe/utils/logging_filter.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openfe/__init__.py b/openfe/__init__.py index 1eee631d0..48c17f850 100644 --- a/openfe/__init__.py +++ b/openfe/__init__.py @@ -3,11 +3,11 @@ def _mute_timeseries(record): - return not "Warning on use of the timeseries module:" in record.msg + return "Warning on use of the timeseries module:" not in record.msg def _mute_jax(record): - return not "****** PyMBAR will use 64-bit JAX! *******" in record.msg + return "****** PyMBAR will use 64-bit JAX! *******" not in record.msg _mbar_log = logging.getLogger("pymbar.timeseries") diff --git a/openfe/utils/logging_filter.py b/openfe/utils/logging_filter.py index 9336433d6..63d22a95b 100644 --- a/openfe/utils/logging_filter.py +++ b/openfe/utils/logging_filter.py @@ -17,4 +17,4 @@ def __init__(self, string): self.string = string def filter(self, record): - return not self.string in record.msg + return self.string not in record.msg From 5b4d523a5d9b3ff59dcb3b551de0f1672faafa37 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 10 Nov 2025 16:03:22 -0700 Subject: [PATCH 3/5] address E721 with isintance() checks --- openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py b/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py index a288783b0..c24f898c3 100644 --- a/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py +++ b/openfe/protocols/openmm_rfe/_rfe_utils/lambdaprotocol.py @@ -103,9 +103,9 @@ def __init__(self, functions='default', windows=10, lambda_schedule=None): else: self.lambda_schedule = np.linspace(0., 1., windows) - if type(self.functions) == dict: + if isinstance(self.functions, dict): self.type = 'user-defined' - elif type(self.functions) == str: + elif isinstance(self.functions, str): self.functions = None # will be set later self.type = functions From e32cd8082052c5ceeae760f29e1c2d2c9a5aa666 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 10 Nov 2025 16:20:09 -0700 Subject: [PATCH 4/5] fix bare excepts --- openfe/tests/conftest.py | 3 ++- openfecli/tests/conftest.py | 3 ++- pyproject.toml | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openfe/tests/conftest.py b/openfe/tests/conftest.py index 49a3288bc..d0012b822 100644 --- a/openfe/tests/conftest.py +++ b/openfe/tests/conftest.py @@ -2,6 +2,7 @@ # For details, see https://github.com/OpenFreeEnergy/openfe import os import pathlib +import urllib.error import urllib.request from importlib import resources @@ -361,7 +362,7 @@ def am1bcc_ref_charges(): try: urllib.request.urlopen("https://www.google.com") -except: # -no-cov- +except urllib.error.URLError: # -no-cov- HAS_INTERNET = False else: HAS_INTERNET = True diff --git a/openfecli/tests/conftest.py b/openfecli/tests/conftest.py index d5ea7119d..889f6f278 100644 --- a/openfecli/tests/conftest.py +++ b/openfecli/tests/conftest.py @@ -1,8 +1,9 @@ +import urllib.error import urllib.request try: urllib.request.urlopen("https://www.google.com") -except: # -no-cov- +except urllib.error.URLError: # -no-cov- HAS_INTERNET = False else: HAS_INTERNET = True diff --git a/pyproject.toml b/pyproject.toml index e2fb13b6b..08b5bdb33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,8 +61,7 @@ lint.select = [ ] lint.ignore = [ "E402", # module-level import not at top (conflicts w/ isort) - "E722", # bare excepts (TODO: we should fix these in a follow-up PR) - "E731", # lambda expressions (TODO: we should fix these) + "E501", # line length too long, resolve this for comments "F401", # unused imports (TODO: we should fix these) "F811", "F841", From 42b60984ed2d3c2bcc3a76419cfa3bc5311ab887 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 10 Nov 2025 17:46:20 -0700 Subject: [PATCH 5/5] precommit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 08b5bdb33..784d16912 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,10 +52,10 @@ line-length = 100 # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. lint.select = [ + "E", # pycodestyle errors "F", # Pyflakes "I", # isort "W", # pycodestyle warnings - "E", # pycodestyle errors # "C901" # mccabe complexity TODO: add this back in # "UP", # TODO: add this in ]