Skip to content

Hack in SimpleNamespace-like functionality to Options#7347

Merged
mergify[bot] merged 3 commits into
Qiskit:mainfrom
jakelishman:fix/options-simplenamespace
Dec 2, 2021
Merged

Hack in SimpleNamespace-like functionality to Options#7347
mergify[bot] merged 3 commits into
Qiskit:mainfrom
jakelishman:fix/options-simplenamespace

Conversation

@jakelishman
Copy link
Copy Markdown
Member

@jakelishman jakelishman commented Dec 2, 2021

Summary

This is an awful hack to support various SimpleNamespace-like operations
that qiskit-experiments are using. We need to transition downstream
packages to the new Options API, but in the meantime, this makes the
Options class behave as much like a SimpleNamespace as it can, while
still keeping the new instance attributes and methods.

Details and comments

This passes the qiskit-experiments tests on my machine. The real problem is how qiskit-experiments accesses options.__dict__, so this involves some terrible behaviour to make that work as expected.

It's an absolutely horrific hack, and I regret ever learning Python.

@eggerdj - this passes the tests on my machine, but could you check it does everything you need as well?

This is an awful hack to support various SimpleNamespace-like operations
that qiskit-dynamics are using.  We need to transition downstream
packages to the new Options API, but in the meantime, this makes the
Options class behave as much like a SimpleNamespace as it can, while
still keeping the new instance attributes and methods.
@jakelishman jakelishman requested review from a team, chriseclectic and jyu00 as code owners December 2, 2021 19:44
@mtreinish mtreinish added Changelog: None Do not include in the GitHub Release changelog. priority: high labels Dec 2, 2021
@mtreinish mtreinish added this to the 0.19 milestone Dec 2, 2021
mtreinish
mtreinish previously approved these changes Dec 2, 2021
Copy link
Copy Markdown
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, thanks for figuring all these hairy things out. Before we tag it automerge and put it in the merge queue though we should verify it works for qiskit-experiments. @eggerdj @nkanazawa1989 @chriseclectic if you could test this that would be great.

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 2, 2021

Pull Request Test Coverage Report for Build 1532598027

  • 16 of 16 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 83.089%

Totals Coverage Status
Change from base Build 1532511696: 0.003%
Covered Lines: 51444
Relevant Lines: 61914

💛 - Coveralls

chriseclectic
chriseclectic previously approved these changes Dec 2, 2021
Copy link
Copy Markdown
Member

@chriseclectic chriseclectic left a comment

Choose a reason for hiding this comment

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

I ran qiskit-experiments tests locally with this branch and had no failures

I was surprised at how little pylint complained about the actual
implementation, but it complains about the usage.

This could conceivably be called a pylint bug; because we override
`__setattr__`, pylint should perhaps recognise that general attribute
setting might be allowed.
@jakelishman jakelishman dismissed stale reviews from chriseclectic and mtreinish via d6ab60f December 2, 2021 21:14
Comment thread test/python/providers/test_options.py Outdated
@jakelishman
Copy link
Copy Markdown
Member Author

jakelishman commented Dec 2, 2021

It's possible that qiskit-experiments' CI may fail after this on the linting stage with pylint's assigning-non-slot. If so, you may want to consider just temporarily suppressing that warning; to some degree, it's kind of a pylint bug, because I overrode __setattr__ to make the assignments work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: None Do not include in the GitHub Release changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants