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

frozenset, when subclassed will yield warning upon call to super(...).__init__(iterable) #53868

Closed
carstenkleinaxn-softwarede mannequin opened this issue Aug 22, 2010 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@carstenkleinaxn-softwarede
Copy link
Mannequin

BPO 9659
Nosy @rhettinger, @benjaminp, @merwok

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 2010-08-22.15:34:30.530>
created_at = <Date 2010-08-22.14:42:19.952>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'frozenset, when subclassed will yield warning upon call to super(...).__init__(iterable)'
updated_at = <Date 2010-08-25.13:34:29.440>
user = 'https://bugs.python.org/carstenkleinaxn-softwarede'

bugs.python.org fields:

activity = <Date 2010-08-25.13:34:29.440>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2010-08-22.15:34:30.530>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2010-08-22.14:42:19.952>
creator = 'carsten.klein@axn-software.de'
dependencies = []
files = []
hgrepos = []
issue_num = 9659
keywords = []
message_count = 7.0
messages = ['114676', '114677', '114678', '114680', '114683', '114889', '114904']
nosy_count = 5.0
nosy_names = ['rhettinger', 'benjamin.peterson', 'stutzbach', 'eric.araujo', 'carsten.klein@axn-software.de']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue9659'
versions = ['Python 2.6']

@carstenkleinaxn-softwarede
Copy link
Mannequin Author

Example

class a(frozenset):
    def __init__(self, iterable):
        super(a, self).__init__(iterable)


i = a([1,2,3])
> __main__:3: DeprecationWarning: object.__init__() takes no parameters
> a([1, 2, 3])

This might be due to the fact that the frozenset type structure does not initialize the tp_init field in setobject.c, thus inheriting the original __init__ from object.

Subclassing set will not issue that warning as it actually defines the tp_init field to (initroc)set_init.

This holds true also for the Python 2.7 release and maybe also later releases.

Expected behaviour: do not output that warning message and provide an initproc for the tp_field.

@carstenkleinaxn-softwarede carstenkleinaxn-softwarede mannequin added the type-bug An unexpected behavior, bug, or error label Aug 22, 2010
@merwok
Copy link
Member

merwok commented Aug 22, 2010

Thank you for the report. 2.6 is in security mode, it does not get bug fixes anymore. Can you reproduce the bug with 2.7, 3.1 and 3.2?

@merwok merwok added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Aug 22, 2010
@stutzbach
Copy link
Mannequin

stutzbach mannequin commented Aug 22, 2010

I can reproduce it in Python 3.1 and 3.2 I don't have a build of Python 2.7 handy at the moment to test it there.

In Python 3.2 and 2.7, DeprecationWarnings are silenced by default. I had to start Python 3.2 with "-W always::DeprecationWarning" to see the problem.

@benjaminp
Copy link
Contributor

This is correct. immutable types should use __new__, not __init__.

@rhettinger
Copy link
Contributor

Thanks Benjamin. I concur with your conclusion.

@carstenkleinaxn-softwarede
Copy link
Mannequin Author

Thanks for the information. Where is this documented? I cannot find it in the official Python docs... TIA.

@benjaminp
Copy link
Contributor

2010/8/25 Carsten Klein <report@bugs.python.org>:

Carsten Klein <carsten.klein@axn-software.de> added the comment:

Thanks for the information. Where is this documented? I cannot find it in the official Python docs... TIA.

http://docs.python.org/dev/reference/datamodel.html#object.\_\_new__

@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
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants