pyRevit icon indicating copy to clipboard operation
pyRevit copied to clipboard

Ironpython 3.4:  issue with enum when using its `None` member ?

Open CyrilWaechter opened this issue 2 years ago • 16 comments

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:

  1. Use a script including following code:
from Autodesk.Revit.UI import TaskDialogResult
TaskDialogResult.None
  1. 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.

CyrilWaechter avatar Jul 19 '23 08:07 CyrilWaechter

Could you write this import and test?

from Autodesk.Revit.UI import TaskDialogResult

dosymep avatar Jul 19 '23 09:07 dosymep

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)

CyrilWaechter avatar Jul 19 '23 09:07 CyrilWaechter

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

dosymep avatar Jul 19 '23 11:07 dosymep

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.

CyrilWaechter avatar Jul 19 '23 12:07 CyrilWaechter

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

Cyril-Pop avatar Jul 20 '23 17:07 Cyril-Pop

there is also a method in coreutils for that: get_enum_none

nodatasheet avatar Jul 29 '23 17:07 nodatasheet

@CyrilWaechter I did merge you PR but you may want to check if @nodatasheet link does the job

jmcouffin avatar Aug 07 '23 18:08 jmcouffin

@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.

CyrilWaechter avatar Aug 18 '23 08:08 CyrilWaechter

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?

jbf1212 avatar Feb 07 '24 17:02 jbf1212

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.

CyrilWaechter avatar Feb 07 '24 18:02 CyrilWaechter

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.

jbf1212 avatar Feb 07 '24 18:02 jbf1212

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 avatar Feb 08 '24 09:02 CyrilWaechter

@CyrilWaechter what action do you suggest on the pyRevit repo side, if any?

jmcouffin avatar Feb 08 '24 09:02 jmcouffin

@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

CyrilWaechter avatar Feb 08 '24 09:02 CyrilWaechter

@jmcouffin, Maybe good idea support only latest version IronPython2, IronPython3 and PythonNet

dosymep avatar Feb 08 '24 10:02 dosymep

Added this item to the next release roadmap. @dosymep Will discuss at next meetup

jmcouffin avatar Feb 08 '24 10:02 jmcouffin

Now, the 2711 engine is the only one available for ipy2. Older engines have been removed. Closing for now

jmcouffin avatar Apr 03 '24 07:04 jmcouffin