Skip to content

Commit

Permalink
fix(python): dynamic proxies handling of setters
Browse files Browse the repository at this point in the history
The Dyanmic proxies were missing an implementation of `__setattr__`,
which caused setter invokations to not be forwarded to the `node`
process.

This is what causes aws/aws-cdk#5032
  • Loading branch information
RomainMuller committed Nov 14, 2019
1 parent a820217 commit eec9640
Show file tree
Hide file tree
Showing 16 changed files with 516 additions and 4 deletions.
29 changes: 29 additions & 0 deletions packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2266,3 +2266,32 @@ export class Demonstrate982 {

public constructor() { }
}

/**
* Make sure that setters are properly called on objects with interfaces
*/
export interface IObjectWithProperty {
property: string;
wasSet(): boolean;
}
export class ObjectWithPropertyProvider {
public static provide(): IObjectWithProperty {
class Impl implements IObjectWithProperty {
private _property: string = '';
private _wasSet = false;

public get property() { return this._property; }
public set property(value: string) {
this._property = value;
this._wasSet = true;
}

public wasSet() {
return this._wasSet;
}
}
return new Impl();
}

private constructor() { }
}
81 changes: 80 additions & 1 deletion packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -5118,6 +5118,54 @@
}
]
},
"jsii-calc.IObjectWithProperty": {
"assembly": "jsii-calc",
"docs": {
"stability": "experimental",
"summary": "Make sure that setters are properly called on objects with interfaces."
},
"fqn": "jsii-calc.IObjectWithProperty",
"kind": "interface",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2273
},
"methods": [
{
"abstract": true,
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2275
},
"name": "wasSet",
"returns": {
"type": {
"primitive": "boolean"
}
}
}
],
"name": "IObjectWithProperty",
"properties": [
{
"abstract": true,
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2274
},
"name": "property",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IPrivatelyImplemented": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -7360,6 +7408,37 @@
],
"name": "ObjectRefsInCollections"
},
"jsii-calc.ObjectWithPropertyProvider": {
"assembly": "jsii-calc",
"docs": {
"stability": "experimental"
},
"fqn": "jsii-calc.ObjectWithPropertyProvider",
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2277
},
"methods": [
{
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2278
},
"name": "provide",
"returns": {
"type": {
"fqn": "jsii-calc.IObjectWithProperty"
}
},
"static": true
}
],
"name": "ObjectWithPropertyProvider"
},
"jsii-calc.Old": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -11128,5 +11207,5 @@
}
},
"version": "0.20.5",
"fingerprint": "g9C1lL8c+vgxBjOWVBFMMPlcwkF3Z81xxTAGfc73x9o="
"fingerprint": "0rO96JPKRUt2x4hOyoCkj3VQvwUDmrvfFTBOkOvT86M="
}
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public void VariadicCallbacksAreHandledCorrectly()
}

[Fact(DisplayName = Prefix + nameof(ReturnSubclassThatImplementsInterface976))]
public void ReturnSubclassThatImplementsInterface976()
public void ReturnSubclassThatImplementsInterface976()
{
var obj = SomeTypeJsii976.ReturnReturn();
Assert.Equal(obj.Foo, 333);
Expand Down Expand Up @@ -1265,5 +1265,13 @@ public void StructsCanBeDowncastedToParentType()
Assert.NotNull(Demonstrate982.TakeThis());
Assert.NotNull(Demonstrate982.TakeThisToo());
}

[Fact(DisplayName = Prefix + nameof(CanUseInterfaceSetters))]
public void CanUseInterfaceSetters()
{
var obj = ObjectWithPropertyProvider.Provide();
obj.Property = "New Value";
Assert.True(obj.WasSet());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1553,4 +1553,11 @@ public java.lang.Number next() {
return next;
}
}

@Test
public void canUseInterfaceSetters() {
final IObjectWithProperty obj = ObjectWithPropertyProvider.provide();
obj.setProperty("New Value");
assertTrue(obj.wasSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5118,6 +5118,54 @@
}
]
},
"jsii-calc.IObjectWithProperty": {
"assembly": "jsii-calc",
"docs": {
"stability": "experimental",
"summary": "Make sure that setters are properly called on objects with interfaces."
},
"fqn": "jsii-calc.IObjectWithProperty",
"kind": "interface",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2273
},
"methods": [
{
"abstract": true,
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2275
},
"name": "wasSet",
"returns": {
"type": {
"primitive": "boolean"
}
}
}
],
"name": "IObjectWithProperty",
"properties": [
{
"abstract": true,
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2274
},
"name": "property",
"type": {
"primitive": "string"
}
}
]
},
"jsii-calc.IPrivatelyImplemented": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -7360,6 +7408,37 @@
],
"name": "ObjectRefsInCollections"
},
"jsii-calc.ObjectWithPropertyProvider": {
"assembly": "jsii-calc",
"docs": {
"stability": "experimental"
},
"fqn": "jsii-calc.ObjectWithPropertyProvider",
"kind": "class",
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2277
},
"methods": [
{
"docs": {
"stability": "experimental"
},
"locationInModule": {
"filename": "lib/compliance.ts",
"line": 2278
},
"name": "provide",
"returns": {
"type": {
"fqn": "jsii-calc.IObjectWithProperty"
}
},
"static": true
}
],
"name": "ObjectWithPropertyProvider"
},
"jsii-calc.Old": {
"assembly": "jsii-calc",
"docs": {
Expand Down Expand Up @@ -11128,5 +11207,5 @@
}
},
"version": "0.20.5",
"fingerprint": "g9C1lL8c+vgxBjOWVBFMMPlcwkF3Z81xxTAGfc73x9o="
"fingerprint": "0rO96JPKRUt2x4hOyoCkj3VQvwUDmrvfFTBOkOvT86M="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
/// <summary>Make sure that setters are properly called on objects with interfaces.</summary>
/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiInterface(nativeType: typeof(IObjectWithProperty), fullyQualifiedName: "jsii-calc.IObjectWithProperty")]
public interface IObjectWithProperty
{
/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiProperty(name: "property", typeJson: "{\"primitive\":\"string\"}")]
string Property
{
get;
set;
}
/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiMethod(name: "wasSet", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}")]
bool WasSet();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
/// <summary>Make sure that setters are properly called on objects with interfaces.</summary>
/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiTypeProxy(nativeType: typeof(IObjectWithProperty), fullyQualifiedName: "jsii-calc.IObjectWithProperty")]
internal sealed class IObjectWithPropertyProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IObjectWithProperty
{
private IObjectWithPropertyProxy(ByRefValue reference): base(reference)
{
}

/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiProperty(name: "property", typeJson: "{\"primitive\":\"string\"}")]
public string Property
{
get => GetInstanceProperty<string>();
set => SetInstanceProperty(value);
}

/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiMethod(name: "wasSet", returnsJson: "{\"type\":{\"primitive\":\"boolean\"}}")]
public bool WasSet()
{
return InvokeInstanceMethod<bool>(new System.Type[]{}, new object[]{});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace
{
/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.ObjectWithPropertyProvider), fullyQualifiedName: "jsii-calc.ObjectWithPropertyProvider")]
public class ObjectWithPropertyProvider : DeputyBase
{
protected ObjectWithPropertyProvider(ByRefValue reference): base(reference)
{
}

protected ObjectWithPropertyProvider(DeputyProps props): base(props)
{
}

/// <remarks>
/// stability: Experimental
/// </remarks>
[JsiiMethod(name: "provide", returnsJson: "{\"type\":{\"fqn\":\"jsii-calc.IObjectWithProperty\"}}")]
public static Amazon.JSII.Tests.CalculatorNamespace.IObjectWithProperty Provide()
{
return InvokeStaticMethod<Amazon.JSII.Tests.CalculatorNamespace.IObjectWithProperty>(typeof(Amazon.JSII.Tests.CalculatorNamespace.ObjectWithPropertyProvider), new System.Type[]{}, new object[]{});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
case "jsii-calc.IJsii496": return software.amazon.jsii.tests.calculator.IJsii496.class;
case "jsii-calc.IMutableObjectLiteral": return software.amazon.jsii.tests.calculator.IMutableObjectLiteral.class;
case "jsii-calc.INonInternalInterface": return software.amazon.jsii.tests.calculator.INonInternalInterface.class;
case "jsii-calc.IObjectWithProperty": return software.amazon.jsii.tests.calculator.IObjectWithProperty.class;
case "jsii-calc.IPrivatelyImplemented": return software.amazon.jsii.tests.calculator.IPrivatelyImplemented.class;
case "jsii-calc.IPublicInterface": return software.amazon.jsii.tests.calculator.IPublicInterface.class;
case "jsii-calc.IPublicInterface2": return software.amazon.jsii.tests.calculator.IPublicInterface2.class;
Expand Down Expand Up @@ -135,6 +136,7 @@ protected Class<?> resolveClass(final String fqn) throws ClassNotFoundException
case "jsii-calc.NullShouldBeTreatedAsUndefinedData": return software.amazon.jsii.tests.calculator.NullShouldBeTreatedAsUndefinedData.class;
case "jsii-calc.NumberGenerator": return software.amazon.jsii.tests.calculator.NumberGenerator.class;
case "jsii-calc.ObjectRefsInCollections": return software.amazon.jsii.tests.calculator.ObjectRefsInCollections.class;
case "jsii-calc.ObjectWithPropertyProvider": return software.amazon.jsii.tests.calculator.ObjectWithPropertyProvider.class;
case "jsii-calc.Old": return software.amazon.jsii.tests.calculator.Old.class;
case "jsii-calc.OptionalArgumentInvoker": return software.amazon.jsii.tests.calculator.OptionalArgumentInvoker.class;
case "jsii-calc.OptionalConstructorArgument": return software.amazon.jsii.tests.calculator.OptionalConstructorArgument.class;
Expand Down
Loading

0 comments on commit eec9640

Please sign in to comment.