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

aws-ec2: ec2.AmazonLinux2Kernel is not an enum in Python #26305

Open
pwrmiller opened this issue Jul 10, 2023 · 3 comments
Open

aws-ec2: ec2.AmazonLinux2Kernel is not an enum in Python #26305

pwrmiller opened this issue Jul 10, 2023 · 3 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@pwrmiller
Copy link

Describe the bug

In Python, AmazonLinux2Kernel is not an enumeration (not an enum.Enum) in CDK -

ec2.AmazonLinux2Kernel.KERNEL_5_10 == ec2.AmazonLinux2Kernel.KERNEL_5_10
False

vs

ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 == ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023
True

We can see that the class of this is not an enumeration, like other enumerations in the aws-ec2 code:

class AmazonLinux2Kernel(
    metaclass=jsii.JSIIMeta,
    jsii_type="aws-cdk-lib.aws_ec2.AmazonLinux2Kernel",
):
    '''Amazon Linux 2 kernel versions.

    :exampleMetadata: infused
# ...
# vs 

@jsii.enum(jsii_type="aws-cdk-lib.aws_ec2.AmazonLinuxGeneration")
class AmazonLinuxGeneration(enum.Enum):
    '''What generation of Amazon Linux to use.
# ...

This inconsistency means it is difficult to compare certain objects in python.

Expected Behavior

I expected an enumeration to be an enumeration - the comparison above should have passed.

Current Behavior

The enumeration was not an enumeration, and the comparison above failed.

Reproduction Steps

The code above should suffice.

Possible Solution

Make these enumerations, enumerations.

Additional Information/Context

No response

CDK CLI Version

2.84.0

Framework Version

No response

Node.js Version

18.16.0

OS

MacOS

Language

Python

Language Version

3.9.6

Other information

No response

@pwrmiller pwrmiller added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 10, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jul 10, 2023
@pahud
Copy link
Contributor

pahud commented Jul 10, 2023

I think it's because of their different internal implementation.

AmazonLinuxGeneration is enum while AmazonLinux2Kernel is actually a class(object in python) and you can't compare object with '==' in python.

@pahud pahud added p2 effort/medium Medium work item – several days of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 10, 2023
@pwrmiller
Copy link
Author

pwrmiller commented Jul 10, 2023

Agreed. Some degree of standardization probably needs to happen here. We should ask: does it make sense to compare two AmazonLinuxGeneration values? Does it also make sense to compare two AmazonLinux2Kernel values?

I think most Python developers would expect things that look like enumerations to be enumerations. As a workaround, for now, I'm using the toString method provided on the AmazonLinux2Kernel class, but it's not ergonomic or pythonic.

@pwrmiller
Copy link
Author

And another thought: if these shouldn't be an enumeration (or if that's breaking), would it make sense to implement the __eq__ method for comparisons for classes like this? What's the JSII mechanism to provide an equality/ comparison?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants