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 — problem with ABCMeta.__prepare__ when called after types.new_class · Issue #77371 · python/cpython

problem with ABCMeta.__prepare__ when called after types.new_class #77371

New issue
Copy link
New issue
Copy link
Open
#161890
Open
problem with ABCMeta.__prepare__ when called after types.new_class#77371
#161890
Copy link
Labels
3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc direasypendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Description

Ricyteach
mannequin
opened on Mar 30, 2018
Issue body actions
BPO 33190
Nosy @ilevkivskyi, @Ricyteach
PRs
  • bpo-33190: elucidated types.new_class docstring #6317
  • Files
  • abcmeta_prepare.py: demo of issue
  • 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 = None
    created_at = <Date 2018-03-30.20:43:02.783>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'problem with ABCMeta.__prepare__ when called after types.new_class'
    updated_at = <Date 2018-03-31.02:58:22.949>
    user = 'https://github.com/Ricyteach'

    bugs.python.org fields:

    activity = <Date 2018-03-31.02:58:22.949>
    actor = 'Ricyteach'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2018-03-30.20:43:02.783>
    creator = 'Ricyteach'
    dependencies = []
    files = ['47509']
    hgrepos = []
    issue_num = 33190
    keywords = ['patch']
    message_count = 5.0
    messages = ['314714', '314716', '314717', '314718', '314731']
    nosy_count = 2.0
    nosy_names = ['levkivskyi', 'Ricyteach']
    pr_nums = ['6317']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33190'
    versions = ['Python 3.7', 'Python 3.8']

    Linked PRs

    • gh-77371: Clarify that types.new_class() kwds are class keywords #161890

    Activity

    1. Ricyteach commented on Mar 30, 2018

      @Ricyteach
      Ricyteachmannequin
      on Mar 30, 2018
      MannequinAuthor
      More actions

      I am pretty sure this is a bug. If not I apologize.

      Say I want to dynamically create a new C class, with base class MyABC (and dynamically assigned abstract method m). This works fine if I use type, but if I use new_class, the keyword argument to the m method implementation gets lost somewhere in the call to ABCMeta.__prepare___.

      I've attached a file to demo. Thanks.

    2. Ricyteach
      added
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Mar 30, 2018
    3. ilevkivskyi commented on Mar 30, 2018

      @ilevkivskyi
      ilevkivskyi
      on Mar 30, 2018
      Member
      More actions

      This is not a bug, but a misunderstanding:

      • First, ABCMeta doesn't have __prepare__, it is just type.__prepare__
      • Second, the third argument to types.new_class is called kwds for a reason. It is not a namespace like in type but the set of keywords in the equivalent class definition. For example:

      types.new_class('Test', (A, B), {'metaclass': Meta, 'foo': 42})

      id equivalent to

      class Test(A, B, metaclass=Meta, foo=42):
          pass

      If you want to populate the namespace, then you should use the fourth argument exec_body which should be a callable that takes newly created dictionary and populates it with items. For your case it should be:

      C = new_class("C", (MyABC,), {}, exec_body=lambda ns: ns.update(namespace))

      If you want to clarify the corresponding docstring, then please open a PR. Otherwise you can close the issue.

    4. Ricyteach commented on Mar 30, 2018

      @Ricyteach
      Ricyteachmannequin
      on Mar 30, 2018
      MannequinAuthor
      More actions

      Excellent; thank you very much for the explanation.

      I have never done a PR on a project this size but I'll give it a try.

    5. ilevkivskyi commented on Mar 30, 2018

      @ilevkivskyi
      ilevkivskyi
      on Mar 30, 2018
      Member
      More actions

      https://devguide.python.org/ will help you.

    6. Ricyteach commented on Mar 31, 2018

      @Ricyteach
      Ricyteachmannequin
      on Mar 31, 2018
      MannequinAuthor
      More actions

      Thank you; I gave it a go. Hopefully didn't cause too much additional work for someone.

    7. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    8. furkanonder commented on May 13, 2023

      @furkanonder
      furkanonder
      on May 13, 2023
      Contributor
      More actions

      @ilevkivskyi I think we can close the problem because the issue is not a bug, it is a misunderstanding.

    9. ilevkivskyi commented on May 13, 2023

      @ilevkivskyi
      ilevkivskyi
      on May 13, 2023
      Member
      More actions

      There is still an option to improve the docstring for new_class() but if no-one wants to do this, then we can close.

    10. hugovk
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      easy
      pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
      and removed
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Oct 26, 2026
    11. github-project-automation
      added this to docs issueson Oct 26, 2026
    12. github-project-automation
      moved this to Todo in docs issueson Oct 26, 2026
    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.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc direasypendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

      Projects

      • docs issues
        Status
        Todo
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — 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.