[proxy] github.com← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public

Conversation

Copy link
Contributor

takluyver commented Jun 12, 2017

If the TypeError is caught and handled by calling code, there's no need to compute the object's repr for the error message - the repr may take a long time (real case encountered in IPython & Jedi), or it may throw another error.

If the error results in a traceback, it will still compute the repr and produce the message as before.

I think this defensiveness is worthwhile for inspect functions because, by design, we're calling them with arbitrary objects which might be badly behaved, and expecting them to be useful nonetheless.

An alternative fix would be to use object.__repr__() to always get the plain <foo object at 0x123abc...> representation.

https://bugs.python.org/issue30639

Copy link

@takluyver, thanks for your PR! By analyzing the history of the files in this pull request, we identified @larryhastings, @1st1 and @zestyping to be potential reviewers.

Copy link
Contributor

marco-buttu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A part of the newline that should be removed, the rest LGTM

Lib/inspect.py Outdated
lines.pop(0)
return '\n'.join(lines)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new line should be removed.

Lib/inspect.py Outdated
'function, traceback, frame, or code object'.format(object))
raise TypeError('object of type {} is not a module, class, method, '
'function, traceback, frame, or code object'.format(
type(object).__name__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry I did not tell you in the previous message, but I realized just now. You should align the type(object).__name__ to 'function'.

Copy link
Contributor Author

Can I prevail on anyone to merge this? @serhiy-storchaka , I implemented the change you suggested on the issue.

serhiy-storchaka requested a review from 1st1 June 20, 2017 15:22
Copy link
Member

Could you please take a look on this change @1st1?

Copy link
Member

1st1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a NEWS entry using blurb.

'function, traceback, frame, or code object'.format(object))
raise TypeError('object of type {} is not a module, class, method, '
'function, traceback, frame, or code object'.format(
type(object).__name__))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please change the error message to "module, class, method, function, traceback, frame, or code object was expected, got {}".

Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Contributor Author

I have made the requested changes; please review again

Copy link

Thanks for making the requested changes!

@serhiy-storchaka, @1st1: please review the changes made to this pull request.

Copy link
Member

1st1 commented Oct 24, 2017

Merged. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants