Skip to content

Conversation

@steverice
Copy link

No description provided.

? getExtendsType($, props.type)
: undefined;
let basesType = props.bases ? props.bases : (globalBasesType ?? undefined);
function createBasesType(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this function are aimed at allowing us to specify additional bases for the purpose of adding Generic.

Those bases are generated in ClassDeclaration.

Comment on lines +195 to +221
if (
!props.type.isFinished &&
(props.type.node as TemplateDeclarationNode)?.templateParameters
) {
const templateParameters = (props.type.node as TemplateDeclarationNode)?.templateParameters;
typeVars = (
<>
<For each={templateParameters} hardline>
{(node) => {
const typeVar = (
<py.FunctionCallExpression
target={typingModule["."].TypeVar}
args={[<py.Atom jsValue={node.id.sv} />]}
/>
);
return <py.VariableDeclaration name={node.id.sv} initializer={typeVar} />;

// ("${node.id.sv}")`;
// return <py.Declaration name={String(node.id.sv)}></py.Declaration>;
}}
</For>
</>
);
for (const templateParamter of templateParameters) {
typeArgs.push(templateParamter.id.sv);
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is all aimed at determining if there are template parameters that are unfulfilled and, if so, adding them as type arguments to a Generic base.

</>
);
for (const templateParamter of templateParameters) {
typeArgs.push(templateParamter.id.sv);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't great, we're just making a list of strings. These should probably be references but I didn't have time to figure out how to make that work.

const output = (
<Output
program={context.program}
externals={[ef.abcModule, ef.dataclassesModule, ef.typingModule, py.enumModule]}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part was critical, as the stdlib references didn't work without it.

I'm not sure if it's expected that we'll always need to do this in emitters? Or if something should be happening with references or scopes or what have you so it happens automatically.

</For>
<For each={type.models}>
{(name, type) => {
return <ef.ClassDeclaration type={type} abstract={!type.isFinished} />;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbf I don't understand what isFinished actually means.

}

function isTemplateVar(type: Type): boolean {
return (type as TemplatedTypeBase).templateMapper !== undefined;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯_(ツ)_/¯

reportPythonDiagnostic($.program, { code: "python-unsupported-type", target: type });
break;
case "TemplateParameter":
return code`${String((type.node as TemplateParameterDeclarationNode).id.sv)}`;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can do a lot better than a string! Should be a reference.

Comment on lines +78 to +80
if (isTemplateVar(type)) {
return <TypeExpression type={type.templateMapper?.args[0] as Type} />;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The weird thing is that models used as template arguments are treated as models here.

Comment on lines +135 to +142
const typeNode = isOptional ? (
<py.TypeReference
refkey={typingModule["."].Optional}
typeArgs={[unpackedTypeNode]}
></py.TypeReference>
) : (
unpackedTypeNode
);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds support for wrapping types in Optional[] if the model property is optional.

Comment on lines +267 to 271
<Show when={!!typeVars}>
{typeVars}
<hbr />
<line />
</Show>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typeVars should probably go at the top of the module, but I didn't want to figure out how to do that.

Even then, I'm not sure there is a defined style for where TypeVars should go.

Comment on lines +195 to +198
if (
!props.type.isFinished &&
(props.type.node as TemplateDeclarationNode)?.templateParameters
) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauriciogardini this is what I was referring to here #45 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants