[ty] Improve support for Callable type context#23888
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 86.59%. The percentage of expected errors that received a diagnostic held steady at 80.96%. The number of fully passing files held steady at 68/132. |
|
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
trio
flake8
sphinx
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
0 | 40 | 0 |
invalid-argument-type |
0 | 1 | 0 |
invalid-assignment |
0 | 1 | 0 |
invalid-return-type |
0 | 1 | 0 |
unused-ignore-comment |
1 | 0 | 0 |
| Total | 1 | 43 | 0 |
Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.
Raw diff:
Expression (https://github.com/cognitedata/Expression)
- tests/test_compose.py:21:16 error[invalid-assignment] Object of type `(Never, /) -> Never` is not assignable to `(int, /) -> int`
attrs (https://github.com/python-attrs/attrs)
+ typing-examples/baseline.py:101:74 warning[unused-ignore-comment] Unused `ty: ignore` directive
- tests/test_validators.py:807:21 error[invalid-argument-type] Argument to function `and_` is incorrect: Expected `(Any, Attribute[int], int, /) -> Any`, found `(Any, Attribute[Literal[10]], Literal[10], /) -> Any`b229936 to
7c2c8ee
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
3c8c523 to
2b4e381
Compare
2b4e381 to
cd669df
Compare
| for (typevar, ty) in iter::zip( | ||
| specialization.generic_context(db).variables(db), | ||
| specialization.types(db), | ||
| ) { |
There was a problem hiding this comment.
I could've sworn we had a helper method for this, since it seems like a common thing to grab from a Specialization. But it seems we don't!
There was a problem hiding this comment.
I think I added this at some point in a PR that was never merged... I'll add it in a followup.
| /// This is the case for any type which may contain types in non-covariant position within it, | ||
| /// e.g., nominal instances of a generic class, or callables. | ||
| pub(crate) fn may_prefer_declared_type(self, db: &'db dyn Db) -> bool { | ||
| self.class_specialization(db).is_some() || self.expand_eagerly(db).is_callable_type() |
There was a problem hiding this comment.
Does this need to verify that the nominal class has any non-covariant typevars in its generic context? Given all of the uses of "may" it seems like it's okay for this to return true even if there aren't actually any non-covariant typevars. So this is just used as an optimization for known-no cases.
There was a problem hiding this comment.
Yup, this just an optimization that allows us to ignore the type context if it returns false.
Improves literal promotion and generic call inference that involve
Callabletype context. Resolves astral-sh/ty#3016.