Conditions | 10 |
Total Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like JobDB.__init__() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | |||
12 | def __init__(self): |
||
13 | |||
14 | directory = get_directory() |
||
15 | |||
16 | self.logger = logging.getLogger('ZODB.FileStorage') |
||
17 | fh = logging.FileHandler(directory + 'db.log') |
||
18 | self.logger.addHandler(fh) |
||
19 | |||
20 | self.storage = FileStorage.FileStorage(directory + 'db.fs') |
||
21 | self.db = DB(self.storage) |
||
22 | self.connection = self.db.open() |
||
23 | |||
24 | dbroot = self.connection.root() |
||
25 | |||
26 | if 'job_key' not in dbroot: |
||
27 | from BTrees.OOBTree import OOBTree |
||
28 | dbroot['job_key'] = OOBTree() |
||
29 | dbroot['job_key']['val'] = 0 |
||
30 | |||
31 | self.job_key = dbroot['job_key'] |
||
32 | |||
33 | # Ensure that a 'job_db' key is present |
||
34 | # in the root |
||
35 | if 'job_db' not in dbroot: |
||
36 | from BTrees.OOBTree import OOBTree |
||
37 | dbroot['job_db'] = OOBTree() |
||
38 | |||
39 | self.job_db = dbroot['job_db'] |
||
40 | |||
41 | if 'user_db' not in dbroot: |
||
42 | from BTrees.OOBTree import OOBTree |
||
43 | dbroot['user_db'] = OOBTree() |
||
44 | self.user_db = dbroot['user_db'] |
||
45 | self.user_db['user'] = User('unknown', 'unknown', 'unknown') |
||
46 | |||
47 | self.user_db = dbroot['user_db'] |
||
48 | |||
49 | if 'site_db' not in dbroot: |
||
50 | from BTrees.OOBTree import OOBTree |
||
51 | dbroot['site_db'] = OOBTree() |
||
52 | self.site_db = dbroot['site_db'] |
||
53 | |||
54 | self.site_db = dbroot['site_db'] |
||
55 | |||
56 | if scheduler is not None: |
||
57 | self.site_db[scheduler.name()] = Site(scheduler.name(), |
||
58 | scheduler.scheduler_type()) |
||
59 | |||
60 | if 'queue_db' not in dbroot: |
||
61 | from BTrees.OOBTree import OOBTree |
||
62 | dbroot['queue_db'] = OOBTree() |
||
63 | self.queue_db = dbroot['queue_db'] |
||
64 | |||
65 | self.queue_db = dbroot['queue_db'] |
||
66 | |||
67 | from .version import get_git_version |
||
68 | if 'version' not in dbroot: |
||
69 | dbroot['version'] = get_git_version() |
||
70 | else: |
||
71 | current_version = dbroot['version'] |
||
72 | new_version = get_git_version() |
||
73 | # Add any migrations required here |
||
74 | if current_version != new_version: |
||
75 | pass |
||
76 | |||
77 | dbroot['version'] = new_version |
||
78 | |||
79 | if 'remote_site_db' not in dbroot: |
||
80 | from BTrees.OOBTree import OOBTree |
||
81 | dbroot['remote_site_db'] = OOBTree() |
||
82 | self.remote_site_db = dbroot['remote_site_db'] |
||
83 | |||
84 | self.remote_site_db = dbroot['remote_site_db'] |
||
85 | |||
217 |
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.