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

Prevent inadvertent attribute assignment in Quantity #1124

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ class Quantity:
>>> q3.P
101325.0
"""
__slots__ = ("state", "_phase", "_id", "mass", "constant")

def __init__(self, phase, mass=None, moles=None, constant='UV'):
self.state = phase.TDY
self._phase = phase
Expand Down
5 changes: 5 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,11 @@ def test_equilibrate(self):
q1.equilibrate('HP')
self.assertNear(q1.T, T2)

def test_invalid_setter(self):
q1 = ct.Quantity(self.gas, mass =3)
with self.assertRaises(AttributeError):
q1.HPQ = self.gas.H, self.gas.P, 1

def test_incompatible(self):
gas2 = ct.Solution('h2o2.yaml', transport_model=None)
q1 = ct.Quantity(self.gas)
Expand Down