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

structseq types should expose _fields #64429

Closed
abarnert mannequin opened this issue Jan 13, 2014 · 2 comments
Closed

structseq types should expose _fields #64429

abarnert mannequin opened this issue Jan 13, 2014 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@abarnert
Copy link
Mannequin

abarnert mannequin commented Jan 13, 2014

BPO 20230
Nosy @skrah, @meadori, @ethanfurman, @1st1
Superseder
  • bpo-1820: Enhance Object/structseq.c to match namedtuple and tuple api
  • Files
  • structseq.diff
  • 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 2014-04-29.11:56:03.434>
    created_at = <Date 2014-01-13.01:12:54.433>
    labels = ['interpreter-core', 'type-feature', 'library']
    title = 'structseq types should expose _fields'
    updated_at = <Date 2014-04-29.11:58:18.088>
    user = 'https://bugs.python.org/abarnert'

    bugs.python.org fields:

    activity = <Date 2014-04-29.11:58:18.088>
    actor = 'skrah'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-04-29.11:56:03.434>
    closer = 'skrah'
    components = ['Interpreter Core', 'Library (Lib)']
    creation = <Date 2014-01-13.01:12:54.433>
    creator = 'abarnert'
    dependencies = []
    files = ['33436']
    hgrepos = []
    issue_num = 20230
    keywords = ['patch']
    message_count = 2.0
    messages = ['207991', '207993']
    nosy_count = 5.0
    nosy_names = ['skrah', 'meador.inge', 'ethan.furman', 'yselivanov', 'abarnert']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '1820'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue20230'
    versions = ['Python 3.5']

    @abarnert
    Copy link
    Mannequin Author

    abarnert mannequin commented Jan 13, 2014

    A PyStructSequence type doesn't expose its field names in any way to Python code (except indirectly, via the repr, which you could parse if you really wanted to…).

    The docs claim that "Struct sequence objects are the C equivalent of namedtuple() objects", so it seems like the obvious way to expose them is the exact same way namedtuple types do—as a class attribute named "_fields".

    Also, in bpo-7796, and in a recent thread on python-ideas, multiple people suggested that "named tuple" is a protocol, not a type, and duck typing on _fields is the obvious way to detect types matching that protocol.

    Only the "sequence fields" need to be exposed—fields that don't match up to sequence indices aren't named tuple fields, they're just extra instance attributes (that don't even show up in the repr).

    Patch included. For the tests, I tested the fields in struct_time and stat_result in effectively the same way test_repr tests their repr, so it should pass on all the same platforms/builds.

    @abarnert abarnert mannequin added the type-feature A feature request or enhancement label Jan 13, 2014
    @abarnert
    Copy link
    Mannequin Author

    abarnert mannequin commented Jan 13, 2014

    After more searching (I should have searched on structseq instead of PyStructSequence…), this might be a dup of bpo-1820. If so, apologies.

    @1st1 1st1 added interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir labels Jan 13, 2014
    @skrah skrah mannequin closed this as completed Apr 29, 2014
    @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) stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant