pytorch
3f23ad5b - [Bug] fix for module_has_exports (#50680)

Commit
3 years ago
[Bug] fix for module_has_exports (#50680) Summary: The attributes in `dir(mod)` may not be valid, this will throw error when calling `getattr`. Use `hasattr` to test if it is valid. Here is an example: ```python class A: def __init__(self, x): if x: self._attr = 1 property def val(self): return getattr(self, '_attr') a = A(False) print('val' in dir(a)) print(hasattr(a, 'val')) b = A(True) print('val' in dir(b)) print(hasattr(b, 'val')) ``` And the outputs: ``` True False True True ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/50680 Reviewed By: malfet Differential Revision: D26103975 Pulled By: eellison fbshipit-source-id: 67a799afe7d726153c91654d483937c5e198ba94
Author
Parents
Loading