Skip to content

[ty] Fix more generics-related TODOs#18062

Merged
AlexWaygood merged 1 commit intomainfrom
alex/generics-todos
May 14, 2025
Merged

[ty] Fix more generics-related TODOs#18062
AlexWaygood merged 1 commit intomainfrom
alex/generics-todos

Conversation

@AlexWaygood
Copy link
Member

Summary

Address various generics-related TODOs by converting .to_instance() calls into .to_specialized_instance() calls.

Test Plan

Existing mdtests updated.

@AlexWaygood AlexWaygood requested a review from carljm as a code owner May 13, 2025 02:34
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label May 13, 2025
Comment on lines +2240 to +2242
let Type::ClassLiteral(class_literal) = self.to_class_literal(db) else {
return Type::unknown();
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was necessary or some custom-typeshed tests started panicking because they couldn't find Exception and ExceptionGroup in the custom typeshed

Comment on lines +2550 to +2551
let class = if symbol_ty
.is_subtype_of(self.db(), KnownClass::Exception.to_instance(self.db()))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using is_subtype_of rather than is_assignable_to here because I think we should infer BaseExceptionGroup rather than ExceptionGroup if symbol_ty is Unknown or similar

@github-actions
Copy link
Contributor

mypy_primer results

Changes were detected when running on open source projects
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- error[invalid-return-type] src/hydra_zen/wrapper/_implementations.py:945:16: Return type does not match returned value: Expected `DataClass_`, found `@Todo(unsupported type[X] special form) | (((...) -> Any) & dict[Unknown, Unknown]) | (DataClass_ & dict[Unknown, Unknown]) | (list[Any] & dict[Unknown, Unknown]) | dict[Any, Any] | (((...) -> Any) & list[Unknown]) | (DataClass_ & list[Unknown]) | list[Any] | (dict[Any, Any] & list[Unknown])`
+ error[invalid-return-type] src/hydra_zen/wrapper/_implementations.py:945:16: Return type does not match returned value: Expected `DataClass_`, found `@Todo(unsupported type[X] special form) | (((...) -> Any) & dict[Unknown, Unknown]) | (DataClass_ & dict[Unknown, Unknown]) | (list[Any] & dict[Unknown, Unknown]) | dict[Any, Any] | (((...) -> Any) & list[Unknown]) | (DataClass_ & list[Unknown]) | list[Any]`
+ error[type-assertion-failure] tests/annotations/declarations.py:951:5: Actual type `FullBuilds[Unknown] | StdBuilds[Unknown]` is not the same as asserted type `FullBuilds[@Todo(Support for `typing.TypeAlias`)] | StdBuilds[@Todo(Support for `typing.TypeAlias`)]`
- Found 649 diagnostics
+ Found 650 diagnostics

@AlexWaygood AlexWaygood merged commit 0590b38 into main May 14, 2025
35 checks passed
@AlexWaygood AlexWaygood deleted the alex/generics-todos branch May 14, 2025 16:26
dcreager added a commit that referenced this pull request May 14, 2025
…rals

* origin/main:
  [ty] Add type-expression syntax link to invalid-type-expression (#18104)
  [`flake8-simplify`] add fix safety section (`SIM103`) (#18086)
  [ty] mypy_primer: fix static-frame setup (#18103)
  [`flake8-simplify`] Correct behavior for `str.split`/`rsplit` with `maxsplit=0` (`SIM905`) (#18075)
  [ty] Fix more generics-related TODOs (#18062)
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants