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

Do not merge - Prototype intellisense by emitting function signatures for all classes #2016

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markpeek
Copy link
Member

@markpeek markpeek commented Mar 7, 2022

Based on the auto-gen work and @ITProKyle typing changes, I put together a quick prototype to allow for some intellisense functionality. This is a WIP.

To try out:

- Download the branch
- Install the dev requirements
- make spec
- make regen (note: wafv2 will fail)
- Test with your favorite editor

Issues:

  • Template has a circular dependency so tests fail. Does anyone even use that argument?
  • wafv2 has a "None" property name that doesn't play well with python. Guess no one is using it anyway.
  • Doesn't handle multiple validation types where a Union might be needed.
  • Likely more...this was a quick test.

Might be of interest to @JohnPreston @michael-k

Copy link
Contributor

@michael-k michael-k left a comment

Choose a reason for hiding this comment

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

Generates eg.

class Group(AWSObject):
    def __init__(
        self,
        title: Optional[str],
        template: Optional[Template] = None,
        validation: bool = True,
        *,
        GroupName: iam_group_name = None,
        ManagedPolicyArns: "list[str]" = None,
        Path: iam_path = None,
        Policies: "list[Policy]" = None,
    ):
        ...

but iam_group_name and iam_path aren't valid types. It also shouldn't add = None for required properties.

Personally I'd prefer switching to dataclasses or pydantic instead of generating __init__ methods.

@@ -676,10 +670,13 @@ def _get_type(self, value: Property, stub=False):

if value.type == "List":
if value.item_type:
return "[%s]" % value.item_type
if stub:
return "'list[%s]'" % value.item_type
Copy link
Contributor

Choose a reason for hiding this comment

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

list[…] instead of typing.List[…] is only available in Python 3.9+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants