Skip to content

(Python): @jsii.python.classproperty not working as intended with type checking #3633

Open
@gshpychka

Description

@gshpychka

Describe the bug

Static properties in the generated Python code are not correctly interpreted by the type checking system. They're recognized as class methods, and require casting.

Consider the following example snippet:

ec2.Vpc(self, "vpc", sugnet_configuration=ec2.Vpc.DEFAULT_SUBNETS)

Expected Behavior

pyright does not report any issues

Current Behavior

Type checker interprets the type of the property as a callable method

error: Argument of type "(cls: Vpc) -> List[SubnetConfiguration]" cannot be assigned to parameter "subnet_configuration" of type "Sequence[SubnetConfiguration] | None" in function "__init__"
    Type "(cls: Vpc) -> List[SubnetConfiguration]" cannot be assigned to type "Sequence[SubnetConfiguration] | None"
      "object" is incompatible with "Sequence[SubnetConfiguration]"
      Type cannot be assigned to type "None"

Reproduction Steps

Use any static property and enable type checking.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.61.0

Environment details (OS name and version, etc.)

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.effort/mediumMedium work item – a couple days of effortlanguage/pythonRelated to Python bindingsp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions