-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1954 from glensc/decorated
Refactor: Use decorator package to make decorators
- Loading branch information
Showing
8 changed files
with
113 additions
and
161 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import asyncio | ||
from functools import wraps | ||
|
||
from decorator import decorator | ||
|
||
def coro(f): | ||
|
||
@decorator | ||
def coro(f, *args, **kwargs): | ||
""" | ||
Decorator to get started with async/await with click | ||
https://github.com/pallets/click/issues/85#issuecomment-503464628 | ||
""" | ||
@wraps(f) | ||
def wrapper(*args, **kwargs): | ||
return asyncio.run(f(*args, **kwargs)) | ||
|
||
return wrapper | ||
return asyncio.run(f(*args, **kwargs)) |
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 |
---|---|---|
@@ -1,25 +1,16 @@ | ||
from functools import wraps | ||
from decorator import decorator | ||
|
||
|
||
def flatten_list(method): | ||
@wraps(method) | ||
def inner(*args, **kwargs): | ||
return list(method(*args, **kwargs)) | ||
@decorator | ||
def flatten_list(method, *args, **kwargs): | ||
return list(method(*args, **kwargs)) | ||
|
||
return inner | ||
|
||
@decorator | ||
def flatten_dict(method, *args, **kwargs): | ||
return dict(method(*args, **kwargs)) | ||
|
||
def flatten_dict(method): | ||
@wraps(method) | ||
def inner(*args, **kwargs): | ||
return dict(method(*args, **kwargs)) | ||
|
||
return inner | ||
|
||
|
||
def flatten_set(method): | ||
@wraps(method) | ||
def inner(*args, **kwargs): | ||
return set(method(*args, **kwargs)) | ||
|
||
return inner | ||
@decorator | ||
def flatten_set(method, *args, **kwargs): | ||
return set(method(*args, **kwargs)) |
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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
from functools import wraps | ||
from decorator import decorator | ||
|
||
from plextraktsync.factory import factory | ||
|
||
session = factory.session | ||
|
||
|
||
def nocache(method): | ||
@wraps(method) | ||
def inner(*args, **kwargs): | ||
with session.cache_disabled(): | ||
return method(*args, **kwargs) | ||
|
||
return inner | ||
@decorator | ||
def nocache(method, *args, **kwargs): | ||
with session.cache_disabled(): | ||
return method(*args, **kwargs) |
Oops, something went wrong.