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

[Python] Equality of record with optional filed doesn't works if the field are set to None #3605

Closed
MangelMaxime opened this issue Nov 21, 2023 · 1 comment · Fixed by #3606
Labels
python Python

Comments

@MangelMaxime
Copy link
Member

MangelMaxime commented Nov 21, 2023

Description

open Fable.Core.Testing

type SmallRecord2 =
    { optionalField : string option }

let a = Ok({ optionalField = None })
let b = Ok({ optionalField = None })

// printfn "%A" (a = b) This version of the equality crash too
printfn "%A" (Assert.AreEqual(a, b, ""))

Error:

Watching ../..
Traceback (most recent call last):
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/./fableBuild/./Main.py", line 118, in <module>
    main(sys.argv[1:])
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/./fableBuild/./Main.py", line 112, in main
    arg: None = assert_equal(a, b, "")
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/fableBuild/fable_modules/fable_library/util.py", line 352, in assert_equal
    if not equals(actual, expected):
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/fableBuild/fable_modules/fable_library/util.py", line 226, in equals
    return a == b
           ^^^^^^
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/fableBuild/fable_modules/fable_library/types.py", line 99, in __eq__
    return self.fields == other.fields
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/fableBuild/fable_modules/fable_library/types.py", line 185, in __eq__
    return self.Equals(other)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/fableBuild/fable_modules/fable_library/types.py", line 170, in Equals
    return record_equals(self, other)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/fableBuild/fable_modules/fable_library/types.py", line 146, in record_equals
    return record_compare_to(self, other) == 0
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mmangel/Workspaces/Github/thoth-org/Thoth.Json/tests/Thoth.Json.Tests.Python/fableBuild/fable_modules/fable_library/types.py", line 123, in record_compare_to
    if self.__dict__[name] < other.__dict__.get(name):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'

Expected and actual results

Equality test should not crash

Related information

  • Fable version: 3.5.0
  • Operating system: OSX
@MangelMaxime MangelMaxime added the python Python label Nov 21, 2023
@MangelMaxime
Copy link
Member Author

A similar problem occurs when running the following:

let a = Ok({ optionalField = None })
    let b = Ok({ optionalField = Some "" })

    // printfn "%A" (a = b)
    printfn "%A" (Assert.AreEqual(a, b, ""))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant