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

Get __class__ keyword works without AST modification #734

Conversation

in-code-i-trust
Copy link
Contributor

@in-code-i-trust in-code-i-trust commented Feb 2, 2020

Hi, this resolves #723.
As the subject says, the AST modification (introduced in #721) has been removed.

Changes are...

  1. Reverted Get super() and __class__ works in non-global context. #721
  2. Introduced GetGrandParentContextFromFunction() to make __class__ handling code works. c.f.) FunctionDefinition.cs
  3. Imported test from __class__ is replaced with the name of the class in the AST #723

@in-code-i-trust in-code-i-trust changed the title Get class keyword works without ast patching Get __class__ keyword works without AST modification Feb 2, 2020
Copy link
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. There seems to be some sort of binding issue. For whatever reason the following example returns the function instead of the class.

class test(object):
    def test(self):
        def test2():
          return __class__
        return test2()

assert test().test() == test

@@ -229,6 +231,8 @@ internal class DebugProxy {
}
}

internal CodeContext GrandParentContext => _maybegrandparent;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe drop the _maybegrandparent field and use an auto-implemented property?

internal CodeContext GrandParentContext { get; }


/// <summary>
/// Creates a new CodeContext which is backed by the specified Python dictionary.
/// </summary>
public CodeContext(PythonDictionary/*!*/ dict, ModuleContext/*!*/ moduleContext) {
public CodeContext(PythonDictionary/*!*/ dict, ModuleContext/*!*/ moduleContext, CodeContext maybegrandparent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a concept that should be exposed publicly? Maybe add an internal constructor overload instead?

@slozier
Copy link
Contributor

slozier commented Mar 6, 2021

Thanks for the PR! Closing this since the issue has been resolved by #1087

@slozier slozier closed this Mar 6, 2021
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.

__class__ is replaced with the name of the class in the AST
2 participants