jsii icon indicating copy to clipboard operation
jsii copied to clipboard

Update Python dependencies (typeguard)

Open osqui0110 opened this issue 2 years ago • 13 comments

Hey! I'm not sure about how you manage python dependencies. I'm working on a project using glue Python shell scripts. Trying to add Pandera to validate Pandas DFs, my dependency manager (poetry) shows:

Because no versions of pandera match >0.18.0,<0.19.0
 and pandera (0.18.0) depends on typeguard (>=3.0.2), pandera (>=0.18.0,<0.19.0) requires typeguard (>=3.0.2).
And because constructs (10.3.0) depends on typeguard (>=2.13.3,<2.14.0)
 and no versions of constructs match >10.3.0,<11.0.0, pandera (>=0.18.0,<0.19.0) is incompatible with constructs (>=10.3.0,<11.0.0).
So, because testglue depends on both constructs (^10.3.0) and pandera (^0.18.0), version solving failed.

That version of Typeguard is quite old (currently 4.x)

Is it possible to use updated dependencies? thx!

osqui0110 avatar Jan 18 '24 16:01 osqui0110

Dear AWS Team,

We are in the same situation as @osqui0110. Would it be possible to update the typeguard version.

Thank you and all the best!

iwanbolzern avatar Mar 14 '24 12:03 iwanbolzern

I hoppend a PR for jsii to fix this: https://github.com/aws/jsii/pull/4455 It would be great if someone could review it.

iwanbolzern avatar Mar 14 '24 15:03 iwanbolzern

@mrgrain Me again, seeing a similar issue here with pinned typeguard package for the python runtime. Let me know if you think this can also be upgraded. Thanks.

MatthewGrant avatar Oct 10 '24 16:10 MatthewGrant

The latest release should include this: https://github.com/aws/constructs/releases/tag/v10.3.1

LMK if it works.

mrgrain avatar Oct 10 '24 17:10 mrgrain

The latest release should include this: https://github.com/aws/constructs/releases/tag/v10.3.1

LMK if it works.

You're the best! Looks like we are all good now. Thanks.

MatthewGrant avatar Oct 10 '24 17:10 MatthewGrant

constructs==10.3.1 (which pip installed with typeguard==4.3.0) broke our deployment which was creating an NLB through aws-cdk-lib==2.162.0, just as an FYI:

$ python
Python 3.12.7 (main, Oct  7 2024, 11:35:44) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from aws_cdk import aws_ec2 as ec2, aws_elasticloadbalancingv2 as elb2
>>> from aws_cdk import Stack
>>> stack = Stack()
>>> vpc = ec2.Vpc(stack, "test-vpc")
>>> nlb = elb2.NetworkLoadBalancer(stack, "test-nlb", vpc=vpc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 16504, in __init__
    props = NetworkLoadBalancerProps(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 17314, in __init__
    check_type(argname="argument vpc", value=vpc, expected_type=type_hints["vpc"])
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 967, in check_type
    typeguard.check_type(value=value, expected_type=expected_type, collection_check_strategy=typeguard.CollectionCheckStrategy.ALL_ITEMS) # type:ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_functions.py", line 106, in check_type
    check_type_internal(value, expected_type, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 861, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 729, in check_protocol
    raise TypeCheckError(
typeguard.TypeCheckError: aws_cdk.aws_ec2.Vpc is not compatible with the IVpc protocol because its 'add_client_vpn_endpoint' method has mandatory keyword-only arguments in its declaration: cidr, server_certificate_arn

berkaycagir avatar Oct 11 '24 07:10 berkaycagir

Thanks for the report @berkaycagir Can you help me understand what's the issue here?

It looks the new release of constructs caused your python project to now install typeguard v4, whereas previously it would pick typeguard v2?

And with that newer version of typeguard, there's an incompatibility with the VPC construct in aws-cdk-lib?

Does that some it up alright?

mrgrain avatar Oct 11 '24 09:10 mrgrain

constructs==10.3.1 (which pip installed with typeguard==4.3.0) broke our deployment which was creating an NLB through aws-cdk-lib==2.162.0, just as an FYI:

$ python
Python 3.12.7 (main, Oct  7 2024, 11:35:44) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from aws_cdk import aws_ec2 as ec2, aws_elasticloadbalancingv2 as elb2
>>> from aws_cdk import Stack
>>> stack = Stack()
>>> vpc = ec2.Vpc(stack, "test-vpc")
>>> nlb = elb2.NetworkLoadBalancer(stack, "test-nlb", vpc=vpc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 16504, in __init__
    props = NetworkLoadBalancerProps(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 17314, in __init__
    check_type(argname="argument vpc", value=vpc, expected_type=type_hints["vpc"])
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 967, in check_type
    typeguard.check_type(value=value, expected_type=expected_type, collection_check_strategy=typeguard.CollectionCheckStrategy.ALL_ITEMS) # type:ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_functions.py", line 106, in check_type
    check_type_internal(value, expected_type, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 861, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 729, in check_protocol
    raise TypeCheckError(
typeguard.TypeCheckError: aws_cdk.aws_ec2.Vpc is not compatible with the IVpc protocol because its 'add_client_vpn_endpoint' method has mandatory keyword-only arguments in its declaration: cidr, server_certificate_arn

The new typeguard is doing what it should. This error is due to a bug that let's jsii generate broken python code: https://github.com/aws/jsii/issues/4541

fraghag avatar Oct 11 '24 09:10 fraghag

Yes, there's clearly something wrong with the code jsii produces.

https://github.com/aws/jsii/issues/4541 is a known issue, but this case seems to be different because the keyword args do match in both protocol and implementation. 🤔

mrgrain avatar Oct 11 '24 10:10 mrgrain

Continuing the conversation here: https://github.com/aws/jsii/issues/4658

mrgrain avatar Oct 11 '24 11:10 mrgrain

We yanked the 10.3.1 release of constructs from PyPI as a quick mitigation for most users. https://pypi.org/project/constructs/10.3.1/

We will revert this to an older version of typeguard soon.

Re-opened this issue to track that we eventually need to release support for newer typeguard versions.


To discuss the issue itself, please use https://github.com/aws/jsii/issues/4658

mrgrain avatar Oct 11 '24 12:10 mrgrain

Thanks for the report @berkaycagir Can you help me understand what's the issue here?

It looks the new release of constructs caused your python project to now install typeguard v4, whereas previously it would pick typeguard v2?

And with that newer version of typeguard, there's an incompatibility with the VPC construct in aws-cdk-lib?

Does that some it up alright?

I'm sorry I wasn't able to provide more details; but thank you very much for following up on it and the yank, I appreciate it.

berkaycagir avatar Oct 14 '24 12:10 berkaycagir

We had to revert the latest attempt as well, see https://github.com/aws/constructs/issues/2825

Transferring this issue as this is mainly a jsii concern.

mrgrain avatar Dec 11 '25 09:12 mrgrain