Skip to content

Allow passing of Python objects in the parameters dict - #41

Merged
connorjward merged 12 commits into
mainfrom
connorjward/appctx-auto
Aug 26, 2026
Merged

connorjward merged 12 commits into
mainfrom
connorjward/appctx-auto

Conversation

@connorjward

Copy link
Copy Markdown
Collaborator

We build an appctx manager under the hood to coordinate things.

We build an appctx manager under the hood to coordinate things.
@connorjward
connorjward requested a review from JHopeCollins July 15, 2026 10:17
Comment thread petsctools/options.py Outdated

@JHopeCollins JHopeCollins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is much more ergonomic. Is there a benefit to still allowing passing an AppContextManager? Could we just make this an internal detail and have One True Way of passing python types?

@connorjward

Copy link
Copy Markdown
Collaborator Author

This is much more ergonomic. Is there a benefit to still allowing passing an AppContextManager? Could we just make this an internal detail and have One True Way of passing python types?

You make a good point. I was torn as to whether we still want the class around. It is a nice abstraction but I think I agree that we should make it purely internal. Will do.

@connorjward
connorjward force-pushed the connorjward/appctx-auto branch from 607d872 to e7aee2b Compare July 21, 2026 20:19
@connorjward

Copy link
Copy Markdown
Collaborator Author

@JHopeCollins I think I'm now happy with this.

@JHopeCollins

JHopeCollins commented Aug 24, 2026

Copy link
Copy Markdown
Member

Really really nice. Big fan.

Will go through in more detail, but at a first pass one thing that jumps out is that we should override Options.__additem__ in case someone tries to do the following:

petsctools.Options["key"] = python_object

The easy thing is just to disallow it because there's no way to associate an AppContextManager. Unless we think it would be safe to just stick it into the global appctx dictionary...

@connorjward

Copy link
Copy Markdown
Collaborator Author

Really really nice. Big fan.

Will go through in more detail, but at a first pass one thing that jumps out is that we should override Options.__additem__ in case someone tries to do the following:

petsctools.Options["key"] = python_object

The easy thing is just to disallow it because there's no way to associate an AppContextManager. Unless we think it would be safe to just stick it into the global appctx dictionary...

I think inserting it into the global appctx dictionary would be the right thing to do

Comment thread petsctools/options.py Outdated

@JHopeCollins JHopeCollins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other than some docstring updates this looks great.

Comment thread tests/test_options.py
Comment thread tests/test_options.py Outdated
Comment thread petsctools/options.py
Comment thread petsctools/options.py
Comment thread petsctools/options.py
Comment thread petsctools/options.py Outdated
Comment thread petsctools/options.py Outdated
* Move appctx code for readability
* Add __setitem__ and __delitem__ and tests
@connorjward

Copy link
Copy Markdown
Collaborator Author

Really really nice. Big fan.
Will go through in more detail, but at a first pass one thing that jumps out is that we should override Options.__additem__ in case someone tries to do the following:

petsctools.Options["key"] = python_object

The easy thing is just to disallow it because there's no way to associate an AppContextManager. Unless we think it would be safe to just stick it into the global appctx dictionary...

I think inserting it into the global appctx dictionary would be the right thing to do

I've just added __setitem__ and __delitem__ plus tests for them.

@JHopeCollins JHopeCollins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should fix the CI errors, then this is good to go

Comment thread tests/test_options.py
Comment thread petsctools/__init__.py
@connorjward

Copy link
Copy Markdown
Collaborator Author

Sweet. I'll push it through from here. Thanks for all the reviews!

@connorjward
connorjward merged commit 2f81589 into main Aug 26, 2026
2 checks passed
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.

2 participants