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

Subclassing Protocol get different __init__ #88969

Closed
uriyyo opened this issue Aug 2, 2021 · 5 comments
Closed

Subclassing Protocol get different __init__ #88969

uriyyo opened this issue Aug 2, 2021 · 5 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@uriyyo
Copy link
Member

uriyyo commented Aug 2, 2021

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']

    @uriyyo
    Copy link
    Member Author

    uriyyo commented Aug 2, 2021

    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

    @uriyyo uriyyo added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 2, 2021
    @serhiy-storchaka serhiy-storchaka added 3.9 only security fixes 3.10 only security fixes labels Aug 2, 2021
    @serhiy-storchaka
    Copy link
    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'

    @ambv
    Copy link
    Contributor

    ambv commented Aug 2, 2021

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

    @ambv
    Copy link
    Contributor

    ambv commented Aug 2, 2021

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

    @miss-islington
    Copy link
    Contributor

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

    @ambv ambv closed this as completed Aug 2, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants