Skip to content

Improve metaclass logic#1189

Merged
slozier merged 3 commits intoIronLanguages:masterfrom
BCSharp:metaclass_prepare
Apr 24, 2021
Merged

Improve metaclass logic#1189
slozier merged 3 commits intoIronLanguages:masterfrom
BCSharp:metaclass_prepare

Conversation

@BCSharp
Copy link
Copy Markdown
Member

@BCSharp BCSharp commented Apr 23, 2021

It addresses a part of the problem reported in #1154 (duplicate calls to __prepare__) and several other related issues. Off the top of my head:

  • removes duplicate calls to __init__
  • supports inheriting of __prepare__, __new__, __init__ by metaclasses
  • supports __prepare__ on a function used as "metaclass"
  • fixes interplay when mixing metaclasses provided classes and functions in various scenarios
  • ...

Copy link
Copy Markdown
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.

I'm glad one of us is good at writing tests! Just some minor comments, looks goot to me otherwise.

Comment thread Tests/test_metaclass.py Outdated
Comment thread Src/IronPython/Runtime/Operations/PythonOps.cs Outdated
return obj;
// ------------------------------------------------------------------------

static Func<CodeContext, CodeContext> getClassCode(CodeContext/*!*/ context, FunctionCode funcCode, Func<CodeContext, CodeContext> body) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not that you need to change this, but I usually PascalCase local functions. We should probably adopt a convention. I'll have to check if there's an editorconfig rule for this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I usually use dromedaryCase for anything local (inc. functions) to distinguish it from regular methods. But I am happy to adopt any convention; .editorconfig check would be good. However, I may have committed my dromedaryCase in some other places already, though now I can't find it...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I managed to define an .editorconfig rule, unfortunately it seems like the file has to be open in VS for it to display an issue. Anyway, I opened a bunch of files to see if it would find rule violation and there are indeed a few. An exception to the rule might be the helper methods like link.linkWindows where the casing matches the public parent. Another interesting case is where the local function is essentially replacing lambda (e.g. in SurrogatePassErrors). I assume I would have dromedaryCased the lambda? I guess it's not as clear cut as I thought it was.

@slozier slozier merged commit d492fd8 into IronLanguages:master Apr 24, 2021
@BCSharp BCSharp deleted the metaclass_prepare branch April 24, 2021 16:03
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.

2 participants