Python: Cannot pass Enum value when str expected
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
Description
### Describe the bug
In Python, Enum members cannot be passed in lieu of strings.
For example, the Enum `cloudwatch.Statistic` cannot be used as described in the code examples in the docs.
Here's the exact example that's currently in the docs:
```
import aws_cdk.aws_cloudwatch as cloudwatch
# delivery_stream: firehose.DeliveryStream
# Alarm that triggers when the per-second average of incoming bytes exceeds 90% of the current service limit
incoming_bytes_percent_of_limit = cloudwatch.MathExpression(
expression="incomingBytes / 300 / bytePerSecLimit",
using_metrics={
"incoming_bytes": delivery_stream.metric_incoming_bytes(statistic=cloudwatch.Statistic.SUM),
"byte_per_sec_limit": delivery_stream.metric("BytesPerSecondLimit")
}
)
```
### Expected Behavior
The code example works.
### Current Behavior
Exception during synth:
```
TypeError: type of argument statistic must be one of (str, NoneType); got aws_cdk.aws_cloudwatch.Statistic instead
```
### Reproduction Steps
Simpler example:
```
from aws_cdk import aws_cloudwatch as cw
cw.Metric(namespace="foo", metric_name="bar", statistic=cw.Statistic.SUM)
```
### Possible Solution
The current workaround is to use the `.value` prop of the enum member and pass that.
### Additional Information/Context
_No response_
### SDK version used
1.64.0
### Environment details (OS name and version, etc.)
Linux
Contributor guide
Research direction
The entry point shown is Python's cw.Metric(..., statistic=cw.Statistic.SUM); start by reproducing that call in the jsii Python runtime and tracing argument conversion for enum values. Done means the documented CloudWatch example and simpler Metric example synthesize without requiring .value, while existing behavior remains intact.
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
- Mostly clear
- Newbie friendliness
- 38/100