replace DummyMod with a more robust ModuleType that supports a custom user_ns#14754
replace DummyMod with a more robust ModuleType that supports a custom user_ns#14754Carreau merged 3 commits intoipython:mainfrom
Conversation
|
FYI @jasongrout |
|
Looks like there are some test issues around pickling that need to be fixed; will get to those in a bit |
|
Looks like a bunch of the pickling issues in downstream tests are failing for unrelated reasons, and then there's another test that expects the string |
|
The failure in test_embed.py seems to be unrelated; I see it happening on another PR as well: https://github.com/ipython/ipython/actions/runs/13446531221/job/37572996725?pr=14753 |
All those are unrelated, and will be fixed with a new ipyparallel release. Don't worry about those. I think we can update ipykernel 6.x and 7 (not release), for test to allow for |
|
Let's try. |
What changes are proposed in this pull request?
Some IPython apps, such as the one used in Databricks, need to seed the shell with a custom user namespace before it is actually created. This means the main module used by ipython can’t be a normal ModuleType (which doesn’t support overwriting dict) but instead a custom “DummyMod”. DummyMod isn’t considered an instance of ModuleType, which can mess up tools like ipytest + pytest -- see, for example, pytest-dev/pytest#12965.
To fix, in this PR we create a helper function that generates a
ModuleTypesubclass on-the-fly and that uses the user namespace provided a priori as its__dict__. Note thatModuleType.__dict__is read-only, which is probably why IPython originally created DummyMod. To get around that, we create a__dict__property and use custom getters / setters to delegate to the user_ns we pass in.Searching around, it seems like
DummyMod/FakeModulemay have caused some pain points in the past, e.g. around pickling (#384, #112) -- still trying to determine if this change can help with that.How is this tested?
Manual + pre-merge