Skip to content

Commit c145d02

Browse files
committed
fix incorrectly written lazy properties [GH-6]
The lazy properties weren't lazy...on the opposite the way they were written they were rebuilt the property was called.
1 parent d861485 commit c145d02

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

compdb/backend/json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class JSONCompilationDatabase(CompilationDatabaseInterface):
1212
def __init__(self, json_db_path):
1313
self.json_db_path = json_db_path
14+
self.__data = None
1415

1516
@classmethod
1617
def probe_directory(cls, directory):
@@ -48,7 +49,7 @@ def _dict_to_compile_command(d):
4849

4950
@property
5051
def _data(self):
51-
if not hasattr(self, '__data'):
52+
if self.__data is None:
5253
with open(self.json_db_path) as f:
5354
self.__data = json.load(f)
5455
return self.__data

compdb/includedb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class IncludedByDatabase(CompilationDatabaseInterface):
141141
def __init__(self, graph, database):
142142
self.graph = graph
143143
self.database = database
144+
self.__db_index = None
144145

145146
def __repr__(self):
146147
return '<IncludedByGraph: graph = {}, database = {}>'.format(
@@ -177,7 +178,7 @@ def _bfs_walk_from(self, path):
177178

178179
@property
179180
def _db_index(self):
180-
if not hasattr(self, '__db_index'):
181+
if self.__db_index is None:
181182
self.__db_index = frozenset(self.database.get_all_files())
182183
return self.__db_index
183184

0 commit comments

Comments
 (0)