Open slide opened 7 years ago
Should File2.py have "from File1 import DB"?
On Sun, Nov 13, 2016 at 5:30 PM Gui Talarico notifications@github.com wrote:
I have been struggling with this for while, and haven't been able to find any information on it. I understand this might not be enough information for you to be able to help, so please feel free to close it.
I have no idea, if this is a IronPython bug, or something about imports in Python I am not aware of. I also can't provide a good repro case, since this assembly will not load outside the program environment (Autodesk Revit), so will provide a generic equivalent case below.
Any information/ideas on what could be causing this would be greatly appreciated. File1.py
import clr clr.AddReference('RevitAPI') # Contains Autodesk.Revit.DB namespace from Autodesk.Revit import DBDB.Element.Name # OK. DB.Element.Name.GetValue() # OK: Method exists. As Expected
File2.py
from File2 import DBDB.Element.Name # OK DB.Element.Name.GetValue() # Method DOES NOT Exist, get an Attribute Error is raised. from Autodesk.Revit import DB # Re-import the same namespace again DB.Element.Name.GetValue() # OK: Method Exists
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/IronLanguages/main/issues/1540, or mute the thread https://github.com/notifications/unsubscribe-auth/AADaP4Pp1GAbgPF8TWqrlfFRyf-jbzksks5q96u3gaJpZM4Kw26Q .
From @gtalarico on November 14, 2016 0:53
Thanks slide, sorry, typo in example. I have revised the code sample.
PS: cross posted this on Stack Overflow, I will post back and close If I get a response. http://stackoverflow.com/questions/40580471/net-assembly-loses-some-methods-when-imported-from-one-python-file-into-another
From @andygraham on November 14, 2016 18:56
I don't know if this is related to the above or is a different feature concerning the mapping of .NET Object class to the Python object class.
I tried the same but using Form from System.Windows.Form and found four methods missing. Interestingly they seem to be four base methods of the .NET Object class. They are visible in the Form class in file1 but missing in the imported Form class in file2.
Equals GetHashCode GetType ReferenceEquals
Doing it with Int16 includes Equals and GetHashCode but loses
GetType MemberwiseClone ReferenceEquals
different but again base methods from Object.
Trying it with various .NET classes I get various numbers of different methods missing. There seems no consistency except they always seem to be the Object base methods.
From @gtalarico on November 20, 2016 0:2
@slide can you reproduce this as well?
I can look into this next week.
From @andygraham on November 20, 2016 9:35
Here is the code I used to test it - might save you a few minutes!
produce it. Run file2.py
From @PMoureu on December 7, 2016 2:0
This may be linked to clr, and how it handles the references to the DLL used in each cases.
In each 2nd file, all references come back just by adding :
import clr
Same results if you import another namespace from the assembly like
from Autodesk.Revit.UI import TaskDialog
or
from System.Windows.Forms import Label
"Such context change is per-python-module" https://blogs.msdn.microsoft.com/haibo_luo/2007/09/
From @andygraham on December 7, 2016 8:51
That's interesting! I didn't think of trying that - though I probably should have :(. I would have expected all the .NET methods or none to be available without clr imported. I wonder why only a random few go missing!
Just wanted to post a work-around I found for my specific case where the GetValue / SetValue are missing. The internal dunder method still works:
>>> DB.Element.Name.GetValue(self._revit_object)
'getset_descriptor' object has no attribute 'GetValue'
>>> DB.Element.Name.__get__(self._revit_object)
ABC
PS: In my case, importing clr or reimporting class is not fixing, not sure why.
From @gtalarico on November 14, 2016 0:30
I have been struggling with this for while, and haven't been able to find any information on it. I understand this might not be enough information for you to be able to help, so please feel free to close it.
I have no idea, if this is a IronPython bug, or something about imports in Python I am not aware of. I also can't provide a good repro case, since this assembly will not load outside the program environment (Autodesk Revit), so will provide a generic equivalent case below.
Any information/ideas on what could be causing this would be greatly appreciated.
File1.py
File2.py
Copied from original issue: IronLanguages/main#1540