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

Float in nested tuple[dict] gets converted to string #641

Open
elya5 opened this issue Jan 5, 2024 · 2 comments
Open

Float in nested tuple[dict] gets converted to string #641

elya5 opened this issue Jan 5, 2024 · 2 comments

Comments

@elya5
Copy link

elya5 commented Jan 5, 2024

I have the variable ranks = ({'name': 'abc', 'score': 3.4},). The score gets converted into a string by django-unicorn even though it is a float. Type hints like tuple[dict[str, str|float]] or even tuple[dict[str, float] do not have an effect.

(Background seems to be described here: #82)

A minimal example would look like this:

class SortTableView(UnicornView):
    ranks: tuple[dict[str,float|str]] = ()

    def mount(self):
        self.ranks = ({'name': 'abc', 'score': 3.4},)

    def button_click(self):
        self.ranks = tuple(sorted(self.rank, key=lambda row: row['score'])
        # wrong sort order here because the score is a string not a float
@adamghill
Copy link
Owner

Thanks for the bug report! I can try to handle nested types like this I think. 👍 Will let you know what I come up with.

@elya5
Copy link
Author

elya5 commented Jan 8, 2024

One idea I had is to prefix all floats when converting them to a string. It seems to work but I don't know if this is something you'd go along with.

See: elya5@beae4fd

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