Skip to content

Conversation

@eellison
Copy link
Contributor

Type objects in python have an attribute __abstractmethods__ that throws when it is accessed, so we were failing with an AttributeError whenever a type was used in TorchScript.

This pr prevents that error from happening. We can't just throw when a type is used because it could be used to access a static method: #27163

@eellison eellison requested review from driazati and suo October 15, 2019 22:08
def fn(x):
return type(x)

with self.assertRaisesRegex(RuntimeError, "value of type type"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put quotes around the output here so it doesn't look like a typo?
e.g.
value of type 'type'

# with an abstract method, in either case we cannot compile it as a class
if '__abstractmethods__' in names:
return False
fns = [getattr(cls, name) for name in names if inspect.isroutine(getattr(cls, name))]
Copy link
Contributor

Choose a reason for hiding this comment

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

You can avoid special casing type here by changing the getattr to getattr(cls, name, None)

Copy link
Contributor

Choose a reason for hiding this comment

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

Or better yet change this whole thing to this which doesn't have the problem of accessing the attribute at all:

members = inspect.getmembers(cls)
members = map(lambda x: x[1], members)
fns = filter(inspect.isroutine, members)

@suo
Copy link
Member

suo commented Oct 25, 2019

Just checking in here—any blockers?

@eellison eellison requested a review from driazati October 29, 2019 22:15
@eellison
Copy link
Contributor Author

@pytorchbot rebase this please

1 similar comment
@eellison
Copy link
Contributor Author

@pytorchbot rebase this please

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@eellison is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@eellison merged this pull request in a5aeb37.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants