← 输入框|github.com|刷新
Skip to content

Subclassing Protocol get different __init__ #88969

Closed

Description

@uriyyo
BPO 44806
Nosy @ambv, @serhiy-storchaka, @miss-islington, @uriyyo, @Fidget-Spinner
PRs
  • bpo-44806: Fix issue with typing.Protocol __init__ method generation #27541
  • bpo-44806: Fix __init__ in subclasses of protocols #27545
  • [3.10] bpo-44806: Fix __init__ in subclasses of protocols (GH-27545) #27558
  • [3.9] bpo-44806: Fix __init__ in subclasses of protocols (GH-27545) #27559
  • bpo-44807: Forbid to define __init__ method in Protocol classes #27543
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-02.17:37:34.149>
    created_at = <Date 2021-08-02.09:20:47.665>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'Subclassing Protocol get different __init__'
    updated_at = <Date 2021-08-02.17:37:34.149>
    user = 'https://github.com/uriyyo'

    bugs.python.org fields:

    activity = <Date 2021-08-02.17:37:34.149>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-08-02.17:37:34.149>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2021-08-02.09:20:47.665>
    creator = 'uriyyo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44806
    keywords = ['patch']
    message_count = 5.0
    messages = ['398736', '398756', '398780', '398782', '398785']
    nosy_count = 5.0
    nosy_names = ['lukasz.langa', 'serhiy.storchaka', 'miss-islington', 'uriyyo', 'kj']
    pr_nums = ['27541', '27545', '27558', '27559', '27543']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue44806'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. uriyyo commented on Aug 2, 2021

      @uriyyo
      MemberAuthor

      When we subclassing Protocol, we get a __init__ differing from default one but the protocol in question didn't define any __init__.

      More information can be found here - python/typing#644

    2. added
      3.11only security fixes
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Aug 2, 2021
    3. serhiy-storchaka commented on Aug 2, 2021

      @serhiy-storchaka
      Member

      There is other related case:

      >>> from typing import *
      >>> class P(Protocol): pass
      ... 
      >>> class B:
      ...     def __init__(self):
      ...         self.test = 'OK'
      ... 
      >>> class D(P, B):
      ...     pass
      ... 
      >>> D().test
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      AttributeError: 'D' object has no attribute 'test'
    4. ambv commented on Aug 2, 2021

      @ambv
      Contributor

      New changeset 043cd60 by Serhiy Storchaka in branch 'main':
      bpo-44806: Fix __init__ in subclasses of protocols (GH-27545)
      043cd60

    5. ambv commented on Aug 2, 2021

      @ambv
      Contributor

      New changeset 0f6a773 by Miss Islington (bot) in branch '3.9':
      bpo-44806: Fix __init__ in subclasses of protocols (GH-27545) (GH-27559)
      0f6a773

    6. miss-islington commented on Aug 2, 2021

      @miss-islington
      Contributor

      New changeset 2cc19a5 by Miss Islington (bot) in branch '3.10':
      bpo-44806: Fix __init__ in subclasses of protocols (GH-27545)
      2cc19a5

    7. transferred this issue fromon Apr 10, 2022
    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

      3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifestdlibStandard 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