◐ Shell
clean mode source ↗

gh-91896: Improve visibility of `ByteString` deprecation warnings by AlexWaygood · Pull Request #104294 · python/cpython

Conversation

@AlexWaygood

#102096 added deprecation warnings for collections.abc.ByteString, but these warnings are currently only emitted on subclassing ByteString or calling isinstance() against it. Importing ByteString or accessing it via import collections.abc; collections.abc.ByteString does not currently trigger any warnings, meaning somebody who's just using the class for type annotations might not get any warning that the class will be removed in 3.14. Moreover, the isinstance() deprecation warnings are only emitted on isinstance() checks against collections.abc.ByteString, not on isinstance() checks against typing.ByteString. The docs update that we just made in 1f56795 says that typing.ByteString will also be removed in Python 3.14, so we should emit the same deprecation warnings for typing.ByteString.

This PR adds deprecation warnings for:

  • from collections.abc import ByteString
  • import collections.abc; collections.abc.ByteString
  • from typing import ByteString
  • import typing; typing.ByteString
  • isinstance(b"", typing.ByteString)

@AlexWaygood

(Skipping news as I think the news entry in #102096 should be enough)

Eclips4

@rhettinger

I'm not opposed to this but think it isn't necessary. We aren't required to emit warnings. The deprecation notices in whatsnew and the docs will suffice. This doubly true for ByteString which like has low use.

@AlexWaygood

I'm not opposed to this but think it isn't necessary. We aren't required to emit warnings. The deprecation notices in whatsnew and the docs will suffice. This doubly true for ByteString which like has low use.

I don't feel strongly about this, and perhaps it isn't strictly necessary, but I would prefer maximum visibility, personally. I think it will help users if they get a clear runtime warning when they use the symbol in a type annotation, before the symbol is removed.

hauntsaninja

Choose a reason for hiding this comment

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

Thanks! While collections.abc.ByteString is extremely low use, there is some use of typing.ByteString as an annotation out there, for which this could help.

Either way we should lean on type checkers for this deprecation as well, since we won't get warnings in stub files or some from __future__ import annotations scenarios.

hauntsaninja

This was referenced

May 12, 2023

carljm added a commit to carljm/cpython that referenced this pull request

May 12, 2023

Reviewers

@Eclips4 Eclips4 Eclips4 left review comments

@hauntsaninja hauntsaninja hauntsaninja approved these changes

@gvanrossum gvanrossum Awaiting requested review from gvanrossum

@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner

@JelleZijlstra JelleZijlstra Awaiting requested review from JelleZijlstra JelleZijlstra is a code owner

@rhettinger rhettinger Awaiting requested review from rhettinger rhettinger is a code owner

Labels