-
-
Notifications
You must be signed in to change notification settings - Fork 2k
add types to tkinter.Text methods #4460
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
Conversation
|
I think it's now correct:
|
|
One more thing: text index strings are like However, tkinter accepts floats as well, and some people use float text indexes to "reduce typing", most commonly |
|
@Hawk777 What do you think about float text indexes? |
|
I haven’t really used the I’m not sure how relevant it is that comparisons don’t work right. Most math also wouldn’t work right, but I don’t think it’s the place of a type system to try and enforce rules about how the values are calculated. While some languages do use their type systems to indicate detailed constraints on values (e.g. Rust’s Put another way, even if the type system accepts only strings, then you can pass so many different types of invalid values anyway. Given that, would prohibiting |
Right, you can put different kinds of things into a string when specifying a text index. It's handy and I often do it, but it's not really related to the float thing.
With these stubs, I make sure to accept two kinds of values:
I'm struggling with figuring out whether it's more practical to allow floats and ints, possibly allowing surprising bugs to happen, or disallow floats altogether, forcing lazy typers to add some quotes into code that used to pass mypy checks. |
|
My point is that, if you accept strings, then the type system will accept things like I suppose the question is: what is the philosophy of typeshed? Should the type annotations reflect all the ways in which the API can be legitimately used (in which case we must accept floats), or should they reflect only what we consider to be “good” ways (in which case we should probably reject floats)? |
|
floats allowed now because avoiding errors is generally the way to go in typeshed |
srittau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No red flags.
(If you have time to review only one PR, then please review #4459 instead, it's more important IMO)
I don't know how to get rid of overlappingdumpoverloads. I want it to returnNoneif a non-Nonecommandis specified, andList[Tuple[str, str, str]]ifcommandis not specified or it's specified asNone. The problem is thatindex2is beforecommand, and that has a default value too.tag_prevrangeandtag_nextrangereturn a union. It's not great, but I think it's similar to returningOptional; if you forget to handle the two different cases, then you likely have a bug. And if you're sure that one of the two cases never happens, then you shouldassertthat.