Ask Your Question
0

PolynomialRing and from __future__ import unicode_literals

asked 12 years ago

updated 12 years ago

Hello

sage: from __future__ import unicode_literals
sage: R=PolynomialRing(QQ,'x')

TypeError Traceback (most recent call last)

/home/moky/script/<ipython console=""> in <module>()

/home/moky/Sage/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.pyc in PolynomialRing(base_ring, arg1, arg2, sparse, order, names, name, implementation) 425 if R is None: 426 raise TypeError("invalid input (%s, %s, %s) to PolynomialRing function; please see the docstring for that function"%( --> 427 base_ring, arg1, arg2)) 428 429 return R

TypeError: invalid input (Rational Field, x, None) to PolynomialRing function; please see the docstring for that function

I guess this is the same kind of problem that the one in this question

By the way, this is "fixed" by using str :

sage: R=PolynomialRing(QQ,str('x'))
sage: f=R.lagrange_polynomial([(0,1),(1,4)]);f
3*x + 1
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 12 years ago

DSM gravatar image

There are lots of places in the Sage codebase, including PolynomialRing, where someone does an isinstance(something, str) when they should do isinstance(something, basestring), where basestring is the shared parent of str and unicode.

In this case:

elif isinstance(arg1, str) or (isinstance(arg1, (list,tuple)) and len(arg1) == 1):

Because of how the branching works, it looks like you could also get away with making the names a list:

sage: from __future__ import unicode_literals
sage: R = PolynomialRing(QQ, 'x')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Applications/sage/devel/sage-main/sage/<ipython console> in <module>()

/Applications/sage/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.pyc in PolynomialRing(base_ring, arg1, arg2, sparse, order, names, name, implementation)
    425     if R is None:
    426         raise TypeError("invalid input (%s, %s, %s) to PolynomialRing function; please see the docstring for that function"%(
--> 427             base_ring, arg1, arg2))
    428 
    429     return R

TypeError: invalid input (Rational Field, x, None) to PolynomialRing function; please see the docstring for that function
sage: R = PolynomialRing(QQ, ['x'])
sage:

but this could lead to similar problems elsewhere.

Preview: (hide)
link

Comments

Are you suggesting you want to grep through those and make a patch? :-)

kcrisman gravatar imagekcrisman ( 12 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 647 times

Last updated: Sep 29 '12