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

does not rescue exceptions raised by to_x #710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion spec/tags/core/array/try_convert_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/core/hash/try_convert_tags.txt

This file was deleted.

4 changes: 3 additions & 1 deletion topaz/objspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ def convert_type(self, w_obj, w_cls, method, raise_error=True):

try:
w_res = self.send(w_obj, method)
except RubyError:
except RubyError as e:
if not isinstance(e.w_value, W_NoMethodError):
Copy link
Member

Choose a reason for hiding this comment

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

Use, space.is_kind_of here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, to_x can raise NoMethodError by itself. may be here better check respond_to? instead of try except.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, using respond_to makes more sense if we don't want to catch that issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, respond_to not good because of method_missing

Copy link
Member

Choose a reason for hiding this comment

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

In my limited tests, Hash seems to swallow NoMethodErrors from insiide to_h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ruby -e 'x = Object.new; def x.to_int; self.aaa; end; [].take(x)'
-e:1:in `to_int': undefined method `aaa' for #<Object:0x000000026bff88> (NoMethodError)

Copy link
Member

Choose a reason for hiding this comment

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

Interesting.

raise
if not raise_error:
return self.w_nil
src_cls_name = self.obj_to_s(self.getclass(w_obj))
Expand Down