Skip to content

Add new dynamic class CustomResourceDict with version support #7

Open
@gordonbondon

Description

@gordonbondon

Current approach with CustomResource["relative/path/to/crd.yaml", "spec", "some_property"] is limited to having only one definition/version in crd file and its impossible to extend with new options. Returned errors always mention TypedDict('Jsonschema') which is not userfriendly.

Instead, we should use get_dynamic_class_hook https://github.com/python/mypy/blob/3acbf3fe78a61c19ff96754233ada453472004c4/mypy/plugin.py#L692-L705 to provide more options while creating custom resource type definition. Possible syntax:

MyResource = CustomResourceDict(
    definition_path="/path/to/crd.yaml",
    property_path: ["spec", "some_property"]
    group: "myapi.io",
    version: "v1",
    kind: "MyResource"
)

First iteration should include these features:

  • CustomResourceDict dynamic hook
  • Handle multiple versions per CustomResourceDefinition
  • Handle multiple definitions per file
  • Set TypeDict name from kind

Similar to https://github.com/lovasoa/marshmallow_dataclass/blob/513e8bfc0dcef02314180790486cea3c04f65178/marshmallow_dataclass/mypy.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions