-
Notifications
You must be signed in to change notification settings - Fork 492
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
Summary: 'TryExcept 6' is too complex (13) See https://www.flake8rules.com/rules/C901.html Differential Revision: D64511308
- Loading branch information
1 parent
ea876e1
commit 5b08cac
Showing
2 changed files
with
65 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,56 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# pyre-strict | ||
|
||
from functools import wraps | ||
from types import TracebackType | ||
from typing import Any, Callable, 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-ignore[3]: Return type cannot contain Any. | ||
def log_usage( | ||
*log_args: Any, **log_kwargs: Any | ||
) -> Callable[[Callable[..., Any]], Callable[..., Any]]: | ||
# pyre-ignore[2]: Callable cannot return Any. | ||
# pyre-ignore[3]: Return type cannot contain Any. | ||
def _log_usage(func: Callable[..., Any]) -> Callable[..., Any]: | ||
@wraps(func) | ||
# pyre-ignore[3]: Return type cannot contain Any. | ||
def wrapper(*args: Any, **kwargs: Any) -> 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 |