Skip to content

[red-knot] Decide if Type::to_instance should return a Result #16302

@MichaReiser

Description

@MichaReiser

Description

There's a TODO in Types::to_instance:

// TODO: calling `.to_instance()` on any of these should result in a diagnostic,
// since they already indicate that the object is an instance of some kind:

We could consider returning a Result from to_instance so that it's the caller's responsibility, that the method is never called on a type that already is an instance or handle the error gracefully.

I remember that I replaced the fallback to Type::Unknown with a panic and it didn't result in any failing tests. But @AlexWaygood mentioned that it is possible to trigger the panic with a custom/broken typeshed. I'm not sure if I care about that use case too much (existing with a useful panic message might be good enough?) to reduce ergonomics.

I'm leaning toward making it a Result unless it is too painful and can only ever happen with a rather fundamentally broken typeshed.

Metadata

Metadata

Assignees

Labels

tyMulti-file analysis & type inference

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions