aws / aws/jsii

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

Open
#3,633 11 comments 0 reactions 0 assignees View on GitHub
bug effort/medium language/python p1
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### 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

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Vpc.DEFAULT_SUBNETS example with pyright and inspect the generated Python typing for @jsii.python.classproperty. Trace how static properties are represented and add a regression test for the generated type; done means pyright accepts the property without a cast.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.