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

language reference should specify restrictions on class namespace #61624

Closed
ericsnowcurrently opened this issue Mar 14, 2013 · 13 comments
Closed
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@ericsnowcurrently
Copy link
Member

BPO 17422
Nosy @ncoghlan, @ned-deily, @durban, @ericsnowcurrently, @miss-islington, @cdonovick, @ananthan-123
PRs
  • bpo-17422:language reference should specify restrictions on class namespace #18559
  • [3.8] bpo-17422: Language reference should specify restrictions on class namespace (GH-18559) #18610
  • [3.7] bpo-17422: Language reference should specify restrictions on class namespace (GH-18559) #18611
  • bpo-17422: slightly more precise language #18682
  • [3.8] bpo-17422: slightly more precise language (GH-18682) #18812
  • [3.7] bpo-17422: slightly more precise language (GH-18682) #18813
  • Files
  • issue17422.stoneleaf.01.patch
  • 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 2020-03-06.18:38:42.459>
    created_at = <Date 2013-03-14.20:33:35.170>
    labels = ['3.8', 'type-feature', '3.7', '3.9', 'docs']
    title = 'language reference should specify restrictions on class namespace'
    updated_at = <Date 2020-03-10.07:48:52.510>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2020-03-10.07:48:52.510>
    actor = 'ned.deily'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2020-03-06.18:38:42.459>
    closer = 'eric.snow'
    components = ['Documentation']
    creation = <Date 2013-03-14.20:33:35.170>
    creator = 'eric.snow'
    dependencies = []
    files = ['37712']
    hgrepos = []
    issue_num = 17422
    keywords = ['patch']
    message_count = 13.0
    messages = ['184188', '362272', '362470', '362479', '362480', '362853', '362854', '362856', '363530', '363531', '363532', '363534', '363807']
    nosy_count = 8.0
    nosy_names = ['ncoghlan', 'ned.deily', 'daniel.urban', 'docs@python', 'eric.snow', 'miss-islington', 'donovick', 'Ananthakrishnan']
    pr_nums = ['18559', '18610', '18611', '18682', '18812', '18813']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue17422'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @ericsnowcurrently
    Copy link
    Member Author

    (related to PEP-422 and issue bpo-17044)

    The execution namespace from a class definition is passed as the third argument to the metaclass (see builtin___build_class__() in Python/bltinmodule.c). When applicable, which is almost always, the subsequent call to type.__new__() copies that namespace into a new dict which is in turn exposed via the class's __dict__.

    This matters in the case where a metaclass with __prepare__() gets used (or the PEP-422 equivalent). The language reference[1] should note that the object returned by __prepare__() is copied into a new dict when the class is finally created via the metaclass.

    [1] http://docs.python.org/3.4/reference/datamodel.html#customizing-class-creation

    @ericsnowcurrently ericsnowcurrently added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Mar 14, 2013
    @ananthan-123
    Copy link
    Mannequin

    ananthan-123 mannequin commented Feb 19, 2020

    I just addded a PR for this issue.

    @gvanrossum
    Copy link
    Member

    New changeset fbe2e0b by ananthan-123 in branch 'master':
    bpo-17422: Language reference should specify restrictions on class namespace (bpo-18559)
    fbe2e0b

    @miss-islington
    Copy link
    Contributor

    New changeset 91ba446 by Miss Islington (bot) in branch '3.8':
    bpo-17422: Language reference should specify restrictions on class namespace (GH-18559)
    91ba446

    @miss-islington
    Copy link
    Contributor

    New changeset 36a120d by Miss Islington (bot) in branch '3.7':
    bpo-17422: Language reference should specify restrictions on class namespace (GH-18559)
    36a120d

    @ericsnowcurrently
    Copy link
    Member Author

    Thanks for working on this. Sorry I didn't get a chance to see your PR sooner. There was one small thing that needs to be changed back, as I implied in my comment on the PR [1]. Please undo the change in the text from "ordered mapping" to "dict".

    The original "is initialised as an empty ordered mapping" text line should be restored. "dict" is currently still not correct (the language spec does not dictate that dict be ordered). However, PEP-520 specifies that it must be ordered.

    Thanks!

    [1] #18559 (review)

    @ericsnowcurrently ericsnowcurrently added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Feb 28, 2020
    @gvanrossum
    Copy link
    Member

    As I mentioned in my response on the PR, dict *is* required to be ordered since 3.7. So I think it is okay as is.

    @cdonovick
    Copy link
    Mannequin

    cdonovick mannequin commented Feb 28, 2020

    While It is perfectly fine behavior for CPython to use a dict, as dict is an ordered mapping. I think Eric is right that the data model should not specify that a dict is necessarily used in the absence of __prepare__.

    @miss-islington
    Copy link
    Contributor

    New changeset e59334e by Caleb Donovick in branch 'master':
    bpo-17422: slightly more precise language (GH-18682)
    e59334e

    @miss-islington
    Copy link
    Contributor

    New changeset f1b7964 by Miss Islington (bot) in branch '3.7':
    bpo-17422: slightly more precise language (GH-18682)
    f1b7964

    @miss-islington
    Copy link
    Contributor

    New changeset 6df0c47 by Miss Islington (bot) in branch '3.8':
    bpo-17422: slightly more precise language (GH-18682)
    6df0c47

    @ericsnowcurrently
    Copy link
    Member Author

    Thanks for fixing that, Caleb!

    FWIW, I've opened a separate issue (bpo-39879) for adding a note in the language reference about dict ordering. Sorry for the confusion.

    @ned-deily
    Copy link
    Member

    New changeset 2244814 by Ned Deily (Miss Islington (bot)) in branch '3.7':
    bpo-17422: slightly more precise language (GH-18682)
    2244814

    @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.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants