GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — warnings.deprecated leads to incorrectly set _is_protocol on subclasses · Issue #138010 · python/cpython

warnings.deprecated leads to incorrectly set _is_protocol on subclasses #138010

New issue
Copy link
New issue
Copy link
Closed
Closed
warnings.deprecated leads to incorrectly set _is_protocol on subclasses#138010
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Description

@hmwillson
hmwillson
opened on Aug 20, 2025
Issue body actions

Bug report

Bug description:

from warnings import deprecated
from typing import Protocol


class FooProtocol(Protocol):
    pass

class Base:
    pass

@deprecated("")
class DeprecatedBase:
    pass

class FooWithBase(Base, FooProtocol):
    pass

class FooWithDeprecatedBase(DeprecatedBase, FooProtocol):
    pass


assert FooWithBase._is_protocol is False
assert FooWithDeprecatedBase._is_protocol is True

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

  • gh-138010: Fix __init_subclass__ forwarding by warnings.deprecated #138210
  • [3.14] gh-138010: Fix __init_subclass__ forwarding by warnings.deprecated (GH-138210) #138561
  • [3.13] gh-138010: Fix __init_subclass__ forwarding by warnings.deprecated (GH-138210) #138564

Activity

  1. hmwillson
    added
    type-bugAn unexpected behavior, bug, or error
    on Aug 20, 2025
  2. brianschubert
    added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-typing
    and removed
    topic-typing
    on Aug 20, 2025
  3. brianschubert commented on Aug 21, 2025

    @brianschubert
    brianschubert
    on Aug 21, 2025
    Contributor
    More actions

    This seems to happen because the __init_subclass__ method that @deprecated adds directly calls the __init_subclass__ method of the class being decorated. The problem is that that doesn't consider other __init_subclass__ methods that may appear between the decorated class and its parents in the MRO of subclasses. In this case, DeprecatedBase.__init_subclass__ directly calls object.__init_subclass__, which means that Protocol.__init_subclass__ gets skipped when defining FooWithDeprecatedBase.

    Here's a reproducer that doesn't involve Protocol:

    from warnings import deprecated
    
    class Base:
        def __init_subclass__(cls, **kwargs):
            print("ding!")
    
    @deprecated("")
    class DeprecatedBase:
        pass
    
    class Child1(DeprecatedBase, Base):  # output: DeprecationWarning
        pass
    
    class Child2(Base, DeprecatedBase):  # output: "ding!"
        pass

    cc @JelleZijlstra

  4. JelleZijlstra commented on Aug 21, 2025

    @JelleZijlstra
    JelleZijlstra
    on Aug 21, 2025
    Member
    More actions

    I see, we need to distinguish between the case where __init_subclass__ is present directly on the decorated base (in which case we call it directly) and the case where it isn't (in which case we need to use super).

    Reacted by Brian Schubert
  5. XChaitanyaX commented on Aug 28, 2025

    @XChaitanyaX
    XChaitanyaX
    on Aug 28, 2025
    Contributor
    More actions

    Just want to know if the if "__init_subclass__" in arg.__dict__: really necessary as we are already checking if the __init_subclass__ is a bound method of the decorated base if isinstance(original_init_subclass, MethodType):

  6. JelleZijlstra
    added a commit that references this issue on Sep 5, 2025

    gh-138010: Fix `__init_subclass__` forwarding by `warnings.deprecated` (

    e2c038f
  7. miss-islington
    added a commit that references this issue on Sep 5, 2025

    pythongh-138010: Fix `__init_subclass__` forwarding by `warnings.depr…

    8923b3d
  8. brianschubert
    added a commit that references this issue on Sep 5, 2025

    [3.13] pythongh-138010: Fix `__init_subclass__` forwarding by `warnin…

    3df5a67
  9. JelleZijlstra
    added a commit that references this issue on Sep 5, 2025

    [3.13] gh-138010: Fix `__init_subclass__` forwarding by `warnings.dep…

    cf62144
  10. lkollar
    added a commit that references this issue on Sep 9, 2025

    pythongh-138010: Fix `__init_subclass__` forwarding by `warnings.depr…

    1fd478d
  11. JelleZijlstra
    added a commit that references this issue on Oct 8, 2025

    [3.14] gh-138010: Fix `__init_subclass__` forwarding by `warnings.dep…

    51dfc67
  12. frenzymadness commented on Oct 8, 2025

    @frenzymadness
    frenzymadness
    on Oct 8, 2025
    Contributor
    More actions

    The fix is implemented and merged. It seems this can be closed.

  13. StanFromIreland
    closed this as completedon Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.