-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[red-knot] Specialize str.startswith for string literals
#17351
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
|
|
The pyinstrument changes show that we now understand the So I think those diagnostics are true positives according to our model, where Two false positives further down in the file are now gone, because they use |
3e44581 to
f35c255
Compare
|
It might be confusing for users if we infer precise types for Overall I'm okay with this, but note that this goes beyond what the spec requires of us when it comes to understanding |
b89dbc8 to
0042529
Compare
It's going to be extremely rare that someone actually calls
Yes, but the spec is vague. And there is this issue which aims to improve the spec. It includes this comment:
And this comment:
And this:
|
0042529 to
1fd746c
Compare
str.startswith for string literals
* main: [red-knot] Specialize `str.startswith` for string literals (#17351) [syntax-errors] `yield`, `yield from`, and `await` outside functions (#17298) [red-knot] Refresh diagnostics when changing related files (#17350) Add `Checker::import_from_typing` (#17340) Don't add chaperone space after escaped quote in triple quote (#17216) [red-knot] Silence errors in unreachable type annotations / class bases (#17342)
## Summary Minor follow-up to #17351, thank you @AlexWaygood.
Summary
Infer precise Boolean literal types for
str.startswithcalls where the instance and the prefix are both string literals. This allows us to understandsys.platform.startswith(…)branches.Test Plan
New Markdown tests