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 between Records with None fields fails #3611

Closed
HLWeil opened this issue Nov 24, 2023 · 2 comments
Closed

[Python] Equality between Records with None fields fails #3611

HLWeil opened this issue Nov 24, 2023 · 2 comments

Comments

@HLWeil
Copy link

HLWeil commented Nov 24, 2023

Description

Equation between two Records fails in python, when the Record Type contains an Option field and the value bound to this field is None. The error message is the following:

TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'

Repro code

[Please provide the F# code to reproduce the problem or a link to the REPL.
Ideally, it should be possible to easily turn this code into a unit test.](https://fable.io/repl/#?code=MQJwBARAdgrg5gUwC4C4wDECGAjANggOgGEB7EBAGjABYCAmAgBggFgAodkgBwSgx3zEyCTjz4BlAJ4BnJAgC2Q3PgDGSAJYko0ggHFeCEOpXtRvMFNkKCAFQQAPJAQBKCODFyYQAUXtdy0tKa2qZsSJI8YK4qYAC87GCJYADeCUnpAIJgaLJGUHBg3BpaaYkAvqH4SGCYcSlZsWAAcloIFWxVYNh1yQ3Nre3s-upQSABmfBAApNgQYAAUtY3YAJTsQA&html=Q&css=Q)

Reason

The failing function is the following:

def record_compare_to(self: Record, other: Record) -> int:
    if self is other:
        return 0

    elif hasattr(self, "__dict__") and self.__dict__:
        for name in self.__dict__.keys():
            if self.__dict__[name] < other.__dict__.get(name):
                return -1
            elif self.__dict__[name] > other.__dict__.get(name):
                return 1

    elif hasattr(self, "__slots__") and self.__slots__:
        for name in self.__slots__:
            if getattr(self, name) < getattr(other, name):
                return -1
            elif getattr(self, name) > getattr(other, name):
                return 1

    return 0

@Freymaurer

@MangelMaxime
Copy link
Member

This is fixed by #3606

It will be included in the next Fable release.

@HLWeil
Copy link
Author

HLWeil commented Nov 24, 2023

Great to hear 👍

@HLWeil HLWeil closed this as completed Nov 24, 2023
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

No branches or pull requests

2 participants