Skip to content

Commit

Permalink
Merge pull request #1954 from glensc/decorated
Browse files Browse the repository at this point in the history
Refactor: Use decorator package to make decorators
  • Loading branch information
glensc authored May 21, 2024
2 parents d931c91 + 9b0e947 commit 0ec42a1
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 161 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cattrs = {version="==23.2.3", python_version=">='3.7'"}
certifi = "==2024.2.2"
charset-normalizer = "==3.3.2"
click = "==8.1.7"
decorator = "==5.1.1"
deprecated = "==1.2.14"
humanize = "==4.9.0"
idna = {version="==3.7", python_version=">='3.5'"}
Expand Down
47 changes: 18 additions & 29 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions plextraktsync/decorators/coro.py
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))
29 changes: 10 additions & 19 deletions plextraktsync/decorators/flatten.py
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))
13 changes: 5 additions & 8 deletions plextraktsync/decorators/nocache.py
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)
Loading

0 comments on commit 0ec42a1

Please sign in to comment.