ipython / ipython/ipython

`autoreload 3` breaks with pydantic models

Open
#14,841 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

```
[autoreload of browser.library failed: Traceback (most recent call last):
File "/Users/mike/.cache/uv/archive-v0/kNbXlZ4I7_k672roqpeO9/lib/python3.13/site-packages/IPython/extensions/autoreload.py", line 278, in check
superreload(m, reload, self.old_objects, self.shell)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/mike/.cache/uv/archive-v0/kNbXlZ4I7_k672roqpeO9/lib/python3.13/site-packages/IPython/extensions/autoreload.py", line 508, in superreload
update_generic(old_obj, new_obj)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/Users/mike/.cache/uv/archive-v0/kNbXlZ4I7_k672roqpeO9/lib/python3.13/site-packages/IPython/extensions/autoreload.py", line 405, in update_generic
update(a, b)
~~~~~~^^^^^^
File "/Users/mike/.cache/uv/archive-v0/kNbXlZ4I7_k672roqpeO9/lib/python3.13/site-packages/IPython/extensions/autoreload.py", line 343, in update_class
if (old_obj == new_obj) is True:
^^^^^^^^^^^^^^^^^^
File "", line 838, in __eq__
File "", line 898, in __iter__
File "/Users/mike/.cache/uv/archive-v0/kNbXlZ4I7_k672roqpeO9/lib/python3.13/site-packages/pydantic/_internal/_mock_val_ser.py", line 47, in __iter__
return self._get_built().__iter__()
~~~~~~~~~~~~~~~^^
File "/Users/mike/.cache/uv/archive-v0/kNbXlZ4I7_k672roqpeO9/lib/python3.13/site-packages/pydantic/_internal/_mock_val_ser.py", line 58, in _get_built
raise PydanticUserError(self._error_message, code=self._code)
pydantic.errors.PydanticUserError: Pydantic models should inherit from BaseModel, BaseModel cannot be instantiated directly

For further information visit https://errors.pydantic.dev/2.10/u/base-model-instantiated
]
```

however, `autoreload 2` works fine. Ideally, we could catch this specific case so it doesn't break the autoreload functionality and just throws a warning.

I'm happy to help with this problem via a PR, I'm just not sure the best way to handle it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.