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

Python: information around struct base classes is lost #473

Closed
rix0rrr opened this issue Apr 19, 2019 · 2 comments
Closed

Python: information around struct base classes is lost #473

rix0rrr opened this issue Apr 19, 2019 · 2 comments
Labels
bug This issue is a bug. closed-for-staleness effort/large Large work item – several weeks of effort language/python Related to Python bindings p2

Comments

@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 19, 2019

Structs are implemented in Python using mypy_extensions.TypedDict.

Unfortunately, this class uses a metaclass that completely destroys class inheritance information:

    def test_inheritance_maintained(self):
        """Check that for JSII struct types the inheritance relationship is maintained."""
        bases = inspect.getmro(jsii_calc.DerivedStruct)
        print(jsii_calc.DerivedStruct.__annotations__)
        print(bases)

The __annotations__ contain all annotations from base classes, but the getmro() returns:

(<class 'importlib._bootstrap.DerivedStruct'>, <class 'dict'>, <class 'object'>)

Even though the actual declaration of DerivedStruct looks like this:

class _DerivedStruct(scope.jsii_calc_lib.MyFirstStruct, jsii.compat.TypedDict, total=False):
    anotherOptional: typing.Mapping[str,scope.jsii_calc_lib.Value]
    """This is optional."""
    optionalAny: typing.Any
    optionalArray: typing.List[str]

@jsii.data_type(jsii_type="jsii-calc.DerivedStruct")
class DerivedStruct(_DerivedStruct):

So we are missing the bases _DerivedStruct and MyFirstStruct (and everything above).

Without these bases, we can't generate docs for those members.

@rix0rrr rix0rrr added bug This issue is a bug. language/python Related to Python bindings p0 labels Apr 19, 2019
@rix0rrr rix0rrr self-assigned this Apr 23, 2019
rix0rrr pushed a commit that referenced this issue 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.
rix0rrr added a commit that referenced this issue 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.
@rix0rrr
Copy link
Contributor Author

rix0rrr commented May 6, 2019

The way I've fixed this now is actually not great, because it's not going to be useful to IDEs.

We should just generate a complete "Attributes" block in the class docstring instead. This can be done later.

@rix0rrr rix0rrr removed the p0 label May 6, 2019
@RomainMuller RomainMuller added this to the Python Support milestone Aug 6, 2019
@rix0rrr rix0rrr added the p2 label Oct 28, 2019
@RomainMuller RomainMuller removed this from the Python Support milestone Jul 21, 2020
@rix0rrr rix0rrr added the effort/large Large work item – several weeks of effort label Aug 27, 2020
@rix0rrr rix0rrr removed their assignment Jun 18, 2021
@github-actions
Copy link
Contributor

This issue has not received any attention in 2 years. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness effort/large Large work item – several weeks of effort language/python Related to Python bindings p2
Projects
None yet
Development

No branches or pull requests

2 participants