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
Setting __file__
to None breaks Mayavi import
#2279
Comments
This works in master as a temporary workaround for the mayavi import problem, further indicating that #1831 is really the culprit.
|
From the reference: " I don't see any provision for it being |
Looks like we need to clean up our handling of
I suggest that after running each of these |
On Fri, Aug 10, 2012 at 11:30 AM, Bradley M. Froehle <
Actually I would suggest something different: we should work identical to No Python itself doesn't define |
Well, there are two schools of thought regarding
Note that in no case does |
I should mention that I think we got bitten not because we deviated from Python semantics but because we failed to properly restore the previous context. Consider our current code: save_fname = namespace.get('__file__', None)
try:
...
finally:
namespace['__file__'] = save_fname As compared to what I would consider more correct code. save_fname = namespace.get('__file__', None)
try:
...
finally:
if save_fname is not None:
namespace['__file__'] = save_fname
else:
# None is never a valid __file__
del namespace['__file__'] |
On Fri, Aug 10, 2012 at 12:40 PM, Bradley M. Froehle <
But indeed, it should never leak back out post-execution. Cheers, f |
At this point I'm in favor of a wholesale revert of #1831 -- the original patch which added this In addition to not fully restoring the context, in |
@bfroehle, +1 on that. Go for it, if you have the bandwidth right now. |
Revert #1831, the `__file__` injection in safe_execfile / safe_execfile_ipy. This reverts commit 2717feb, reversing changes made to ea4f608. Pull request #1831 (fix #1814 set __file__ when running .ipy files) has been the source of a lot of grief: #2279: Setting __file__ to None breaks Mayavi import #2429: Using warnings.warn() results in TypeError In general the patch was inappropriate because it: 1. Fails to properly restore the context, by setting __file__ to None rather than deleting it. 2. Sets __file__ in the wrong dictionary (self.user_ns rather than where[0]).
closed by #2432 |
Revert ipython#1831, the `__file__` injection in safe_execfile / safe_execfile_ipy. This reverts commit 2717feb, reversing changes made to ea4f608. Pull request ipython#1831 (fix ipython#1814 set __file__ when running .ipy files) has been the source of a lot of grief: ipython#2279: Setting __file__ to None breaks Mayavi import ipython#2429: Using warnings.warn() results in TypeError In general the patch was inappropriate because it: 1. Fails to properly restore the context, by setting __file__ to None rather than deleting it. 2. Sets __file__ in the wrong dictionary (self.user_ns rather than where[0]).
As discussed at the bottom of #1831, after its merge it became impossible to import mayavi, with this traceback:
It may be that there's an issue with mayavi (and if so, we can report it upstream), but breaking use of Mayavi is not acceptable. We may have to temporarily revert #1831 altogether, until we find a cleaner solution to #1814...
I'm not 100% sure on the semantics of
__file__
so there may be a better solution that undoing #1831 completely.The text was updated successfully, but these errors were encountered: