Skip to content

Prevent inadvertent attribute assignment in Quantity#1124

Merged
ischoegl merged 1 commit intoCantera:mainfrom
speth:fix-1093
Oct 19, 2021
Merged

Prevent inadvertent attribute assignment in Quantity#1124
ischoegl merged 1 commit intoCantera:mainfrom
speth:fix-1093

Conversation

@speth
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

Copy link
Copy Markdown
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