question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`TextField.value`'s type hint

See original GitHub issue

Description

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:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
FeodorFitsnercommented, Nov 22, 2022

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?

image

0reactions
iron3oxidecommented, Dec 17, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found