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(python): maintain inheritance chain for structs #482

Merged
merged 1 commit into from
Apr 23, 2019

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Apr 23, 2019

Because structs all inherit from TypedDict, and TypedDict erases the
inheritance chain of structs, we have to maintain a copy of the
inheritance hierarchy on the class objects, for later use during
doc generation.

This addresses (part of) #473.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Because structs all inherit from TypedDict, and TypedDict erases the
inheritance chain of structs, we have to maintain a copy of the
inheritance hierarchy on the class objects, for later use during
doc generation.

This addresses (part of) #473.
@rix0rrr rix0rrr requested review from dstufft and a team as code owners April 23, 2019 12:23
code.openBlock(`class _${this.name}(${classParams.concat(["total=False"]).join(", ")})`);
for (const member of optionalMembers) {
member.emit(code, resolver);
}
code.closeBlock();

// Now we'll emit the mandatory members.
code.line(`@jsii.data_type(jsii_type="${this.fqn}")`);
code.line(`@jsii.data_type(jsii_type="${this.fqn}", jsii_struct_bases=[_${this.name}])`);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the _ for here?

Copy link
Contributor Author

@rix0rrr rix0rrr Apr 23, 2019

Choose a reason for hiding this comment

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

Every struct gets compiled into 2 classes:

class _MyStruct(...):
  ...

class MyStruct(_MyStruct):
  ...

One holds the required fields, the other one the optional fields.

@rix0rrr rix0rrr merged commit 607f151 into master Apr 23, 2019
@rix0rrr rix0rrr deleted the huijbers/mirror-inheritance-chain branch April 23, 2019 13:09
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