`TextField.value`'s type hint
See original GitHub issueDescription
TextField.value
can take both a str
and a number. But its type hint in textfield.py
is Optional[str] = None
(either str
or None
)
The type hint should be updated, if you think this behavior is normal.
Code example to reproduce the issue:
import flet as ft
def main(page: ft.Page):
tb1 = ft.TextField(value=2500)
tb2 = ft.TextField(value="2500")
page.add(tb1, tb2)
ft.app(target=main)
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How can I type-hint a function where the return type depends ...
python - How can I type-hint a function where the return type depends on the input type of an argument? - Stack Overflow....
Read more >Type hints cheat sheet - mypy 0.991 documentation
Type hints cheat sheet#. This document is a quick cheat sheet showing how to use type annotations for various common types in Python....
Read more >TextField | Apple Developer Documentation
Creates a text field that applies a format style to a bound optional value, with a label generated from a view builder. Available...
Read more ><input type="text"> - HTML: HyperText Markup Language | MDN
The placeholder attribute is a string that provides a brief hint to the user as to what kind of information is expected in...
Read more >Create and style a text field - Flutter documentation
TextField ( decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Enter a search term', ), ),. To retrieve the value when it changes, see the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It shows error which is correct. It’s supposed to accept strings only.
I could add beartype decorator to enforce strings at runtime. Would that work?
Why is value an Optional? I just tried out the counter example from the docs and pyright complained that the TextField value that is manipulated in the callback functions can be None.
It of course isn’t, because it gets set when the TextField is created, but is it not more intuitive to say that a TextField always has a value and that its default value is an empty string?
Sorry if this is obvious, I am not familiar with the code yet.
EDIT: I just read some of the code and noticed that an empty string is already returned as the default value using self._get_attr(). Shouldn’t the method be typed as returning a str then?