[ty] Make infer_subscript_expression_types a method on Type#22731
[ty] Make infer_subscript_expression_types a method on Type#22731charliermarsh merged 1 commit intomainfrom
infer_subscript_expression_types a method on Type#22731Conversation
a15f0c4 to
098cc9d
Compare
|
|
Okay, looks like a no-op as expected (those look like the usual suspects in mypy-primer). |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-return-type |
1 | 4 | 4 |
invalid-assignment |
0 | 4 | 1 |
invalid-argument-type |
0 | 2 | 1 |
| Total | 1 | 10 | 6 |
Typing conformance resultsNo changes detected ✅ |
4009a13 to
1fc1615
Compare
|
(will review tomorrow morning -- thank you!) |
4e92b43 to
39886cf
Compare
933dfc8 to
4d6aa20
Compare
AlexWaygood
left a comment
There was a problem hiding this comment.
Thank you! Another one we've known we've needed to do for a long time now
There was a problem hiding this comment.
nit: add a short module docstring?
| #[derive(Debug)] | ||
| pub(crate) struct SubscriptError<'db> { | ||
| result_ty: Type<'db>, | ||
| errors: Vec<SubscriptErrorKind<'db>>, |
There was a problem hiding this comment.
IIUC, I think in the common case there's likely to be only 1 error, so maybe this should be a SmallVec<[SubscriptErrorKind<'db>; 1]>`?
There was a problem hiding this comment.
Using a Vec here has the advantage that the very common case (no error) is small. Using a SmallVec probably requires boxing the SubscriptError in the Result, so that it remains small.
There was a problem hiding this comment.
(no strong opinion, happy to defer to you)
| IndexOutOfBounds { | ||
| kind: &'static str, | ||
| tuple_ty: Type<'db>, | ||
| length: String, |
There was a problem hiding this comment.
Nit
| length: String, | |
| length: Box<str>, |
| pub(crate) enum SubscriptErrorKind<'db> { | ||
| /// An index is out of bounds for a literal tuple/string/bytes subscript. | ||
| IndexOutOfBounds { | ||
| kind: &'static str, |
There was a problem hiding this comment.
I guess it would be nice to use a small enum for this field (and similar ones on other variants) rather than &'static str -- it would be more readable and more strongly typed.
4d6aa20 to
2ee10b1
Compare
* main: (62 commits) [`refurb`] Do not add `abc.ABC` if already present (`FURB180`) (#22234) [ty] Add a new `assert-type-unspellable-subtype` diagnostic (#22815) [ty] Avoid duplicate syntax errors for `await` outside functions (#22826) [ty] Fix unary operator false-positive for constrained TypeVars (#22783) [ty] Fix binary operator false-positive for constrained TypeVars (#22782) [ty] Fix false-positive `unsupported-operator` for "symmetric" TypeVars (#22756) [`pydocstyle`] Clarify which quote styles are allowed (`D300`) (#22825) [ty] Use distributed versions of AND and OR on constraint sets (#22614) [ty] Add support for dict literals and dict() calls as default values for parameters with TypedDict types (#22161) Document `-` stdin convention in CLI help text (#22817) [ty] Make `infer_subscript_expression_types` a method on `Type` (#22731) [ty] Simplify `OverloadLiteral::spans` and `OverloadLiteral::parameter_span` (#22823) [ty] Require both `*args` and `**kwargs` when calling a `ParamSpec` callable (#22820) [ty] Handle tagged errors in conformance (#22746) Add `--color` cli option to force colored output (#22806) Identify notebooks by LSP didOpen instead of `.ipynb` file extension (#22810) [ty] Fix docstring rendering for literal blocks after doctests (#22676) [ty] Update salsa to fix out-of-order query validation (#22498) [ty] Inline cycle initial and recovery functions (#22814) [ty] Pass the generic context through the decorator (#22544) ...
Summary
A refactor in anticipation of #22654.