forked from pytorch/captum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce complexity of logging try-catch + add typing (pytorch#1380)
Summary: Pull Request resolved: pytorch#1380 'TryExcept 6' is too complex (13) See https://www.flake8rules.com/rules/C901.html Reviewed By: jjuncho Differential Revision: D64511308 fbshipit-source-id: c42173f6e7ea4b8732141640f4886b3e347f599a
- Loading branch information
1 parent
0f2170a
commit 8dc48a5
Showing
2 changed files
with
64 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# pyre-strict | ||
|
||
from functools import wraps | ||
from types import TracebackType | ||
from typing import Any, List, Optional, Union | ||
|
||
|
||
def log(*args: Any, **kwargs: Any) -> None: | ||
pass | ||
|
||
|
||
class TimedLog: | ||
def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
pass | ||
|
||
def __enter__(self) -> "TimedLog": | ||
return self | ||
|
||
def __exit__( | ||
self, | ||
exception_type: Optional[BaseException], | ||
exception_value: Optional[BaseException], | ||
traceback: Optional[TracebackType], | ||
) -> bool: | ||
return exception_value is not None | ||
|
||
|
||
# pyre-fixme[3]: Return type must be annotated. | ||
def log_usage(*log_args: Any, **log_kwargs: Any): | ||
# pyre-fixme[3]: Return type must be annotated. | ||
# pyre-fixme[2]: Parameter must be annotated. | ||
def _log_usage(func): | ||
@wraps(func) | ||
# pyre-fixme[53]: Captured variable `func` is not annotated. | ||
# pyre-fixme[3]: Return type must be annotated. | ||
def wrapper(*args: Any, **kwargs: Any): | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return _log_usage | ||
|
||
|
||
def set_environment(env: Union[None, List[str], str]) -> None: | ||
pass | ||
|
||
|
||
def disable_detailed_logging() -> None: | ||
pass | ||
|
||
|
||
def patch_methods(_, patch_log: bool = True) -> None: | ||
pass |