View Issue Details

IDProjectCategoryView StatusLast Update
0002417FreeCADBugpublic2016-01-31 13:00
Reporterlooo Assigned Towmayer  
PrioritylowSeveritytweakReproducibilityalways
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version0.16 
Summary0002417: console autocomplete runs python properties
DescriptionThe FreeCAD console executes the properties of an object on autocomplete.
Steps To Reproducerun this macro:

class a(object):
    @property
    def test1(self):
        print("hello")
    
    @property
    def test2(self):
        print(" you")

Gui.object = a()

and in console type:
>>> Gui.object.

this will trigger the properties.
TagsNo tags attached.
FreeCAD Information

Activities

wmayer

2016-01-31 09:50

administrator   ~0006778

The same also happens with old-style classes:

class a:
...

The commit 0f858f99 fixes this part of the problem. Instances of old-style classes can be easily identified by checking for PyInstance_Type. Then its type object (PyClass_Type) can be used to get all its attributes.

However, I didn't find a way to identify instances or the types of new-style classes.

Then, a "module" is also a new style class and to get all its attributes I must query the instance of the module and not its type object.

Any idea how to solve this?

wmayer

2016-01-31 13:00

administrator   ~0006779

I found a solution. To test for new-style classes the tp_flags is set to Py_TPFLAGS_HEAPTYPE and additionally I check that it's an instance of 'PyBaseObject_Type' (which corresponds to 'object' in Python).

And the hasattr/getattr access has been replaced with a call of Py_CompileString & PyEval_EvalCode because otherwise a property is triggered twice.

But note, when you enter 'Gui.object.test1.' into the console then test1 will be executed. I have tested this with the IDLE editor and this shows the same behaviour.

Related Changesets

FreeCAD: master 0f858f99

2016-01-31 02:28:24

wmayer

Details Diff
+ issue 0002417: console autocomplete runs python properties Affected Issues
0002417
mod - src/Gui/CallTips.cpp Diff File

FreeCAD: master a3bf5421

2016-01-31 13:54:18

wmayer

Details Diff
+ fixes 0002417: console autocomplete runs python properties Affected Issues
0002417
mod - src/Gui/CallTips.cpp Diff File

Issue History

Date Modified Username Field Change
2016-01-23 13:27 looo New Issue
2016-01-31 01:28 wmayer Changeset attached => FreeCAD Master master 0f858f99
2016-01-31 09:50 wmayer Note Added: 0006778
2016-01-31 12:54 wmayer Changeset attached => FreeCAD Master master a3bf5421
2016-01-31 12:54 wmayer Assigned To => wmayer
2016-01-31 12:54 wmayer Status new => closed
2016-01-31 12:54 wmayer Resolution open => fixed
2016-01-31 13:00 wmayer Note Added: 0006779
2016-01-31 13:00 wmayer Fixed in Version => 0.16