Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@deprecated overloads for invalid uses of contextlib.ContextDecorator? #12881

Open
Zac-HD opened this issue Oct 23, 2024 · 3 comments
Open

@deprecated overloads for invalid uses of contextlib.ContextDecorator? #12881

Zac-HD opened this issue Oct 23, 2024 · 3 comments

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented Oct 23, 2024

python/cpython#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 returning Never 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.

@JelleZijlstra
Copy link
Member

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.

@AlexWaygood
Copy link
Member

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 #8566 for an example)

@Zac-HD Zac-HD changed the title Overloads with -> Never for invalid uses of contextlib.ContextDecorator? @deprecated overloads for invalid uses of contextlib.ContextDecorator? Oct 23, 2024
@Zac-HD
Copy link
Contributor Author

Zac-HD commented Oct 23, 2024

Makes sense! Hopefully we'll get a decision upstream, to at least document it, and can then use @deprecated in typeshed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants