Skip to content

Commit

Permalink
Configure and use black
Browse files Browse the repository at this point in the history
  • Loading branch information
pcart-grandjean committed Feb 21, 2024
1 parent db6f139 commit a1a2805
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"files.trimTrailingWhitespace": true
"files.trimTrailingWhitespace": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"editor.formatOnSave": true,
"black-formatter.args": [
"--line-length=160"
]
}
24 changes: 15 additions & 9 deletions executiontime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Defines the printexecutiontime decorator
"""

from datetime import datetime
from functools import wraps
from typing import Any, Callable, Optional
Expand All @@ -24,20 +25,23 @@
WHITE = Fore.WHITE
YELLOW = Fore.YELLOW

def printexecutiontime(message: str, output: Callable[..., None] =print, color:Optional[str]=None)->Any:
'''

def printexecutiontime(message: str, output: Callable[..., None] = print, color: Optional[str] = None) -> Any:
"""
This function returns a decorator. This allows to have a decorator that accepts parameters.
message: A string with a '{0}' placeholder for the time that will be sent to the console.
'''
def decorator(function: Callable[..., Any])->Any:
'''
"""

def decorator(function: Callable[..., Any]) -> Any:
"""
The decorator itself returns a wrapper function that will replace the original one.
'''
"""

@wraps(function)
def wrapper(*args: Any, **kwargs: Any)->Any:
'''
def wrapper(*args: Any, **kwargs: Any) -> Any:
"""
This wrapper calculates and displays the execution time of the function.
'''
"""
start = datetime.utcnow()
value = function(*args, **kwargs)
elapsed = datetime.utcnow() - start
Expand All @@ -46,5 +50,7 @@ def wrapper(*args: Any, **kwargs: Any)->Any:
msg = color + msg + Fore.RESET
output(msg)
return value

return wrapper

return decorator

0 comments on commit a1a2805

Please sign in to comment.