Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(rosetta) type inference is not sufficiently narrowed causing incorrect Python translations #3029

Closed
nija-at opened this issue Oct 5, 2021 · 4 comments · Fixed by #3043
Closed
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort p1

Comments

@nija-at
Copy link
Contributor

nija-at commented Oct 5, 2021

🐛 Bug Report

Given the method signature -

mymethod(props: any);

and the snippet that uses this method as -

mymethod({
   Foo: 'Bar',
   Baz: 5
});

This gets incorrectly translated into Python as -

mymethod(
  Foo="Bar",
  Baz=5
)

Real life example -

================= 95964378aeaa3097f169ababbfa7299d423f35d782742e0b6ef0ec429f7e6e7e =================
template.hasResourceProperties('Foo::Bar', {
  Foo: 'Bar',
  Baz: 5,
  Qux: [ 'Waldo', 'Fred' ],
});
----------- python -----------
template.has_resource_properties("Foo::Bar",
    Foo="Bar",
    Baz=5,
    Qux=["Waldo", "Fred"]
)
@nija-at nija-at added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 5, 2021
@nija-at nija-at changed the title (rosetta) type inference is not sufficiently narrow during Python translations (rosetta) type inference is not sufficiently narrowed causing incorrect Python translations Oct 5, 2021
@nija-at
Copy link
Contributor Author

nija-at commented Oct 5, 2021

The workaround is to declare the second parameter as a separate variable with an explicit type before passing it into the method.

@RomainMuller
Copy link
Contributor

Yeah so for some reason that last parameter seems interpreted as a property bag, whereas the type signature of the method suggests it cannot be that (it should only happen if the last parameter is known to be a struct).

@RomainMuller RomainMuller added effort/medium Medium work item – a couple days of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 6, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 7, 2021

Oh this is fun. The type of this argument is any, but from the type checker PoV it doesn't (can't?) distinguish between an any that's declared as an any, or an any it just assumes because it can't find a declaration for a function, for example.

@rix0rrr rix0rrr closed this as completed in ae4f992 Oct 7, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mergify bot pushed a commit that referenced this issue Oct 8, 2021
Try and resolve the containing function call. If it resolves, we
know the `any` the typechecker is giving us is actually intended to
be an `any`.

If the containing call does not resolve, we'll treat it as an unknown
type of an uncompiling sample, and assume there's a struct there.

Fixes #3029.



---

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
mergify bot pushed a commit to aws/aws-cdk that referenced this issue Oct 11, 2021
)

Rosetta automatic snippet translation is doing a poor
job of snippet translation. This is mainly because the
snippets are not compilable.

Update snippets to make them compilable and translate
correctly.

Additionally, make the rosetta compilation strict and run
during the build step.

There are still a few more translation errors, but these are
arising from bugs in rosetta.
aws/jsii#3026
aws/jsii#3029

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…#16801)

Rosetta automatic snippet translation is doing a poor
job of snippet translation. This is mainly because the
snippets are not compilable.

Update snippets to make them compilable and translate
correctly.

Additionally, make the rosetta compilation strict and run
during the build step.

There are still a few more translation errors, but these are
arising from bugs in rosetta.
aws/jsii#3026
aws/jsii#3029

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants