diff --git a/packages/jsii-pacmak/lib/targets/python.ts b/packages/jsii-pacmak/lib/targets/python.ts index 63493f0eba..048a6b5cd7 100644 --- a/packages/jsii-pacmak/lib/targets/python.ts +++ b/packages/jsii-pacmak/lib/targets/python.ts @@ -593,6 +593,7 @@ abstract class BaseMethod implements PythonBase { const paramType = toTypeName(prop.prop).pythonType({ ...context, parameterType: true, + typeAnnotation: true, }); const paramDefault = prop.prop.optional ? ' = None' : ''; @@ -1133,10 +1134,10 @@ class Struct extends BasePythonClassType { // Re-type struct arguments that were passed as "dict". Do this before validating argument types... for (const member of members.filter((m) => m.isStruct(this.generator))) { // Note that "None" is NOT an instance of dict (that's convenient!) - const typeName = toPythonFullName( - (member.type.type as spec.NamedTypeReference).fqn, - context.assembly, - ); + const typeName = toTypeName(member.type.type).pythonType({ + ...context, + typeAnnotation: false, + }); code.openBlock(`if isinstance(${member.pythonName}, dict)`); code.line(`${member.pythonName} = ${typeName}(**${member.pythonName})`); code.closeBlock(); diff --git a/packages/jsii-pacmak/lib/targets/python/type-name.ts b/packages/jsii-pacmak/lib/targets/python/type-name.ts index 2ca14c7ed1..5092adebc7 100644 --- a/packages/jsii-pacmak/lib/targets/python/type-name.ts +++ b/packages/jsii-pacmak/lib/targets/python/type-name.ts @@ -335,7 +335,7 @@ class UserType implements TypeName { // Identify declarations that are not yet initialized and hence cannot be // used as part of a type qualification. Since this is not a forward // reference, the type was already emitted and its un-qualified name must - // be used instead of it's locally qualified name. + // be used instead of its locally qualified name. const nestingParent = surroundingTypeFqns ?.map((fqn) => toPythonFqn(fqn, assembly).pythonFqn) ?.reverse() @@ -357,7 +357,7 @@ class UserType implements TypeName { // This is not for a type annotation, so we should be at a point in time // where the surrounding symbol has been defined entirely, so we can // refer to it "normally" now. - return { pythonType: pythonFqn.substring(nestingParent.length + 1) }; + return { pythonType: pythonFqn.slice(packageName.length + 1) }; } // We'll just make a module-qualified reference at this point. @@ -380,7 +380,7 @@ class UserType implements TypeName { const alias = `_${toImport}_${aliasSuffix}`; return { - pythonType: [alias, ...nested].join('.'), + pythonType: wrapType([alias, ...nested].join('.')), requiredImport: { sourcePackage: relativeImportPath( submodulePythonName,