Skip to content

Commit

Permalink
mid work
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Aug 29, 2024
1 parent dc77d6c commit 29a125b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@jsii/python-runtime/src/jsii/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ 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)
cls.__jsii_proxy_class__ = getattr(cls, "__jsii_proxy_class__", lambda : None)

# https://github.com/agronholm/typeguard/issues/479
cls.__protocol_attrs__ = getattr(cls, "__protocol_attrs__", [])
Expand Down
31 changes: 30 additions & 1 deletion packages/@jsii/python-runtime/tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ def test_inheritance_maintained(self):

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

class TestImplementsInterface:

def test_jsii_proxy_class_defaults_to_none(self) -> None:
@jsii.implements(IBaz)
class MyBaz():
pass

klass = getattr(MyBaz, "__jsii_proxy_class__")()
assert klass == None

def test_jsii_proxy_class_preserves_user_defined_attribute(self) -> None:

class _MyBazProxy():
def baz_method(self) -> str:
return "_MyBazProxy"

@jsii.implements(IBaz)
class MyBaz():

@staticmethod
def __jsii_proxy_class__():
return _MyBazProxy

def baz_method(self) -> str:
return "MyBaz"

klass = getattr(MyBaz, "__jsii_proxy_class__")()
instance = klass()
assert instance.baz_method() == "_MyBazProxy"

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

Expand All @@ -42,7 +72,6 @@ def baz_interface_func(b: IBaz) -> None:
baz = Baz()
baz_interface_func(baz)


def test_overrides_method_with_kwargs() -> None:
class Overridden(OverrideMe):
def implement_me(
Expand Down

0 comments on commit 29a125b

Please sign in to comment.