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

traceback attribute error #48284

Closed
ghazel mannequin opened this issue Oct 3, 2008 · 9 comments
Closed

traceback attribute error #48284

ghazel mannequin opened this issue Oct 3, 2008 · 9 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@ghazel
Copy link
Mannequin

ghazel mannequin commented Oct 3, 2008

BPO 4034
Nosy @pitrou, @vstinner, @benjaminp
Files
  • use_struct_member.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 2009-03-18.20:52:52.385>
    created_at = <Date 2008-10-03.23:31:58.673>
    labels = ['type-bug']
    title = 'traceback attribute error'
    updated_at = <Date 2009-03-18.21:35:15.810>
    user = 'https://bugs.python.org/ghazel'

    bugs.python.org fields:

    activity = <Date 2009-03-18.21:35:15.810>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-03-18.20:52:52.385>
    closer = 'benjamin.peterson'
    components = []
    creation = <Date 2008-10-03.23:31:58.673>
    creator = 'ghazel'
    dependencies = []
    files = ['11703']
    hgrepos = []
    issue_num = 4034
    keywords = ['patch', 'needs review']
    message_count = 9.0
    messages = ['74282', '74326', '74330', '74405', '74783', '78411', '83719', '83776', '83780']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'vstinner', 'ghazel', 'benjamin.peterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4034'
    versions = ['Python 2.6']

    @ghazel
    Copy link
    Mannequin Author

    ghazel mannequin commented Oct 3, 2008

    Unrelated to this bug, I would like to have the ability to remove the
    reference to the frame from the traceback object. Specifically so that
    the traceback object could be stored for a while without keeping all
    the locals alive as well.

    So, periodically I test to see if python allows that. Python 2.6 gave
    some strange results compared to 2.5.2:

    Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit 
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> try:
    ...     x = dskjfds
    ... except:
    ...     import sys
    ...     t, v, tb = sys.exc_info()
    ...
    >>> tb
    <traceback object at 0x01396670>
    >>> dir(tb)
    ['tb_frame', 'tb_lasti', 'tb_lineno', 'tb_next']
    >>> tb.tb_frame
    <frame object at 0x01371598>
    >>> tb.tb_frame = None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'traceback' object has only read-only attributes (assign 
    to .tb_frame)
    >>>
    
    
    Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit 
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> try:
    ...     x = lfdskf
    ... except:
    ...     import sys
    ...     t, v, tb = sys.exc_info()
    ...
    >>> tb
    <traceback object at 0x01581F80>
    >>> dir(tb)
    ['tb_frame', 'tb_lasti', 'tb_lineno', 'tb_next']
    >>> tb.tb_frame
    <frame object at 0x013B9E10>
    >>> tb.tb_frame = None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'traceback' object has no attribute 'tb_frame'
    >>>

    @ghazel ghazel mannequin added the type-bug An unexpected behavior, bug, or error label Oct 3, 2008
    @benjaminp
    Copy link
    Contributor

    Here's a patch. It looks like traceback just needs to use a struct
    sequence instead of providing tp_getattr its self.

    @ghazel
    Copy link
    Mannequin Author

    ghazel mannequin commented Oct 4, 2008

    There seem to be some other exception type and string inconsistencies,
    but they are not new to Python 2.6

    >>> tb.tb_frame = None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'traceback' object has only read-only attributes (assign 
    to .tb_frame)
    
    >>> tb.tb_frame.f_locals = None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: attribute 'f_locals' of 'frame' objects is not writable
    
    >>> tb.tb_frame.f_globals = None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: readonly attribute
    
    >>> dict.clear = "foo"
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: can't set attributes of built-in/extension type 'dict'

    Should it be an AttributeError or TypeError? Should it be "read-only",
    readonly", "not writable" or "can't set"?

    Btw, here's the other ticket for the feature request:
    http://bugs.python.org/issue1565525

    @vstinner
    Copy link
    Member

    vstinner commented Oct 6, 2008

    Instead of converting tb_frame attribute to read only, I prefer to
    allow the user to clear the traceback to free some memory bytes. So I
    wrote a different patch.

    marge$ ./python
    Python 2.7a0 (trunk:66786M, Oct  7 2008, 00:48:32)
    >>> try:
    ...  a
    ... except:
    ...  import sys
    ...  t, v, tb = sys.exc_info()
    ...
    >>> tb
    <traceback object at 0xb7c76edc>
    >>> tb.tb_frame
    <frame object at 0x81cdbec>
    >>> tb.tb_frame=42
    >>> tb.tb_frame
    42
    >>> tb.tb_frame=None
    >>>

    @vstinner
    Copy link
    Member

    My patch causes a crash with:

    import sys
    try:
        raise Exception("hm!")
    except:
        t, v, tb = sys.exc_info()
        tb.tb_frame = {}
        raise t, v, tb

    Change tb.tb_frame value is not a good idea. It's better to clear
    locals/globals: see msg74329.

    @pitrou
    Copy link
    Member

    pitrou commented Dec 28, 2008

    One possibility would be to only allow deleting the tb_frame attribute
    (setting it to NULL), not setting it to an arbitrary object.

    @vstinner
    Copy link
    Member

    Ping. benjamin.peterson's patch fixes the very strange issue, and I
    would like to see it upstream.

    About clearing the frame/traceback, it's another issue (bpo-1565525).

    @benjaminp
    Copy link
    Contributor

    Fixed in r70463.

    @vstinner
    Copy link
    Member

    @benjamin.peterson: Cool! Thanks.

    @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
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants