-
Notifications
You must be signed in to change notification settings - Fork 300
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
python: anonymous record creation generates camel case dict fields #3870
Comments
Something else to note: when the field starts with a capital, it is left unchanged: type data = {| FromId: int |}
// this creates a dict with camel case field "fromId"
let makeData() = {| FromId = 1 |}
let y (d: data) =
d.FromId from typing import Any
def make_data(__unit: None=None) -> dict[str, Any]:
return {
"FromId": 1
}
def y(d: dict[str, Any]) -> int:
return d["FromId"] |
A similar problem happens when using Record. type Test =
{
FirstName : string
lastName : string
}
let test =
{
FirstName = ""
lastName = ""
}
test.FirstName
test.lastName from __future__ import annotations
from dataclasses import dataclass
from fable_library_js.reflection import (TypeInfo, string_type, record_type)
from fable_library_js.types import Record
def _expr0() -> TypeInfo:
return record_type("Test.Test", [], Test, lambda: [("FirstName", string_type), ("last_name", string_type)])
@dataclass(eq = False, repr = False, slots = True)
class Test(Record):
FirstName: str
last_name: str
Test_reflection = _expr0
test: Test = Test("", "")
test.FirstName
test.last_name I suspect that the convention in Python is to use |
As far as I can understand, the record one seems to be working, in the sense that the class contains the same fields as the accessor used at the call-site: So it seems there's a convention in the python backend of converting to snake case automatically, but it's not implemented correctly for anonymous records. |
Yes, but it also seems like the I don't know if this should also be applied to properties that use However, if we do so there is a need to mangle the name of the property because |
Description
When using the python backend and making use of an anonymous record, the accessors use snake case, while the construction code has camel cased fields, resulting in a
KeyError
when called:Repro code
https://fable.io/repl/#?code=FAFwngDgpgBAJgQxAmBeGBvAPjAZgJwHsBbASTgC4YBLAOxBiwF9hgB6NmEAC2oGcYAY3xQkUASjjVBDAO7UeQhMSgAbJX1i5qauDABEBEuX3BVUBsQQBrKABEkCABQBKNJhxGye9AEZGLGYWMGAwTpTwjm7owDDwAHRe5EA&html=Q&css=Q
Related information
The text was updated successfully, but these errors were encountered: