FreeCAD / FreeCAD

This is the official source code of FreeCAD, a free and opensource multiplatform 3D parametric modeler.
https://www.freecad.org
Other
18.68k stars 3.94k forks source link

Expressions _math.pi and _math.e are broken #15302

Open krushia opened 1 month ago

krushia commented 1 month ago

Is there an existing issue for this?

Problem description

FreeCAD provides limited access to the Python math module via expressions using the pseudoproperty _math. _math.pi and _math.e don't seem to work, presumably because of the builtin pi and e constants (which are hardcoded and not related to the Python math ones at all) confusing the expression parser.

For correctly working examples, try any of these in an expression:

_math.inf
_math.nan
_math.tau

Full version info

OS: Gentoo Linux (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.38043 (Git) AppImage
Build type: Release
Branch: main
Hash: 561e521817034ea7660de987d8ab7183ad583595
Python 3.11.9, Qt 5.15.13, Coin 4.0.2, Vtk 9.2.6, OCC 7.7.2
Locale: English/United States (en_US)
Installed mods: 
  * parts_library
  * Curves 0.6.40
  * A2plus 0.4.65
  * DynamicData 2.62.0
  * Assembly4 0.50.14
  * dodo 1.0.1
  * Alternate_OpenSCAD 1.0.0 (Disabled)
  * CurvedShapes 1.0.9
  * Design456 0.0.1
  * fasteners 0.5.24
  * SearchBar 1.0.2
  * Nodes 0.1.36 (Disabled)
  * 3D_Printing_Tools
  * Pyramids-and-Polyhedrons
  * workfeature (Disabled)
  * MnesarcoUtils 0.2.5
  * OpenTheme 2024.7.3
  * Manipulator 1.5.7
  * Assembly3 0.12.2
  * lattice2 1.0.0
  * ThreadProfile 1.90.0
  * freecad.gears 1.2.0
  * Launcher
  * CommandPanel
  * CubeMenu
  * Reinforcement
  * PieMenu 1.7.5
  * MeshRemodel 1.9.23

Subproject(s) affected?

Expressions

Anything else?

No response

Code of Conduct

maxwxyz commented 1 month ago

does this work in 0.21.2?

krushia commented 1 month ago

does this work in 0.21.2?

Nope. Same results.

This also affects _self.pi (if a parameter named pi exists), foo.pi, and <<foo>>.pi. Interestingly it can't be entered at all in the expression editor, even with the conditional trick that usually lets me enter naughty things in the "currently not evaluated" half.

Screenshot_20240709_123427 Screenshot_20240709_124017