Skip to content

Commit a6575a9

Browse files
asmeureroscarbenjamin
authored andcommitted
Restore sympy.printing.{ccode,fcode,cxxcode} for backwards compatibility
They were renamed in sympy#19908, because the submodule sharing the same name as the function was causing issues in __init__.py. However, these modules also contained things that were not included in __init__.py but were nonetheless part of the public API, such as the printer classes. Consequently, renaming the imports broke the API. This restores the submodules as shims, which are not imported by default (and hence will not cause issues with conflicts in __init__.py). Note that after running import sympy.printing.ccode (or from sympy.printing.ccode import ...) any subsequent from sympy.printing import ccode (or sympy.printing.ccode) will result in the ccode submodule, not the function (this is why ccode.py was renamed to c.py in the first place). Hence, this shim should be avoided and is only provided for backwards compatibility. I haven't deprecated these shim modules in this commit, but I may do that in a later commit. See also the discussion on sympy#20234.
1 parent 1b02f59 commit a6575a9

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

sympy/printing/ccode.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
This is a shim file to provide backwards compatibility (ccode.py was renamed
3+
to c.py in SymPy 1.7).
4+
"""
5+
6+
from .c import (ccode, print_ccode, known_functions_C89, known_functions_C99, # noqa:F401
7+
reserved_words, reserved_words_c99, get_math_macros,
8+
C89CodePrinter, C99CodePrinter, C11CodePrinter,
9+
c_code_printers)

sympy/printing/cxxcode.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
This is a shim file to provide backwards compatibility (cxxcode.py was renamed
3+
to cxx.py in SymPy 1.7).
4+
"""
5+
6+
from .cxx import (cxxcode, reserved, CXX98CodePrinter, # noqa:F401
7+
CXX11CodePrinter, CXX17CodePrinter, cxx_code_printers)

sympy/printing/fcode.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
This is a shim file to provide backwards compatibility (fcode.py was renamed
3+
to fortran.py in SymPy 1.7).
4+
"""
5+
6+
from .fortran import fcode, print_fcode, known_functions, FCodePrinter # noqa:F401

sympy/printing/tests/test_c.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,7 @@ def test_ccode_codegen_ast():
835835
'pwer(x);',
836836
'return x;',
837837
])
838+
839+
def test_ccode_submodule():
840+
# Test the compatibility sympy.printing.ccode module imports
841+
import sympy.printing.ccode # noqa:F401

sympy/printing/tests/test_cxx.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ def test_CXX17CodePrinter():
5454

5555
def test_cxxcode():
5656
assert sorted(cxxcode(sqrt(x)*.5).split('*')) == sorted(['0.5', 'std::sqrt(x)'])
57+
58+
def test_cxxcode_submodule():
59+
# Test the compatibility sympy.printing.cxxcode module imports
60+
import sympy.printing.cxxcode # noqa:F401

sympy/printing/tests/test_fortran.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,7 @@ def test_FunctionDefinition_print():
804804
# Should be changed to proper test once multi-line generation is working
805805
# see https://github.com/sympy/sympy/issues/15824
806806
raises(NotImplementedError, lambda: fcode(fd1))
807+
808+
def test_fcode_submodule():
809+
# Test the compatibility sympy.printing.fcode module imports
810+
import sympy.printing.fcode # noqa:F401

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy