Issue 1411 Patch

0 views
Skip to first unread message

Matt Curry

unread,
Apr 15, 2010, 1:03:40 AM4/15/10
to sympy-patches
Hello everyone, this is my first time patching. I fixed this issue:
http://code.google.com/p/sympy/issues/detail?id=1411&q=sage . I
changed all the printmethod names in sympy (e.g. "_foo_" => "_foo") to
make it compatible with the Sage notebook. Here's the patch:

---
sympy/galgebra/latex_ex.py | 2 +-
sympy/physics/secondquant.py | 14 +++++++-------
sympy/printing/ccode.py | 2 +-
sympy/printing/fcode.py | 2 +-
sympy/printing/latex.py | 2 +-
sympy/printing/mathml.py | 2 +-
sympy/printing/pretty/pretty.py | 2 +-
sympy/printing/repr.py | 2 +-
sympy/printing/str.py | 2 +-
sympy/printing/tests/test_ccode.py | 2 +-
sympy/printing/tests/test_fcode.py | 2 +-
sympy/printing/tests/test_latex.py | 4 ++--
sympy/printing/tests/test_repr.py | 4 ++--
sympy/printing/tests/test_str.py | 4 ++--
14 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/sympy/galgebra/latex_ex.py b/sympy/galgebra/latex_ex.py
index 0e719df..d8b65a7 100644
--- a/sympy/galgebra/latex_ex.py
+++ b/sympy/galgebra/latex_ex.py
@@ -111,7 +111,7 @@ class extends the LatexPrinter class currently in
sympy in the following ways:
form \partial_{differentiation variable}
"""

- #printmethod ='_latex_ex_'
+ #printmethod ='_latex_ex'
sym_fmt = 0
fct_fmt = 0
pdiff_fmt = 0
diff --git a/sympy/physics/secondquant.py b/sympy/physics/
secondquant.py
index 769f6a3..5d3f77b 100644
--- a/sympy/physics/secondquant.py
+++ b/sympy/physics/secondquant.py
@@ -241,7 +241,7 @@ def eval(cls, symbol, upper, lower):
except ViolationOfPauliPrinciple:
return S.Zero

- def _latex_(self,printer):
+ def _latex(self,printer):
return "%s^{%s}_{%s}" %(
self.symbol,
"".join([ i.name for i in self.args[1]]),
@@ -592,7 +592,7 @@ def _get_preferred_index(self):
def _dagger_(self):
return self

- def _latex_(self,printer):
+ def _latex(self,printer):
return "\\delta_{%s%s}"%
(self.args[0].name,self.args[1].name)

def __repr__(self):
@@ -1026,7 +1026,7 @@ def is_only_q_annihilator(self):
def __repr__(self):
return "AnnihilateFermion(%s)"%self.state

- def _latex_(self,printer):
+ def _latex(self,printer):
return "a_{%s}"%self.state.name

class CreateFermion(FermionicOperator, Creator):
@@ -1146,7 +1146,7 @@ def is_only_q_annihilator(self):
def __repr__(self):
return "CreateFermion(%s)"%self.state

- def _latex_(self,printer):
+ def _latex(self,printer):
return "a^\\dagger_{%s}"%self.state.name

Fd = CreateFermion
@@ -1865,7 +1865,7 @@ def __repr__(self):
def __str__(self):
return "[%s,%s]" %(self.args[0],self.args[1])

- def _latex_(self,printer):
+ def _latex(self,printer):
return "\\left[%s,%s\\right]"%tuple([
printer._print(arg) for arg in self.args])

@@ -2184,7 +2184,7 @@ def get_subNO(self, i):
mul = Mul(*(self.args[0].args[0:i] + self.args[0].args[i
+1:]))
return NO(mul)

- def _latex_(self,printer):
+ def _latex(self,printer):
return "\\left\\{%s\\right\\}"%printer._print(self.args[0])

def __repr__(self):
@@ -2921,7 +2921,7 @@ def get_permuted(self,expr):

return S.NegativeOne*expr

- def _latex_(self, printer):
+ def _latex(self, printer):
return "P(%s%s)"%self.args


diff --git a/sympy/printing/ccode.py b/sympy/printing/ccode.py
index 61b68fa..8f2b04b 100644
--- a/sympy/printing/ccode.py
+++ b/sympy/printing/ccode.py
@@ -15,7 +15,7 @@

class CCodePrinter(StrPrinter):
"""A printer to convert python expressions to strings of c
code"""
- printmethod = "_ccode_"
+ printmethod = "_ccode"

def _print_Pow(self, expr):
PREC = precedence(expr)
diff --git a/sympy/printing/fcode.py b/sympy/printing/fcode.py
index f1f98a8..6d7eee7 100644
--- a/sympy/printing/fcode.py
+++ b/sympy/printing/fcode.py
@@ -35,7 +35,7 @@

class FCodePrinter(StrPrinter):
"""A printer to convert sympy expressions to strings of Fortran
code"""
- printmethod = "_fcode_"
+ printmethod = "_fcode"

_default_settings = {
'order': None,
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index e26b1b4..cce22fc 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -14,7 +14,7 @@
import re, warnings

class LatexPrinter(Printer):
- printmethod = "_latex_"
+ printmethod = "_latex"

_default_settings = {
"order": None,
diff --git a/sympy/printing/mathml.py b/sympy/printing/mathml.py
index abb5d78..b4057ef 100644
--- a/sympy/printing/mathml.py
+++ b/sympy/printing/mathml.py
@@ -15,7 +15,7 @@ class MathMLPrinter(Printer):

References: http://www.w3.org/TR/MathML2/
"""
- printmethod = "_mathml_"
+ printmethod = "_mathml"
_default_settings = {
"order": None,
"encoding": "utf-8"
diff --git a/sympy/printing/pretty/pretty.py b/sympy/printing/pretty/
pretty.py
index 03b84f9..06e84e2 100644
--- a/sympy/printing/pretty/pretty.py
+++ b/sympy/printing/pretty/pretty.py
@@ -14,7 +14,7 @@

class PrettyPrinter(Printer):
"""Printer, which converts an expression into 2D ASCII-art
figure."""
- printmethod = "_pretty_"
+ printmethod = "_pretty"

_default_settings = {
"order": None,
diff --git a/sympy/printing/repr.py b/sympy/printing/repr.py
index d211065..62342fb 100644
--- a/sympy/printing/repr.py
+++ b/sympy/printing/repr.py
@@ -11,7 +11,7 @@
from sympy.mpmath.libmp import prec_to_dps, repr_dps

class ReprPrinter(Printer):
- printmethod = "_sympyrepr_"
+ printmethod = "_sympyrepr"

def reprify(self, args, sep):
return sep.join([self.doprint(item) for item in args])
diff --git a/sympy/printing/str.py b/sympy/printing/str.py
index 6ef2c36..6e7c996 100644
--- a/sympy/printing/str.py
+++ b/sympy/printing/str.py
@@ -15,7 +15,7 @@
from sympy.polys.polyerrors import PolynomialError

class StrPrinter(Printer):
- printmethod = "_sympystr_"
+ printmethod = "_sympystr"
_default_settings = {
"order": None,
"full_prec": "auto",
diff --git a/sympy/printing/tests/test_ccode.py b/sympy/printing/tests/
test_ccode.py
index b05f7bd..820b7c5 100644
--- a/sympy/printing/tests/test_ccode.py
+++ b/sympy/printing/tests/test_ccode.py
@@ -9,7 +9,7 @@

def test_printmethod():
class fabs(abs):
- def _ccode_(self, printer):
+ def _ccode(self, printer):
return "fabs(%s)" % printer._print(self.args[0])
assert ccode(fabs(x)) == "fabs(x)"

diff --git a/sympy/printing/tests/test_fcode.py b/sympy/printing/tests/
test_fcode.py
index 83539c6..7884387 100644
--- a/sympy/printing/tests/test_fcode.py
+++ b/sympy/printing/tests/test_fcode.py
@@ -9,7 +9,7 @@
def test_printmethod():
x = symbols('x')
class nint(Function):
- def _fcode_(self, printer):
+ def _fcode(self, printer):
return "nint(%s)" % printer._print(self.args[0])
assert fcode(nint(x)) == " nint(x)"

diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/
test_latex.py
index 236e835..7afaf28 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -12,11 +12,11 @@

def test_printmethod():
class R(abs):
- def _latex_(self, printer):
+ def _latex(self, printer):
return "foo(%s)" % printer._print(self.args[0])
assert latex(R(x)) == "foo(x)"
class R(abs):
- def _latex_(self, printer):
+ def _latex(self, printer):
return "foo"
assert latex(R(x)) == "foo"

diff --git a/sympy/printing/tests/test_repr.py b/sympy/printing/tests/
test_repr.py
index 3c85f9d..3bf927f 100644
--- a/sympy/printing/tests/test_repr.py
+++ b/sympy/printing/tests/test_repr.py
@@ -29,11 +29,11 @@ def sT(expr, string):

def test_printmethod():
class R(oo.__class__):
- def _sympyrepr_(self, printer):
+ def _sympyrepr(self, printer):
return "foo"
assert srepr(R()) == "foo"
class R(abs):
- def _sympyrepr_(self, printer):
+ def _sympyrepr(self, printer):
return "foo(%s)" % printer._print(self.args[0])
assert srepr(R(x)) == "foo(Symbol('x'))"

diff --git a/sympy/printing/tests/test_str.py b/sympy/printing/tests/
test_str.py
index ecafef7..be0f837 100644
--- a/sympy/printing/tests/test_str.py
+++ b/sympy/printing/tests/test_str.py
@@ -21,11 +21,11 @@

def test_printmethod():
class R(abs):
- def _sympystr_(self, printer):
+ def _sympystr(self, printer):
return "foo(%s)" % printer._print(self.args[0])
assert spr(R(x)) == "foo(x)"
class R(abs):
- def _sympystr_(self, printer):
+ def _sympystr(self, printer):
return "foo"
assert spr(R(x)) == "foo"

--
1.6.3.3

Toon Verstraelen

unread,
Apr 15, 2010, 1:48:26 AM4/15/10
to sympy-...@googlegroups.com
Hi Matt,

Thanks for the patch. Could you send patches as attachments? Line
wrapping messes up the patches. It is even better to compress them with
gzip to prevent mail clients from messing things up.

cheers,

Toon

Matt Curry

unread,
Apr 15, 2010, 1:57:41 AM4/15/10
to sympy-...@googlegroups.com
Yea, I'll attach the patch in this email (in both zipped and non-zipped versions).

Thanks,

Matt

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


patch for issue 1411.zip
0001-Changed-printmethod-names-and-methods-from-_foo_-to-.patch

Toon Verstraelen

unread,
Apr 15, 2010, 4:28:14 PM4/15/10
to sympy-...@googlegroups.com
On 04/15/2010 07:57 AM, Matt Curry wrote:
> Yea, I'll attach the patch in this email (in both zipped and non-zipped
> versions).

I've just reviewed it. The patch is good and the tests run fine. It is
pushed in. Thanks.

Toon

Matt Curry

unread,
Apr 15, 2010, 9:11:58 PM4/15/10
to sympy-...@googlegroups.com
Awesome! Thanks a bunch!

Matt

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

Reply all
Reply to author
Forward
0 new messages