Skip to content

Frozen dataclass __init__ fails for "object" property" #78394

Closed

Description

@Omenien
mannequin
BPO 34213
Nosy @ericvsmith, @miss-islington, @VadimPushtaev
PRs
  • bpo-34213: frozen dataclass with "object" attr bug #8452
  • [3.7] bpo-34213: Allow dataclasses to work with a field named 'object'. (GH-8452) #8745
  • [3.7] bpo-34213: Allow dataclasses to work with a field named 'object'. (GH-8452) #8746
  • Files
  • frozen_dataclass_init_typeerror.py: Minimal .py demonstrating the error
  • 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 = 'https://github.com/ericvsmith'
    closed_at = <Date 2018-09-10.22:43:33.896>
    created_at = <Date 2018-07-24.18:34:20.201>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'Frozen dataclass __init__ fails for "object" property"'
    updated_at = <Date 2018-09-10.22:43:33.895>
    user = 'https://bugs.python.org/Omenien'

    bugs.python.org fields:

    activity = <Date 2018-09-10.22:43:33.895>
    actor = 'eric.smith'
    assignee = 'eric.smith'
    closed = True
    closed_date = <Date 2018-09-10.22:43:33.896>
    closer = 'eric.smith'
    components = ['Library (Lib)']
    creation = <Date 2018-07-24.18:34:20.201>
    creator = 'Omenien'
    dependencies = []
    files = ['47710']
    hgrepos = []
    issue_num = 34213
    keywords = ['patch']
    message_count = 4.0
    messages = ['322321', '322332', '323441', '323459']
    nosy_count = 4.0
    nosy_names = ['eric.smith', 'miss-islington', 'Omenien', 'Vadim Pushtaev']
    pr_nums = ['8452', '8745', '8746']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34213'
    versions = ['Python 3.7', 'Python 3.8']

    Activity

    1. Omenien commented on Jul 24, 2018

      Omenienmannequin
      MannequinAuthor

      When __init__ is called for a class which 1) is annotated with @dataclasses.dataclass(frozen=True) and 2) has a attribute named object a TypeError is raised because object is overridden for the local scope and as a result __setattr__ is called on the passed in argument value instead of the standard object base type.

      I was able to reproduce this in a Docker container running https://github.com/docker-library/python/blob/7a794688c7246e7eff898f5288716a3e7dc08484/3.7/stretch/Dockerfile with the attached .py file.
      Python 3.7.0 (default, Jul 17 2018, 11:04:33)
      [GCC 6.3.0 20170516] on linux

    2. added
      3.7 (EOL)
      stdlib
      type-bug
      on Jul 24, 2018
    3. self-assigned this
      on Jul 24, 2018
    4. VadimPushtaev commented on Jul 24, 2018

      VadimPushtaevmannequin
      Mannequin

      Hello.

      This is my solution for this problem - #8452

      Sorry if I'm not supposed to do anything about the already assigned issue, feel free to ignore my PR.

    5. ericvsmith commented on Aug 12, 2018

      @ericvsmith
      Member

      New changeset 4d12e4d by Eric V. Smith (Vadim Pushtaev) in branch 'master':
      bpo-34213: Allow dataclasses to work with a field named 'object'. (GH-8452)
      4d12e4d

    6. miss-islington commented on Aug 13, 2018

      @miss-islington
      Contributor

      New changeset 32e58fc by Miss Islington (bot) in branch '3.7':
      bpo-34213: Allow dataclasses to work with a field named 'object'. (GH-8452)
      32e58fc

    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

    Labels

    3.7 (EOL)3.8 (EOL)stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions