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

Conversation

speth
Copy link
Member

@speth speth commented Oct 19, 2021

Changes proposed in this pull request

  • Add a 'slots' definition to the Quantity class so trying to set the state using a property that doesn't exist for a particular
    phase model (e.g. HPQ) will not fail silently

If applicable, fill in the issue number this pull request is fixing

Fixes #1093

If applicable, provide an example illustrating new features this pull request is introducing

gas = ct.Solution("h2o2.yaml")
q1 = ct.Quantity(gas, mass=1)
q1.HPQ = gas.H, gas.P, 1  # raises AttributeError

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

Add a '__slots__' definition to the Quantity class so trying to
set the state using a property that doesn't exist for a particular
phase model (e.g. HPQ) will not fail silently.

Fixes Cantera#1093
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

Looks good to me / verified that this works. But I haven't used this feature before myself, so it's probably a good idea if @bryanwweber would have a look also.

@bryanwweber
Copy link
Member

I likewise haven't used these features but it also LGTM. :shipit:

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

I guess someone needs to approve ...

@ischoegl ischoegl merged commit da9535a into Cantera:main Oct 19, 2021
@speth speth deleted the fix-1093 branch July 23, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cantera not throwing any error on the misuse of the attribute 'Q'
3 participants