[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.
* main: (40 commits) [ty] resolve union-likes in emitting union attribute errors (#24263) [ty] Improve support for `Callable` type context (#23888) [ty] Propagate type context through `await` expressions (#24256) [`pyflakes`] Flag annotated variable redeclarations as `F811` in preview mode (#24244) [ty] Preserve `Divergent` when materializing recursive aliases (#24245) Fix W391 fixes for consecutive empty notebook cells (#24236) [flake8-bugbear] Clarify RUF071 fix safety for non-path string comparisons (#24149) [ty] Ban type qualifiers in PEP-695 type aliases (#24242) [ty] Include keyword-prefixed symbols in completions for attributes (#24232) [ty] Add tests for TypedDict method overloads on unions (#24230) [ty] report unused bindings as unnecessary hint diagnostics (#23305) Remove unused `non_root` variable (#24238) Extend F507 to flag %-format strings with zero placeholders (#24215) [`flake8-simplify`] Suppress `SIM105` for `except*` before Python 3.12 (#23869) Ignore pre-initialization references in SIM113 (#24235) Parenthesize expression in RUF050 fix (#24234) Publish playgrounds using the `release-playground` environment (#24223) [ty] Fix instance-attribute lookup in methods of protocol classes (#24213) [ty] Used shared expression cache during generic call inference (#24219) [ty] make `Type::BoundMethod` include instances of same-named methods bound to a subclass (#24039) ...
Improves literal promotion and generic call inference that involve
Callabletype context. Resolves astral-sh/ty#3016.