-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
lazy_import doesn't resolve properly when indirectly imported #16522
Comments
comment:2
Ouch. This is difficult to fix. Sure, we can put in
but that only solves one step of the problem. Next we get in
so if we want to solve this problem, we'd have to do so manually unless we come up with very smart hack in
Exactly the same story. Luckily, the lazy_import proxy objects are pretty transparent when the import has already happened, so it's not too much of an issue when they're in the way (unless you're in a very tight loop). I'll be upgrading the severity and scope of this ticket. |
This comment has been minimized.
This comment has been minimized.
Dependencies: #22752 |
comment:5
Following up on the code in comment |
Changed dependencies from #22752 to none |
comment:7
Seeing how many improperly placed LazyImport (i.e., LazyImport objects that do have a namespace set, but it doesn't match the namespace in which they are bound, or the name they are bound to doesn't match the
gives currently:
Executing:
naturally resolves all these. Two options to use this in practice:
Comments welcome. |
Commit: |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:10
What is the actual problem? The first lines of the ticket description are very cryptic. |
This comment has been minimized.
This comment has been minimized.
comment:12
Replying to @videlec:
I tried to decrypt it. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:39
Rebased New commits:
|
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits: |
comment:41
Dropped workarounds for NN in partitions |
comment:43
I think handling the more common cases like |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:46
Replying to Nils Bruin:
Done |
Author: Nils Bruin, Matthias Koeppe |
Reviewer: Matthias Koeppe, ... |
comment:50
+1 from me, but I think someone else than me should give a positive review: the changes here affect start-up procedures for sage, so it is a rather invasive change. |
comment:51
Yes, I have already reviewed your changes. |
Changed reviewer from Matthias Koeppe, ... to Matthias Koeppe, Nils Bruin |
Changed branch from u/mkoeppe/lazy_import_doesn_t_resolve_properly_when_indirectly_imported_ to |
… the Sage library This is extracted from sagemath#16522. One issue raised on that ticket is that it is problematic to use lazy imports on things other than a function (stated in https://trac.sagemath.org/ticket/16522#comment:20). It appears that using honest imports rather than lazy ones for `NN` should not cause too much of a slowdown, but this needs to be tested. URL: https://trac.sagemath.org/34652 Reported by: jhpalmieri Ticket author(s): John Palmieri Reviewer(s): Matthias Koeppe
We have several places where lazy_import objects are used in a way that prevents them from behaving as designed.
The original idea of
LazyImport
proxies is that they have a pointer to the namespace in which they are bound, so that once the import gets triggered, the proxy object redirects the binding in the namespace to point straight to the proxied object. Once this redirection has happened, the proxy object should not play a role anymore and no performance impact should happen at all.The problem occurs from statements such as:
This doesn't work, because this is a
LazyImport
proxy, which needs to know the namespace in which it is bound to do the proper replacement. This one is tied tosage.calculus.calculus.maxima
, so it can't rebind the globalmaxima_calculus
. Indeed:The binding of
maxima_calculus
in the global namespace (and the one incalculus.all
too) remains to theLazyImport
proxy. Thus we suffer from indirection overhead [one might worry we'd suffer repeated extraneous dictionary modifications, butLazyImport
is smart enough to only attempt to rebindsage.calculus.calculus.maxima
only on the first access] as well as problems that things likeid(LazyImportShim)
andtype(LazyImportShim)
are not what they're supposed to model.If instead we do:
we see that things do resolve:
Other bindings need their own chance to resolve, but do:
The obvious fix: in
calculus.all
, importmaximalib
directly and lazily, rather than indirectly fromsage.calculus.calculus
only kicks the can further, since insage.all
we havefrom sage.calculus.all import *
(which I think is where it really gets placed in the global sage namespace).CC: @kcrisman @embray @tscrim
Component: misc
Author: Nils Bruin, Matthias Koeppe
Branch/Commit:
9837dec
Reviewer: Matthias Koeppe, Nils Bruin
Issue created by migration from https://trac.sagemath.org/ticket/16522
The text was updated successfully, but these errors were encountered: