I just had a conversation on #python about this.  After a bit of talk about 
"from __future__ import absolute_import", which doesn't work in Python 2.4 and 
would require us changing all of our non-absolute imports everywhere (the 
person I talked with said we would pretty much have to use it everywhere in 
SymPy), explicit relative imports (also not supported in Python 2.4, but 
supported without __future__ in Python 2.5+), and renaming symbol.py (which 
would also be a lot of work), I figured out that the solution is much simpler 
than that.  We just need to move ast_parser_python24.py, which is the only file 
that uses this stdlib_symbol, to a separate directory from sympy/core.  

So I propose that we move that file, as well as ast_parser.py and sympify.py, 
to sympy/parsing.  If there are no objections, I will create a patch for this.  

Aaron Meurer

On Dec 28, 2010, at 2:30 PM, Aaron S. Meurer wrote:

> This *seems* to fix it.  The only failure when that import is removed is 
> test_sympify in Python 2.4 and Python 2.5, and it still passes after this 
> diff is applied.  The idea is that once you import a module, it is put in 
> sys.modules, even if you immediately delete the module from the namespace 
> after you import it.  I don't know how supported this behavior is, though.  
> It seems rather hackish to me.
> 
> diff --git a/sympy/__init__.py b/sympy/__init__.py
> index 60da6e1..bbc9654 100644
> --- a/sympy/__init__.py
> +++ b/sympy/__init__.py
> @@ -19,6 +19,7 @@ def __sympy_debug():
> SYMPY_DEBUG = __sympy_debug()
> 
> import symbol as stdlib_symbol
> +del stdlib_symbol
> from sympy.core import *
> from assumptions import *
> from polys import *
> diff --git a/sympy/core/ast_parser_python24.py 
> b/sympy/core/ast_parser_python24.py
> index ed7e41b..1e21d62 100644
> --- a/sympy/core/ast_parser_python24.py
> +++ b/sympy/core/ast_parser_python24.py
> @@ -4,6 +4,7 @@
> from compiler.ast import CallFunc, Name, Const
> from compiler.pycodegen import ExpressionCodeGenerator
> import re
> +import sys
> 
> from basic import Basic
> from symbol import Symbol
> @@ -52,7 +53,7 @@ def atom_name(self, nodelist):
> 
>     def lambdef(self, nodelist):
>         #this is python stdlib symbol, not SymPy symbol:
> -        from sympy import stdlib_symbol
> +        stdlib_symbol = sys.modules['symbol']
>         if nodelist[2][0] == stdlib_symbol.varargslist:
>             names, defaults, flags = self.com_arglist(nodelist[2][1:])
>         else:
> 
> Aaron Meurer
> 
> On Dec 27, 2010, at 10:46 PM, Aaron S. Meurer wrote:
> 
>> Well, it's a problem, because we have stdlib_symbol imported into the 
>> namespace with from sympy import *.  I wonder if this can be fixed by 
>> manipulating sys.modules?
>> 
>> Aaron Meurer
>> 
>> On Dec 21, 2010, at 9:31 PM, Ondrej Certik wrote:
>> 
>>> On Tue, Dec 21, 2010 at 9:54 PM, Aaron S. Meurer <asmeu...@gmail.com> wrote:
>>>> Why is this line
>>>> 
>>>> import symbol as stdlib_symbol
>>>> 
>>>> in the main sympy/__init__.py?  If I comment it out, there are some test 
>>>> failures, but it seems that wherever this is used it should be imported 
>>>> there (there is no reason that it should be imported into the main 
>>>> namespace).  By the way, the symbol module is "Non-terminal symbols of 
>>>> Python grammar (from "graminit.h")."
>>> 
>>> I think that the problem is that it needs to be imported in
>>> sympy/core, and there is already a file called symbol.py, thus there
>>> is no way to import the stdlib symbol. Thus we need to import it one
>>> level up.
>>> 
>>> Ondrej
>>> 
>>> — 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to