Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Make plum work with ipython's autoreload #38

Closed
PhilipVinc opened this issue Feb 8, 2022 · 5 comments
Closed

FR: Make plum work with ipython's autoreload #38

PhilipVinc opened this issue Feb 8, 2022 · 5 comments

Comments

@PhilipVinc
Copy link
Collaborator

The two don't work well together.
I think it's because autoreload changes the classes of objects, but for some reason forgets to update the Types in plum's dispatch tables.

Should be investigated...

@wesselb
Copy link
Member

wesselb commented Feb 8, 2022

This is a good suggestion! I unfortunately currently do not have the bandwidth to investigate this in the short term, but will definitely keep it in mind.

@wesselb
Copy link
Member

wesselb commented Jun 4, 2022

Also tagging @seeM here.

This issue is unfortunately a tricky one to fix. Just to document what's going wrong, here's a minimal example.

Consider the minimal module

from __future__ import annotations


class A:
    def test(self) -> A:
        # Hello
        return self

We now have the following behaviour:

In [1]: from core import A

In [2]: from typing import get_type_hints

In [3]: get_type_hints(A.test)["return"] == A
Out[3]: True

In [4]: # Make changes and trigger autoreload

In [5]: get_type_hints(A.test)["return"] == A
Out[5]: False

(This is on Python 3.9.)

I think it's necessary to carefully pin down how get_type_hints interacts with autoreload, especially with regards to forwards references.

If this particular case can be fixed, I think good support for autoreload in the case of from __future__ import annotations should be possible.

@PhilipVinc
Copy link
Collaborator Author

I had investigated the issue a bit, and eventually realized that the best course of action would be for someone to contact the developers of iPython to ask them to add an hook to auto reload so that when he reloads a class/files plugins can ask to be notified about it.

@wesselb
Copy link
Member

wesselb commented Jun 6, 2022

@PhilipVinc That's interesting. I suppose hooking into autoreload would be the way go about this: upon every autoreload, clear all cache.

I'm wondering, is the above example expected behaviour? Should get_type_hints(A.test)["return"] == A after autoreloading? The locals in an iPython sessions should be updated with every autoreload, right?

Perhaps not relevant to this issue, but I'm tempted to strip out all current functionality to handle forward references from the package and just rely on typing.get_type_hints to handle forward references. What are your thoughts on this?

@wesselb
Copy link
Member

wesselb commented Jun 9, 2022

Experimental support thanks to #44 by @PhilipVinc is included in the latest release v1.6. :)

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

No branches or pull requests

2 participants