Skip to content

Commit

Permalink
feat(pacmak): allow typeguard==3.x and typeguard==4.x (#4611)
Browse files Browse the repository at this point in the history
Currently python projects generated by pacmak define a `typeguard` dependency range of  `typeguard~=2.13.3`, which prevents users from brining newer major version of `typeguard` into their projects. 

This PR adds support for `typeguard==3.x` and `typguard==4.x`, which are the latest versions currently available. We intentionally do not allow an open range because every major version brings breaking changes with it that might need to be addressed.

### Notes

- We couldn't just drop support for `typeguard==2.x` because that would be a breaking change. 
- We could potentially release a new major version of pacmak to make the code more maintainable. My take is that this PR doesn't complicate the code to the extent of justifying a new major version, but lets discuss.

Fixes #4469

---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
iliapolo authored Aug 27, 2024
1 parent b5862e1 commit 32ae5b0
Show file tree
Hide file tree
Showing 9 changed files with 1,722 additions and 344 deletions.
6 changes: 4 additions & 2 deletions packages/@jsii/python-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
"build": "cp ../../../README.md . && rm -f jsii-*.whl && npm run generate && npm run deps && npm run lint",
"lint": "ts-node build-tools/venv.ts black .",
"package": "package-python && package-private",
"test": "npm run test:gen && npm run test:run && npm run test:types",
"test": "npm run test:gen && npm run test:run:typeguard-2 && npm run test:run:typeguard-3 && npm run test:run:typeguard-4 && npm run test:types",
"test:gen": "npm run deps && ts-node build-tools/gen-calc.ts",
"test:run": "ts-node build-tools/venv.ts py.test -v --mypy",
"test:run:typeguard-2": "ts-node build-tools/venv.ts python -m pip install typeguard==2.13.3 && ts-node build-tools/venv.ts py.test -v --mypy",
"test:run:typeguard-3": "ts-node build-tools/venv.ts python -m pip install typeguard==3.0.2 && ts-node build-tools/venv.ts py.test -v --mypy",
"test:run:typeguard-4": "ts-node build-tools/venv.ts python -m pip install typeguard==4.3.0 && ts-node build-tools/venv.ts py.test -v --mypy",
"test:types": "pyright -p .",
"test:update": "UPDATE_DIFF=1 npm run test"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/python-runtime/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"cattrs>=1.8,<23.3",
"importlib_resources>=5.2.0",
"publication>=0.0.3", # This is used by all generated code.
"typeguard~=2.13.3", # This is used by all generated code.
"typeguard>=2.13.3,<5.0.0", # This is used by all generated code.
"python-dateutil",
"typing_extensions>=3.8,<5.0",
],
Expand Down
4 changes: 4 additions & 0 deletions packages/@jsii/python-runtime/src/jsii/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def implements(*interfaces: Type[Any]) -> Callable[[T], T]:
def deco(cls):
cls.__jsii_type__ = getattr(cls, "__jsii_type__", None)
cls.__jsii_ifaces__ = getattr(cls, "__jsii_ifaces__", []) + list(interfaces)
cls.__jsii_proxy_class__ = lambda: getattr(cls, "__jsii_proxy_class__", None)

# https://github.com/agronholm/typeguard/issues/479
cls.__protocol_attrs__ = getattr(cls, "__protocol_attrs__", [])
return cls

return deco
Expand Down
11 changes: 0 additions & 11 deletions packages/@jsii/python-runtime/tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ def test_inheritance_maintained(self):

assert base_names == ["DerivedStruct", "MyFirstStruct"]

def test_descriptive_error_when_passing_function(self):
obj = jsii_calc.Calculator()

with pytest.raises(
TypeError,
match=re.escape(
"type of argument value must be one of (int, float); got method instead"
),
):
obj.add(cast(Any, self.test_descriptive_error_when_passing_function))

def test_implements_interface(self) -> None:
"""Checks that jsii-generated classes correctly implement the relevant jsii-generated interfaces."""

Expand Down
Loading

0 comments on commit 32ae5b0

Please sign in to comment.