-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpts-5.py
50 lines (38 loc) · 1.39 KB
/
pts-5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Python Thoughts Snippet #5 - Separate Logics
# Python 3.7
# 2019/09/11
# post: https://pythonicthoughtssnippets.github.io/#5-separate-logics
# THIS CODE IS NOT MEANT TO BE FUNCTIONAL OR EXECUTABLE,
# IT IS A REPRESENTATION OF AN IDEA AND AN EXAMPLE TO RAISE DISCUSSION.
# As a common practice in my Pythonic Thoughts Snippets,
# I am not going into the details of the minor implementations,
# on doubts please search elsewhere on the web, there are countless of
# amazing explanations; here, we focus on the broader concept
# example 1
def check_folder_exists(func):
"""
Decorator for class property setters
"""
@wraps(func)
def wrapper(self, folder):
if not Path(folder).exists():
raise FileNotFoundError(f'Path not found: {folder}')
else:
return func(self, folder)
return wrapper
class Parameters:
def __init__(self, **kwargs):
self.kwargs = kwargs
@property
def db_folder(self):
return self._db_folder
@db_folder.setter
@check_folder_exists
def db_folder(self, folder):
self._db_folder = folder
# example 2
for step in config_reader.steps:
with GCTXT.abort_if_exception(), \
GCTXT.query_upon_error(XCPTNS.ConfigReadingException), \
GCTXT.abort_if_critical_exceptions(CONFREADER.critical_errors):
step()