Ironpython 3.4: issue with enum when using its `None` member ?
Describe the bug
Apparently ironpython 3.4 has an issue with some Enum. It might be related to None member.
It affects apparently all script which using a WPFWindow.
from pyrevit.forms import WPFWindow
It triggers an error here: https://github.com/eirannejad/pyRevit/blob/6aa2c493231f4301125f2570dc5efd644691bbad/pyrevitlib/rpw/ui/forms/taskdialog.py#L140
To Reproduce Steps to reproduce the behavior:
- Use a script including following code:
from Autodesk.Revit.UI import TaskDialogResult
TaskDialogResult.None
- You should get an error message like:
TaskDialogResult.None
^
SyntaxError: invalid syntax
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Windows 11
- pyRevit Version 4.8.13
Additional context I found no related issue in ironpython repository.
Could you write this import and test?
from Autodesk.Revit.UI import TaskDialogResult
Could you write this import and test?
from Autodesk.Revit.UI import TaskDialogResult
It is what I did in steps To reproduce. Import works. Error is thrown when calling None member. (You can use revitpythonshell 2.0.1 to test, you get the same result)
Okay, I see. I found solution in dynamo wiki.
https://github.com/DynamoDS/Dynamo/wiki/Work-in-progress-to-improve-Python-3-support#accessing-a-net-property-or-enum-named-none-fails-with-syntaxerror-not-planned
Ah… Yes. Now I remember that I already encountered this issue on some of my CPython scripts. Thanks @dosymep
It is an easy fix. As rpw have not been updated for more than 4 years maybe we should commit directly to pyRevit ?
Although I do not understand yet why using WPFWindow needs to be related to rpw at all.
Hi,
for info instead of
self.dialog.DefaultButton = UI.TaskDialogResult.None
you can also use
self.dialog.DefaultButton = UI.TaskDialogResult["None"]
there is an IronPython3 doc about upgrading from ipy2 here https://github.com/IronLanguages/ironpython3/blob/v3.4.0/Documentation/upgrading-from-ipy2.md#none-is-a-keyword
there is also a method in coreutils for that: get_enum_none
@CyrilWaechter I did merge you PR but you may want to check if @nodatasheet link does the job
@CyrilWaechter I did merge you PR but you may want to check if @nodatasheet link does the job
The coreutils get_enum_none is using a loop and compare each value to None which is less efficient than a a dict call or whatever is used by standard ironpython function.
The fix that was pushed for this appears to create an issue when the tool is still being run with IronPython 2. You will get the following error: TypeError: expected Array[Type], got str
Is the plan going forward to deprecate support for IronPython 2?
The fix that was pushed for this appears to create an issue when the tool is still being run with IronPython 2. You will get the following error: TypeError: expected Array[Type], got str
Is the plan going forward to deprecate support for IronPython 2?
The fix works with ironpython 2. Ironpython 2.7.10 is still default on my setup and it still works fine.
Okay, yea I'm seeing the issue on v 2.7.7. I'm not sure what pyRevit assumes the default version to be, but perhaps we can add a check here or something.
Okay, yea I'm seeing the issue on v 2.7.7. I'm not sure what pyRevit assumes the default version to be, but perhaps we can add a check here or something.
From what I remember ironpython 2.7.7 was maintained because it was shipped with Dynamo to ensure compatibility with Dynamo script. Dynamo have been shipping ironpython 2.7.9 from version 2.4.0 and ironpython2 evaluator is not shipped anymore from 2.13. If it is really an ironpython version issue I would vote to deprecate ironpython < 2.7.10.
2.7.7 was released in 2016… 8 years old. It’s time to update.
References:
- Dynamo release notes: https://github.com/DynamoDS/Dynamo/wiki/Release-Notes
- Ironpython website: https://ironpython.net/
Edit: also there was so many fixes between 2.7.7 and 2.7.10… When an user have an issue, checking ironpython version is first step to solve many issues.
@CyrilWaechter what action do you suggest on the pyRevit repo side, if any?
@CyrilWaechter what action do you suggest on the pyRevit repo side, if any?
Remove older ironpython engines (At least < 2.7.9). I wonder if there is still a reason to ship multiple ironpython2 engines ? If not maybe it would worth even to ship only 2.7.12 which is the last version available.
On user side there might be a need to push ironpython engine update. Maybe:
- Step 1 (pyRevit release n): warn user that older engines will be deprecated and propose them to update
- Step 2 (pyRevit release n+1): remove deprecated engines
@jmcouffin, Maybe good idea support only latest version IronPython2, IronPython3 and PythonNet
Added this item to the next release roadmap. @dosymep Will discuss at next meetup
Now, the 2711 engine is the only one available for ipy2. Older engines have been removed. Closing for now