You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know how to explain this one yet... but simply importing napari is changing/breaking something about pydantic.BaseModel. It may be doing many things, but the way I noticed it is that BaseModel signatures are breaking after napari is imported:
update: PySide2 is still not playing well with pydantic (or apparently anything that tries to dynamically update a class __signature__ attribute):
In [1]: frompydanticimportBaseModelIn [2]: importinspectIn [3]: classT(BaseModel):
...: x: int
...: y: str='sadf'
...:
# so far so goodIn [4]: inspect.signature(T)
Out[4]: <Signature (*, x: int, y: str='sadf') ->None>In [5]: importPySide2In [6]: inspect.signature(T)
Out[6]: <Signature (**data: typing.Any) ->None># ??# let's try that againIn [7]: classT(BaseModel):
...: x: int
...: y: str='sadf'
...:
In [8]: inspect.signature(T) # ???---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
<ipython-input-8-e75fbef4a311>in<module>---->1inspect.signature(T)
~/miniconda3/envs/napdev/lib/python3.8/inspect.pyinsignature(obj, follow_wrapped)
3091defsignature(obj, *, follow_wrapped=True):
3092"""Get a signature object for the passed callable."""->3093returnSignature.from_callable(obj, follow_wrapped=follow_wrapped)
30943095~/miniconda3/envs/napdev/lib/python3.8/inspect.pyinfrom_callable(cls, obj, follow_wrapped)
2840deffrom_callable(cls, obj, *, follow_wrapped=True):
2841"""Constructs Signature for the given callable object."""->2842return_signature_from_callable(obj, sigcls=cls,
2843follow_wrapper_chains=follow_wrapped)
2844~/miniconda3/envs/napdev/lib/python3.8/inspect.pyin_signature_from_callable(obj, follow_wrapper_chains, skip_bound_arg, sigcls)
2250ifsigisnotNone:
2251ifnotisinstance(sig, Signature):
->2252raiseTypeError(
2253'unexpected object {!r} in __signature__ '2254'attribute'.format(sig))
TypeError: unexpectedobject<pydantic.utils.ClassAttributeobjectat0x7fe9b925d4f0>in__signature__attribute
I say "still" because I thought this bug, was solved in PySide2 5.13.1... which is why we bumped our pyside requirement. This, however, seems to be a slightly different side of that old bug. need to dig deeper
The text was updated successfully, but these errors were encountered:
tlambert03
changed the title
napari is somehow breaking pydantic
~napari~ PySide2 conflicting with pydantic signatures
Feb 13, 2021
tlambert03
changed the title
~napari~ PySide2 conflicting with pydantic signatures
PySide2 conflicting with pydantic signatures
Feb 13, 2021
ok, some more details... this is really quite a mess. I'm still only kind of following here. but this patch in PySide2 describes their "fix" as follows:
It turned out that the mock tool of the unittest module wants to
write into a __signature__ attribute. We now allow this by implementing
a writable attribute that memorizes any written value.
I'm not sure, but it kinda seems like they're directly modifying how the __signature__ attribute is retrieved for everything? (seems atrocious, but maybe?)
pydantic, however, doesn't set the __signature__ attribute directly to an instance of inspect.Signature, but rather uses a descriptor object to hide the class signature on instances (they do this to fix the signature on callable instance). Apparently, when python then goes to get the class __signature__... pyside2 seems to have broken that descriptor "getter" and instead returns the descriptor class itself. what a mess.
For us, I think we might be able to work around this by undoing what pydantic does with their signature descriptor, and simply being aware that we might need to modify the signature (if desired) on callable object instances.
馃悰 Bug
I don't know how to explain this one yet... but simply importing napari is changing/breaking something aboutpydantic.BaseModel
. It may be doing many things, but the way I noticed it is that BaseModel signatures are breaking after napari is imported:update: PySide2 is still not playing well with pydantic (or apparently anything that tries to dynamically update a class
__signature__
attribute):I say "still" because I thought this bug, was solved in PySide2 5.13.1... which is why we bumped our pyside requirement. This, however, seems to be a slightly different side of that old bug. need to dig deeper
The text was updated successfully, but these errors were encountered: