FreeCAD / FreeCAD

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

Improvement of Python API -- Python implementations have no __repr__ #17059

Open AIRCAP opened 5 days ago

AIRCAP commented 5 days ago

Is there an existing issue for this?

Problem description

As discussed in #development:

@benj5378: @CorvusCorax idk if an issue already exists... but please open an issue on GitHub requesting implementation of __repr__ across objects in all of FreeCAD. It's actually a very big issue, making it very difficult to use Python Console.

https://docs.python.org/3/reference/datamodel.html#object.__repr__

Like even this

Gui.ActiveDocument <GUI Document object at 0x5791140ea400>

If __repr__ was implemented, it would be

Gui.ActiveDocument <GUI Document MyNewTable>

Really bad user experience

We also found out that Gui.Control.activeDialog() only returns true or false instead of a python representation of the dialog to interact . Instead there is Gui.Control.activeTaskDialog() but it has no __repr__ so you can't tell which one.

This issue could act as a meta-issue for general improvements and housecleaning of the Python API in case more are found - in any way this is post 1.0 work and not super urgent.

Full version info

all current versions

Subproject(s) affected?

Other (specify in description)

Anything else?

No response

Code of Conduct

benj5378 commented 5 days ago

Gui.Control.activeTaskDialog() returns Task Dialog as __repr__ for the class. It would be much better if it returned <Task Dialog Sketcher Edit> for instance

Gui.ActiveDocument return <GUI Document object at 0x5791140ea400> as __repr__ , it would be much better if it returned <GUI Document MyNewTable>

Link to __repr__ method https://docs.python.org/3/reference/datamodel.html#object.__repr__