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

Document collections.defaultdict parameter default_factory #85787

Closed
moshemorad12340 mannequin opened this issue Aug 23, 2020 · 6 comments
Closed

Document collections.defaultdict parameter default_factory #85787

moshemorad12340 mannequin opened this issue Aug 23, 2020 · 6 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@moshemorad12340
Copy link
Mannequin

moshemorad12340 mannequin commented Aug 23, 2020

BPO 41621
Nosy @terryjreedy, @ronaldoussoren, @miss-islington, @sweeneyde
PRs
  • bpo-41621: More accurate signature for defaultdict #21945
  • [3.10] bpo-41621: Document defaultdict's default_factory parameter (GH-21945) #26850
  • [3.9] bpo-41621: Document defaultdict's default_factory parameter (GH-21945) #26851
  • 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 2021-06-23.14:59:34.793>
    created_at = <Date 2020-08-23.19:04:06.566>
    labels = ['type-bug', '3.9', '3.10', '3.11', 'ctypes', 'docs']
    title = 'Document collections.defaultdict parameter default_factory'
    updated_at = <Date 2021-06-23.14:59:34.793>
    user = 'https://bugs.python.org/moshemorad12340'

    bugs.python.org fields:

    activity = <Date 2021-06-23.14:59:34.793>
    actor = 'terry.reedy'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-06-23.14:59:34.793>
    closer = 'terry.reedy'
    components = ['Documentation', 'ctypes']
    creation = <Date 2020-08-23.19:04:06.566>
    creator = 'moshemorad12340'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41621
    keywords = ['patch']
    message_count = 6.0
    messages = ['375823', '375840', '375843', '396340', '396343', '396426']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'ronaldoussoren', 'docs@python', 'miss-islington', 'Dennis Sweeney', 'moshemorad12340']
    pr_nums = ['21945', '26850', '26851']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41621'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @moshemorad12340
    Copy link
    Mannequin Author

    moshemorad12340 mannequin commented Aug 23, 2020

    How to reproduce
    ----------------

    >>> from collections import defaultdict
    >>> dd = defaultdict(default_factory=list)
    >>> dd
    defaultdict(None, {'default_factory': <class 'list'>})
    >>> print(dd.default_factory)
    None

    Analysis
    --------
    defdict_init(PyObject *self, PyObject *args, PyObject *kwds) function that initializing defaultdict object ignores the kwds and pass them to the dict init only.

    Expect:
    -------
    Since we can understand why we want to move kwds to dict without modification consider at least adding comment in the docstring or enforce it as positional argument only.

    @moshemorad12340 moshemorad12340 mannequin added the 3.8 only security fixes label Aug 23, 2020
    @moshemorad12340 moshemorad12340 mannequin added docs Documentation in the Doc dir topic-ctypes type-bug An unexpected behavior, bug, or error 3.8 only security fixes labels Aug 23, 2020
    @moshemorad12340 moshemorad12340 mannequin added docs Documentation in the Doc dir topic-ctypes type-bug An unexpected behavior, bug, or error labels Aug 23, 2020
    @iritkatriel iritkatriel added 3.9 only security fixes 3.10 only security fixes labels Aug 23, 2020
    @ronaldoussoren
    Copy link
    Contributor

    This is intentional behaviour, the factory can only be passed as a positional argument.

    The documentation[1] mentions this, although its probably possible to write this a bit clearer.

    [1] https://docs.python.org/3.8/library/collections.html#collections.defaultdict

    @sweeneyde
    Copy link
    Member

    PR 21945 changes the signature:

    • defaultdict(default_factory[, ...])
      + defaultdict(default_factory=None, /, [...])

    @terryjreedy terryjreedy added 3.11 only security fixes and removed 3.8 only security fixes labels Jun 22, 2021
    @terryjreedy terryjreedy changed the title defaultdict miss behave when using default_factory passed as kwargs Document collections.defaultdict parameter default_factory Jun 22, 2021
    @terryjreedy terryjreedy added 3.11 only security fixes and removed 3.8 only security fixes labels Jun 22, 2021
    @terryjreedy terryjreedy changed the title defaultdict miss behave when using default_factory passed as kwargs Document collections.defaultdict parameter default_factory Jun 22, 2021
    @terryjreedy
    Copy link
    Member

    New changeset d1ae570 by Dennis Sweeney in branch 'main':
    bpo-41621: Document defaultdict's default_factory parameter (GH-21945)
    d1ae570

    @miss-islington
    Copy link
    Contributor

    New changeset a65df3f by Miss Islington (bot) in branch '3.9':
    bpo-41621: Document defaultdict's default_factory parameter (GH-21945)
    a65df3f

    @terryjreedy
    Copy link
    Member

    New changeset 88a3342 by Miss Islington (bot) in branch '3.10':
    bpo-41621: Document defaultdict's default_factory parameter (GH-21945)
    88a3342

    @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.9 only security fixes 3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir topic-ctypes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants