From 882149f0a174980be2aed78dea3589bbc5923c35 Mon Sep 17 00:00:00 2001 From: Ryan Kingsbury Date: Sat, 13 Jan 2024 13:26:16 -0500 Subject: [PATCH] Solution.__add__: fix static reference to class; linting --- CHANGELOG.md | 5 +++++ src/pyEQL/solution.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 688eef3f..69072c9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- `Solution.__add_`: Bugfix in the addition operation `+` that could cause problems with + child classes (i.e., classes that inherit from `Solution`) to work improperly + ### Changed - Removed deprecated `pkg_resources` import in favor of `importlib.resources` diff --git a/src/pyEQL/solution.py b/src/pyEQL/solution.py index d058e788..3861600a 100644 --- a/src/pyEQL/solution.py +++ b/src/pyEQL/solution.py @@ -10,8 +10,8 @@ import math import os import warnings -from importlib.resources import files from functools import lru_cache +from importlib.resources import files from pathlib import Path from typing import Any, Literal @@ -153,7 +153,7 @@ def __init__( if database is None: # load the default database, which is a JSONStore db_store = IonDB - elif isinstance(database, (str, Path)): + elif isinstance(database, str | Path): db_store = JSONStore(str(database), key="formula") logger.info(f"Created maggma JSONStore from .json file {database}") else: @@ -2513,7 +2513,7 @@ def __add__(self, other: Solution): mix_pE = -math.log10((mol_e_self + mol_e_other) / mix_vol.to("L").magnitude) # create a new solution - return Solution( + return self.__class__( mix_species.data, # pass a regular dict instead of the FormulaDict volume=str(mix_vol), pressure=str(mix_pressure),