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

inspect.getfile(obj) calls object repr on failure #74824

Closed
takluyver mannequin opened this issue Jun 12, 2017 · 9 comments
Closed

inspect.getfile(obj) calls object repr on failure #74824

takluyver mannequin opened this issue Jun 12, 2017 · 9 comments
Labels
3.7 (EOL) end of life easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@takluyver
Copy link
Mannequin

takluyver mannequin commented Jun 12, 2017

BPO 30639
Nosy @bitdancer, @takluyver, @serhiy-storchaka, @1st1
PRs
  • bpo-30639: Lazily compute repr for error #2132
  • 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 2017-10-24.12:43:35.838>
    created_at = <Date 2017-06-12.13:54:06.692>
    labels = ['3.7', 'easy', 'type-feature', 'library']
    title = 'inspect.getfile(obj) calls object repr on failure'
    updated_at = <Date 2017-10-24.12:43:35.836>
    user = 'https://github.com/takluyver'

    bugs.python.org fields:

    activity = <Date 2017-10-24.12:43:35.836>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-24.12:43:35.838>
    closer = 'yselivanov'
    components = ['Library (Lib)']
    creation = <Date 2017-06-12.13:54:06.692>
    creator = 'takluyver'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30639
    keywords = ['easy']
    message_count = 9.0
    messages = ['295782', '295792', '295796', '295807', '295808', '295809', '295811', '304903', '304905']
    nosy_count = 4.0
    nosy_names = ['r.david.murray', 'takluyver', 'serhiy.storchaka', 'yselivanov']
    pr_nums = ['2132']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30639'
    versions = ['Python 3.7']

    @takluyver
    Copy link
    Mannequin Author

    takluyver mannequin commented Jun 12, 2017

    This came up in IPython & Jedi: several functions in inspect end up calling getfile(). If the object is something for which it can't find the source file, it throws an error, the message for which contains the object's repr.

    This is problematic for us because for some objects the repr may be expensive to calculate (e.g. data tables where the repr forms primary output, not just debugging information). In some cases, it could also throw another error.

    I plan to make a PR for this, but I'm opening an issue so I've got a bpo number.

    ipython/ipython#10493
    davidhalter/jedi#919

    @takluyver takluyver mannequin added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Jun 12, 2017
    @bitdancer
    Copy link
    Member

    What is your proposed solution? This doesn't at the moment sound like a bug in Python to me.

    @takluyver
    Copy link
    Mannequin Author

    takluyver mannequin commented Jun 12, 2017

    Not exactly a bug, but I think that an improvement is possible. My plan is to delay computing the repr until the error is formatted, so that code which catches the TypeError can carry on safely.

    I think this is more relevant for inspect than for many other modules, because by design, we're often calling inspect functions on arbitrary objects which we can make few guarantees about.

    @serhiy-storchaka
    Copy link
    Member

    I think in that case it is enough to report just type name.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life type-feature A feature request or enhancement easy and removed type-bug An unexpected behavior, bug, or error labels Jun 12, 2017
    @takluyver
    Copy link
    Mannequin Author

    takluyver mannequin commented Jun 12, 2017

    Sure, I can do that if you want. The other thing I thought of was using object.__repr__, so the repr always shows like <foo object at 0x123abc...> .

    @serhiy-storchaka
    Copy link
    Member

    The address of the object is not informative. The possibility of getting a source file is determined by the type of the object.

    @takluyver
    Copy link
    Mannequin Author

    takluyver mannequin commented Jun 12, 2017

    OK, I've updated the PR to do that.

    @1st1
    Copy link
    Member

    1st1 commented Oct 24, 2017

    New changeset e968bc7 by Yury Selivanov (Thomas Kluyver) in branch 'master':
    bpo-30639: Lazily compute repr for error (bpo-2132)
    e968bc7

    @1st1
    Copy link
    Member

    1st1 commented Oct 24, 2017

    Thank you, Thomas.

    @1st1 1st1 closed this as completed Oct 24, 2017
    @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 easy stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants