SyntaxWarning when running in Python 3.12
greschd opened this issue · comments
Python 3.12 started warning about improperly escaped strings, for example "\B"
, see the second entry in https://docs.python.org/3/whatsnew/3.12.html#other-language-changes
The PyMAPDL code contains many instances of these. Note that they appear only on a fresh install; after the byte code is generated they do not re-appear.
Steps to reproduce:
- create & activate a fresh 3.12 venv
- Inside the PyMAPDL sources
pip install -e .
python -c 'import ansys.mapdl.core'
To re-reproduce:
git clean -dfx src/
python -c 'import ansys.mapdl.core'
There are two ways to fix this:
- replace single backslashes (
\
) with double backslashes (\\
). - use raw strings
Personally I like to avoid raw strings when possible since they are stranger than one might think, but both options generally work.
Output:
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\commands.py:207: SyntaxWarning: invalid escape sequence '\g'
f"{indented_doc_inject.strip()}\n\n{indentation}\g<0>",
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\commands.py:281: SyntaxWarning: invalid escape sequence '\*'
err_type = re.findall("\*\*\* (.*) \*\*\*", output)[0]
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\array_param.py:1081: SyntaxWarning: invalid escape sequence '\d'
"""Operates on two array parameters.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\macro_files.py:353: SyntaxWarning: invalid escape sequence '\_'
"""Removes (deletes) a directory.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\matrix_op.py:96: SyntaxWarning: invalid escape sequence '\_'
"""Creates a dense matrix.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\matrix_op.py:232: SyntaxWarning: invalid escape sequence '\_'
"""Exports a matrix to a file in the specified format.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\matrix_op.py:298: SyntaxWarning: invalid escape sequence '\_'
"""Computes the fast Fourier transformation of a specified matrix or
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\matrix_op.py:417: SyntaxWarning: invalid escape sequence '\_'
"""Performs a solution using an iterative solver.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\matrix_op.py:828: SyntaxWarning: invalid escape sequence '\_'
"""Creates a sparse matrix.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\parameter_definition.py:58: SyntaxWarning: invalid escape sequence '\_'
"""Defines an array parameter and its dimensions.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\apdl\parameter_definition.py:222: SyntaxWarning: invalid escape sequence '\*'
"""Retrieves a value and stores it as a scalar parameter or part of an array parameter.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\aux3_.py:85: SyntaxWarning: invalid escape sequence '\_'
"""Changes the listed values of the data in a set.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\aux12_\radiosity_solver.py:337: SyntaxWarning: invalid escape sequence '\_'
"""Specifies options for the view factor file and calculates view factors.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\components.py:391: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of components and assemblies.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\picking.py:83: SyntaxWarning: invalid escape sequence '\_'
"""Specifies data required for a picking operation (GUI).
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:96: SyntaxWarning: invalid escape sequence '\_'
"""Selects those areas containing the selected lines.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:138: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of areas.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:269: SyntaxWarning: invalid escape sequence '\_'
"""Selects those areas contained in the selected volumes.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:303: SyntaxWarning: invalid escape sequence '\_'
"""Selects a DOF label set for reference by other commands.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:379: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of elements.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:680: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of keypoints or hard points.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:805: SyntaxWarning: invalid escape sequence '\_'
"""Selects those keypoints contained in the selected lines.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:830: SyntaxWarning: invalid escape sequence '\_'
"""Selects those keypoints associated with the selected nodes.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:869: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of lines.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:992: SyntaxWarning: invalid escape sequence '\_'
"""Selects those lines contained in the selected areas.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1017: SyntaxWarning: invalid escape sequence '\_'
"""Selects those lines containing the selected keypoints.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1060: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of nodes.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1232: SyntaxWarning: invalid escape sequence '\_'
"""Selects those nodes associated with the selected areas.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1279: SyntaxWarning: invalid escape sequence '\_'
"""Selects those nodes attached to the selected elements.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1342: SyntaxWarning: invalid escape sequence '\_'
"""Selects those nodes associated with the selected keypoints.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1371: SyntaxWarning: invalid escape sequence '\_'
"""Selects those nodes associated with the selected lines.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1408: SyntaxWarning: invalid escape sequence '\_'
"""Selects those nodes associated with the selected volumes.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1444: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of parts in an explicit dynamic analysis.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1522: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of volumes.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\database\selecting.py:1630: SyntaxWarning: invalid escape sequence '\_'
"""Selects those volumes containing the selected areas.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\graphics_\annotation.py:150: SyntaxWarning: invalid escape sequence '\_'
"""Specifies the annotation number, type, and hot spot (GUI).
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\graphics_\labeling.py:327: SyntaxWarning: invalid escape sequence '\_'
"""Shows boundary condition (BC) symbols and values on displays.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\graphics_\style.py:436: SyntaxWarning: invalid escape sequence '\_'
"""Specifies the light direction for the display window.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\graphics_\style.py:524: SyntaxWarning: invalid escape sequence '\_'
"""Defines the type of surface shading used with Z-buffering.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\inq_func.py:111: SyntaxWarning: invalid escape sequence '\*'
"""Get information about an element.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\inq_func.py:190: SyntaxWarning: invalid escape sequence '\*'
"""Get information about a keypoints.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\inq_func.py:469: SyntaxWarning: invalid escape sequence '\*'
"""Get information about a volume.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\inq_func.py:719: SyntaxWarning: invalid escape sequence '\-'
"""Get information about a coupled set.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\map_cmd.py:192: SyntaxWarning: invalid escape sequence '\_'
"""Reads coordinate and pressure data from a file.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\animation.py:127: SyntaxWarning: invalid escape sequence '\_'
"""Displays animated graphics data for nonlinear problems.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\animation.py:638: SyntaxWarning: invalid escape sequence '\_'
"""Performs animation of results over multiple results files in an
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\animation.py:716: SyntaxWarning: invalid escape sequence '\_'
"""Produces a sequential contour animation over a range of time.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\element_table.py:607: SyntaxWarning: invalid escape sequence '\_'
"""Allows safety factor or margin of safety calculations to be made.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\element_table.py:645: SyntaxWarning: invalid escape sequence '\_'
"""Calculates the safety factor or margin of safety.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\load_case.py:269: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of load cases.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\path_operations.py:903: SyntaxWarning: invalid escape sequence '\_'
"""Selects a path or paths.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\results.py:108: SyntaxWarning: invalid escape sequence '\_'
"""Plots the fracture parameter (CINT) result data.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\results.py:555: SyntaxWarning: invalid escape sequence '\_'
"""Lists the fracture parameter (CINT) results data.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\special.py:404: SyntaxWarning: invalid escape sequence '\_'
"""Provides tools for determining minimum and maximum possible result
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post1_\surface_operations.py:436: SyntaxWarning: invalid escape sequence '\_'
"""Selects a subset of surfaces
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\post26_\setup.py:137: SyntaxWarning: invalid escape sequence '\_'
"""Stores fracture parameter information in a variable.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\areas.py:95: SyntaxWarning: invalid escape sequence '\_'
"""Associates element attributes with the selected, unmeshed areas.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\elements.py:371: SyntaxWarning: invalid escape sequence '\|'
"""Generates elements from an existing pattern.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\elements.py:1067: SyntaxWarning: invalid escape sequence '\|'
"""Generates elements from an existing pattern.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\explicit_dynamics.py:1513: SyntaxWarning: invalid escape sequence '\_'
"""Selects and plots explicit dynamic contact entities.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\explicit_dynamics.py:1554: SyntaxWarning: invalid escape sequence '\_'
"""Specifies small penetration checking for contact entities in an
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\hard_points.py:36: SyntaxWarning: invalid escape sequence '\_'
"""Defines a hard point.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\keypoints.py:85: SyntaxWarning: invalid escape sequence '\_'
"""Creates a keypoint between two existing keypoints.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\keypoints.py:152: SyntaxWarning: invalid escape sequence '\_'
"""Creates a keypoint at the center of a circular arc defined
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\meshing.py:1002: SyntaxWarning: invalid escape sequence '\_'
"""Associates attributes with the selected, unmeshed keypoints.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\meshing.py:1266: SyntaxWarning: invalid escape sequence '\_'
"""Associates element attributes with the selected, unmeshed lines.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\meshing.py:2767: SyntaxWarning: invalid escape sequence '\_'
"""Associates element attributes with the selected, unmeshed volumes.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\sections.py:1076: SyntaxWarning: invalid escape sequence '\_'
"""Associates section type information with a section ID number.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\preproc\sections.py:1263: SyntaxWarning: invalid escape sequence '\_'
"""Summarizes the section properties for all defined sections in the
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\reduced\generation.py:174: SyntaxWarning: invalid escape sequence '\_'
"""Defines and edits various modal parameters for the ROM method.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\reduced\generation.py:330: SyntaxWarning: invalid escape sequence '\_'
"""Defines options for ROM response surface fitting.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\reduced\generation.py:366: SyntaxWarning: invalid escape sequence '\_'
"""Plots response surface of ROM function or its derivatives with respect
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\analysis_options.py:2595: SyntaxWarning: invalid escape sequence '\_'
"""Checks for overconstraint among constraint equations and Lagrange
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\analysis_options.py:2778: SyntaxWarning: invalid escape sequence '\_'
"""Sets linear perturbation analysis options.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\dynamic_options.py:301: SyntaxWarning: invalid escape sequence '\_'
"""Perform the harmonic ocean wave procedure (HOWP).
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\fe_body_loads.py:697: SyntaxWarning: invalid escape sequence '\_'
"""Imports initial stresses from an explicit dynamics run into ANSYS.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\miscellaneous_loads.py:1013: SyntaxWarning: invalid escape sequence '\-'
"""Controls file writing for multiframe restarts.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\multi_field_solver_load_transfer.py:37: SyntaxWarning: invalid escape sequence '\_'
"""Defines a load transfer for code coupling analyses.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\radiosity.py:69: SyntaxWarning: invalid escape sequence '\_'
"""Creates or loads the radiosity mapping data file for SURF251 or SURF252
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\spectrum_options.py:818: SyntaxWarning: invalid escape sequence '\_'
"""Defines the type of input PSD.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\_commands\solution\spectrum_options.py:1334: SyntaxWarning: invalid escape sequence '\_'
"""Defines the type of multi-point response spectrum.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\launcher.py:1087: SyntaxWarning: invalid escape sequence '\-'
"""Start MAPDL locally.
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\mapdl_core.py:2824: SyntaxWarning: invalid escape sequence '\|'
"if grep -sq 'docker\|lxc' /proc/1/cgroup; then echo 'true' > __outputcmd__.txt; else echo 'false' > __outputcmd__.txt;fi;"
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\parameters.py:150: SyntaxWarning: invalid escape sequence '\*'
"""Current routine string as a string. For example ``"/PREP7"``
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\parameters.py:564: SyntaxWarning: invalid escape sequence '\*'
"""Load a numpy array or python list directly to MAPDL
D:\ANSYSDev\public\pymapdl\src\ansys\mapdl\core\parameters.py:754: SyntaxWarning: invalid escape sequence '\*'
"""Interprets \*STATUS command output from MAPDL
@greschd is this expected given that PyMAPDL supports Python 3.8-3.11?
https://mapdl.docs.pyansys.com/version/stable/getting_started/install_pymapdl.html
Not being a developer I don't keep up with all the changes between Python releases so this is a genuine question.
Mike
@mikerife this happens on the latest development version of PyMAPDL version, which supports Python 3.12: https://mapdl.docs.pyansys.com/version/dev/getting_started/install_pymapdl.html
This is not actively a problem when using PyMAPDL, but it
- clutters up the CI/CD output in downstream projects
- should eventually be fixed, since the expectation is that a future version of Python will raise a
SyntaxError
instead of only a warning