Open Zac-HD opened 2 weeks ago
Returning Never isn't the right solution for overloads that we want users to avoid; it makes type checkers treat code as unreachable, which can have rather confusing effects. However, we may be able to use @deprecated
, especially if CPython also deprecates these behaviors.
Yes, when we've tried these kinds of -> Never
overloads in the past it's almost always caused more trouble than it's worth, unfortunately (see https://github.com/python/typeshed/issues/8566 for an example)
Makes sense! Hopefully we'll get a decision upstream, to at least document it, and can then use @deprecated
in typeshed.
https://github.com/python/cpython/issues/125862 describes some problems that can occur when applying a
ContextDecorator
to an async function or a generator function. Is it reasonable to add overloads returningNever
for such cases, so that typecheckers can warn people?The code in question runs, but it doesn't do anything useful let alone have the expected effect, so I'd love to warn about it sooner than CPython will release a fix.