Skip to content

Fix isinstance checks in Temperature arithmetic operators - #571

Merged
lohedges merged 1 commit into
OpenBioSim:develfrom
chenyangsu:fix/temperature-arithmetic-isinstance
Nov 27, 2026
Merged

lohedges merged 1 commit into
OpenBioSim:develfrom
chenyangsu:fix/temperature-arithmetic-isinstance

Conversation

@chenyangsu

Copy link
Copy Markdown
Contributor

If this is to fix a bug...

Temperature(300.0, "K") + Temperature(10.0, "K"), Temperature(300.0, "K") - Temperature(10.0, "K"), and Temperature(25.0, "C") / Temperature(5.0, "C") (with allow_offset = True) raise TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union, because Temperature.__add__, __sub__, and __truediv__ check isinstance(other, self) instead of isinstance(other, type(self)) (unlike the base Type class in _type.py, which checks type(other) is type(self)).

The fix updates those three checks to isinstance(other, type(self)) in both BioSimSpace/Types/_temperature.py and Sandpit/Exscientia/Types/_temperature.py, and adds test_temperature_arithmetic to both test_types.py suites. Happy to use type(other) is type(self) to match _type.py if you prefer.

  • I confirm that I have merged the latest version of devel into this branch before issuing this pull request (e.g. by running git pull origin devel): [y]
  • I confirm that I have permission to release this code under the GPL3 license: [y]

Suggested reviewers:

@lohedges, @chryswoods

Any additional context of information?

Testing: ran tests/Types/test_types.py and tests/Sandpit/Exscientia/Types/test_types.py against a minimal sire.legacy.Units stub locally since sire is not installed in this environment (12 passed; both new tests failed with TypeError before the fix); ruff check and ruff format --check clean.

@lohedges

Copy link
Copy Markdown
Contributor

Many thanks. I've triggered the CI.

@lohedges lohedges added the bug Something isn't working label Nov 27, 2026
@lohedges
lohedges self-requested a review November 27, 2026 09:45

@lohedges lohedges left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I'll sort out the inconsistencies in the comparisons on devel since they are present in a few other places too.

@lohedges
lohedges merged commit 2b41eea into OpenBioSim:devel Nov 27, 2026
5 checks passed

This branch was previously deployed

1 inactive deployment
biosimspace-build — 4321fc49 Deployed Nov 27, 2026 by chenyangsu via build (3.13, linux) #420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants