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

set.__or__, __and__, etc create subclass types, but ignore __new__ #60083

Closed
JonObermark mannequin opened this issue Sep 7, 2012 · 4 comments
Closed

set.__or__, __and__, etc create subclass types, but ignore __new__ #60083

JonObermark mannequin opened this issue Sep 7, 2012 · 4 comments

Comments

@JonObermark
Copy link
Mannequin

JonObermark mannequin commented Sep 7, 2012

BPO 15879
Nosy @amauryfa, @benjaminp, @bitdancer
Superseder
  • bpo-1721812: A subclass of set doesn't always have init called.
  • 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 2012-09-07.16:44:39.508>
    created_at = <Date 2012-09-07.15:44:41.370>
    labels = []
    title = 'set.__or__, __and__, etc create subclass types, but ignore __new__'
    updated_at = <Date 2012-09-07.17:26:30.617>
    user = 'https://bugs.python.org/JonObermark'

    bugs.python.org fields:

    activity = <Date 2012-09-07.17:26:30.617>
    actor = 'Jon.Obermark'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-09-07.16:44:39.508>
    closer = 'amaury.forgeotdarc'
    components = []
    creation = <Date 2012-09-07.15:44:41.370>
    creator = 'Jon.Obermark'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 15879
    keywords = []
    message_count = 4.0
    messages = ['169986', '169989', '169991', '169997']
    nosy_count = 4.0
    nosy_names = ['amaury.forgeotdarc', 'benjamin.peterson', 'r.david.murray', 'Jon.Obermark']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = '1721812'
    type = None
    url = 'https://bugs.python.org/issue15879'
    versions = []

    @JonObermark
    Copy link
    Mannequin Author

    JonObermark mannequin commented Sep 7, 2012

    If they are not going to call the metaclass or the class new, then they should return set objects instead of subclass objects, so that it is clear what is going on.

    As it is, the results of set operations receive some subclass information but not all. So they are not really obeying the notion of a subclass: the results are neither set objects, nor properly-constructed objects of the set subclass.

    e.g.
    class Fooset(Set):
    def __new__(cls, s = []):
    print 'New called'
    self = super(Fooset, cls).__new__(cls)
    self.update(s)
    if isinstance(s, Fooset):
    self.foo = s.foo
    else:
    self.foo = 'default'
    return self

    x = Fooset([1,2,5])
    y = x|x

    The object y reports being of the type Fooset, but has not been constructed by the type that makes Fooset objects.

    @bitdancer
    Copy link
    Member

    It is probably true that this is a bug, but subclasses of mutable classes do not normally override __new__. (I'm curious what your use case is for doing so.)

    @amauryfa
    Copy link
    Member

    amauryfa commented Sep 7, 2012

    This was already fixed (in the 3.x releases) by bpo-1721812.

    @amauryfa amauryfa closed this as completed Sep 7, 2012
    @JonObermark
    Copy link
    Mannequin Author

    JonObermark mannequin commented Sep 7, 2012

    The closing author is correct, the use case is adequately covered by __init__, and that has been fixed in 3. It makes sense this will not be backported.

    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants