-
Notifications
You must be signed in to change notification settings - Fork 114
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
typechecked
in a Jupyter notebook / IPython always triggers TypeError: <module '__main__'> is a built-in module
#364
Comments
typechecked
in a Jupyter notebook always triggers TypeError: <module '__main__'> is a built-in module
typechecked
in a Jupyter notebook / IPython always triggers TypeError: <module '__main__'> is a built-in module
Yes, |
Thanks for the clarification. I remember doing prototyping in Jupyter notebooks with earlier versions of |
This would require maintaining two completely different modes of operation, and I don't think I want to do that. The biggest intended use case for typeguard is to complement static type checkers in catching type violations that static checkers cannot check for. What is the intended use case for using |
Just being curious: Could you point me to the relevant sections of code that would need to be extended?
Prototyping, testing etc. When exploring a new data set for instance, I use Jupyter notebooks plus annotated functions & classes plus |
I'm not very comfortable adding a hack that only works for IPython and not the usual Python REPL. |
If IPython had a dedicated (and tested / maintained) API for this, it would probably be a big step forward compared to maintaining a hack like this "manually", yep. I pinged folks over there. If there was such an API, would you consider using it? |
I think I might rather reintroduce a wrapper decorator. |
This seems to have stopped working in major version 3 (based on my testing in this project). The current major version of typeguard is 4. The issue looks like: agronholm/typeguard#364 This should probably only be a temporary solution. There are other libraries I could use. But also, it's not obvious that the added clarity of presentation from defining the top-level functions in the notebooks that use them, rather than in modules as I would ordinarily do, is justified, even in the absence of this issue. So it may be worthwhile to revisit that design decision for codegraph. But for now I'm keeping that as it is and holding back typeguard. This commit also updates typing-extensions to the next patch version.
This seems to have stopped working in major version 3 (based on my testing in this project). The current major version of typeguard is 4. The issue looks like: agronholm/typeguard#364 This should probably only be a temporary solution. There are other libraries I could use. But also, it's not obvious that the added clarity of presentation from defining the top-level functions in the notebooks that use them, rather than in modules as I would ordinarily do, is justified, even in the absence of this issue. So it may be worthwhile to revisit that design decision for codegraph. But for now I'm keeping that as it is and holding back typeguard. This commit also updates typing-extensions to the next patch version.
But I'm keeping typeguard back at major version 2 for now, as detailed below. * Update dependencies * Keep typeguard back so typechecked works in notebooks This seems to have stopped working in major version 3 (based on my testing in this project). The current major version of typeguard is 4. The issue looks like: agronholm/typeguard#364 This should probably only be a temporary solution. There are other libraries I could use. But also, it's not obvious that the added clarity of presentation from defining the top-level functions in the notebooks that use them, rather than in modules as I would ordinarily do, is justified, even in the absence of this issue. So it may be worthwhile to revisit that design decision for codegraph. But for now I'm keeping that as it is and holding back typeguard. This commit also updates typing-extensions to the next patch version. * Re-run notebooks
It should be used once the newest version of torchtyping works with jupyter, because the error reporting in the old versions for jaxtyping are bad (don't tell the shape). See: - agronholm/typeguard#364 - patrick-kidger/jaxtyping#6
There are quite a lot of people who encountered this issue when using jaxtyping, which is mostly used in IPython notebooks. For example, this one, or this one. @agronholm, to me it seems like the best approach would be to address this issue as a hack in the typeguard, since I think it would significantly reduce the number of people having this issue. Otherwise, maybe you could explicitly state that you don't intend to introduce a fix in the nearest future, so that jaxtyping/other libraries that use IPython with typeguard would know that this is not going to be fixed soon, and would remove the typeguard as the default choice of the typechecker? E.g. currently, jaxtyping just uses an older version of typeguard, which is quite a bit undesirable. |
Are you sure you commented on the right issue? This one is about the inability to use |
I am quite sure that it is the right issue. For example, you mentioned that somewhen in May:
which is related to the part about "hack" specific for IPython and not REPL. Also, even the starting comment on this issue mentions that it is related to IPython:
Besides, it is the only open issue that is related to IPython, and it is exactly the issue that jaxtyping is having. For example, you could look at this link. I could open a new issue though, if you consider this to be significantly different from the topic of this issue. |
The As far is this particular issue goes, if I were to make The only thing I can think of that would work in both cases would be making a separate decorator that always wraps the target callable rather than recompiling it. EDIT: Or alternatively, adding this as an option, and defaulting to wrapping if the source cannot be found. |
Ah, alright, sorry. Probably I should have dug in deeper. Thanks for your work! |
It should be used once the newest version of torchtyping works with jupyter, because the error reporting in the old versions for jaxtyping are bad (don't tell the shape). See: - agronholm/typeguard#364 - patrick-kidger/jaxtyping#6 Former-commit-id: aab201f
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
Typeguard version
4.0.0
Python version
3.10.10
What happened?
Using
typechecked
in a Jupyter notebook or in IPython results in the following exception, as of version 4:How can we reproduce the bug?
Inside a Jupyter notebook or IPython, do:
Expected outcome: "Hello world" gets printed.
Actual outcome: Exception
TypeError: <module '__main__'> is a built-in module
EDIT: Also happens in IPython.
The text was updated successfully, but these errors were encountered: