Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Enum Cyclic Ref #12617

Merged
merged 6 commits into from
Jul 12, 2021
Merged

Fix Enum Cyclic Ref #12617

merged 6 commits into from
Jul 12, 2021

Conversation

feerrenrut
Copy link
Contributor

Link to issue number:

Blocking PR #12500

Summary of the issue:

When creating DescriptionFor enum values, a "ValueError" can be raised.
There is a bug in the Python standard library for enum, causing a cyclic reference.
The exception is referenced by the frame.
The frame is referenced by the traceback.
The traceback is referenced by the exception.
This is detected by NVDA as an unreachable object, logging an error.

Description of how this pull request fixes the issue:

This patches the enum.Enum.__new__ method to no longer reference the exception from the frame.

Testing strategy:

Merged with #12500, ran with sample, ensured no unreachable object log error.
Unit testing this would be difficult, we'd have to install the NVDA garbageHandler, this would cause side affects for all tests.
These errors are reported to the log of system tests already.
In future we plan for system tests to fail if there are ANY errors in the log, however right now there are several
expected errors in the log on appveyor.
These first need to be resolved.
Additionally, we are in the process of resolving a tricky intermittent failure for system tests.
Once the intermittent failure is resolved we can look to make the tests more strict.

Known issues with pull request:

None

Change log entries:

None

Code Review Checklist:

  • Pull Request description is up to date.
  • Unit tests.
  • System (end to end) tests.
  • Manual testing.
  • User Documentation.
  • Change log entry.
  • Context sensitive help for GUI changes.
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers

@feerrenrut feerrenrut marked this pull request as ready for review July 5, 2021 10:10
@feerrenrut feerrenrut requested a review from a team as a code owner July 5, 2021 10:10
@feerrenrut feerrenrut requested review from seanbudd and michaelDCurran and removed request for seanbudd July 5, 2021 10:10
@feerrenrut feerrenrut mentioned this pull request Jul 5, 2021
9 tasks
@feerrenrut
Copy link
Contributor Author

A diff of the python standard library implementation vs the replacement implementation:
stdLibVsNew.txt

Copy link
Member

@michaelDCurran michaelDCurran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better for maintainability that replacement__new__ is simply:

if value not in cls.__members__.values():
    raise ValueError(f"{value} is not a supported value of {cls}")
return old__new__(value)

Though obviously what you wrote will be useful for a pr against cPython.
But other than the other corrections I and @lukaszgo1 have mentioned, I'd be happy to approve with the code you have here.

devDocs/unreachableObjects.md Outdated Show resolved Hide resolved
devDocs/unreachableObjects.md Outdated Show resolved Hide resolved
feerrenrut and others added 2 commits July 6, 2021 15:30
@feerrenrut
Copy link
Contributor Author

Would it not be better for maintainability that replacement__new__ is simply

I'm trying to maintain compatibility with the built-in enum behavior. There are a number of other values that it accepts for various reasons. Using the suggestion would mean that only values for the enum are accepted.

@feerrenrut feerrenrut requested a review from michaelDCurran July 6, 2021 08:33
@feerrenrut feerrenrut merged commit 8bbbe72 into master Jul 12, 2021
@feerrenrut feerrenrut deleted the fixEnumCyclicRef branch July 12, 2021 03:52
@nvaccessAuto nvaccessAuto added this to the 2021.2 milestone Jul 12, 2021
seanbudd pushed a commit that referenced this pull request Sep 13, 2021
…rent than the one used for building NVDA (#12835)

Fixes regression from #12617. Discovered when working on #12753 as that PR required executing unit tests under various versions of Windows

Summary of the issue:
It is sometimes useful to execute unit tests under various versions of Windows where it is impractical, or even impossible to have full build environment for NVDA. With current master some tests are failing because when importing COM interfaces comtypes complains about them being created on different version of Windows. Before PR #12617 this worked by chance since our monkey patches for compypes were applied when importing core and it just so happened that core was imported before any COM interface was.

Description of how this pull request fixes the issue:
Since we have monkey patch which stops comtypes from complaining about typelib being different than COM interface it has been applied to comtypes before tests starts. To avoid copying code of this monkey patch it was necessary to refactor our monkey patches to make each of them into a separate function - that allows us to apply them selectively rather than just all of them during import.

Testing strategy:
Ensured that unit tests pass under a never version of Windows than the one under which virtual environment for NVDA has been created
Ensured that comtypes monkey patches are properly applied for NVDA in particular that core.CallCancelled is raised when appropriate.
codeofdusk added a commit to codeofdusk/nvda that referenced this pull request Sep 25, 2023
… appears to have been fixed upstream (I can still reproduce it under 3.7 but not under 3.11).
codeofdusk added a commit to codeofdusk/nvda that referenced this pull request Sep 26, 2023
seanbudd pushed a commit that referenced this pull request Sep 26, 2023
…sent in Python 3.11+. (#15531)

Partially reverts #12617.

Summary of the issue:
#12617 added a patched __new__ to work around a GC cycle in Python 3.7. However, on Python 3.11 and 3.12, this is no longer present.

Description of how this pull request fixes the issue:
Remove the patched method.

Testing strategy:
Tested that

On Python 3.7, the cyclic ref is present when the patched __new__ is removed.
On Python 3.11, no unreachable object error is reported in IA2 documents.
On Python 3.12, no unreachable object error is reported in IA2 documents.
seanbudd pushed a commit that referenced this pull request Sep 27, 2023
…sent in Python 3.11+. (#15531)

Partially reverts #12617.

Summary of the issue:
#12617 added a patched __new__ to work around a GC cycle in Python 3.7. However, on Python 3.11 and 3.12, this is no longer present.

Description of how this pull request fixes the issue:
Remove the patched method.

Testing strategy:
Tested that

On Python 3.7, the cyclic ref is present when the patched __new__ is removed.
On Python 3.11, no unreachable object error is reported in IA2 documents.
On Python 3.12, no unreachable object error is reported in IA2 documents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants