mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
It generally recommended to use `is/is not` to compare types. Therefore this series of changes apply this suggestion in the code base, and it aims to finally enabling related linter checks. Pull Request resolved: https://github.com/pytorch/pytorch/pull/165037 Approved by: https://github.com/mlazos
17 lines
404 B
Python
17 lines
404 B
Python
from types import ModuleType
|
|
from typing import Any
|
|
|
|
from .._mangling import is_mangled
|
|
|
|
|
|
def is_from_package(obj: Any) -> bool:
|
|
"""
|
|
Return whether an object was loaded from a package.
|
|
|
|
Note: packaged objects from externed modules will return ``False``.
|
|
"""
|
|
if type(obj) is ModuleType:
|
|
return is_mangled(obj.__name__)
|
|
else:
|
|
return is_mangled(type(obj).__module__)
|