File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,15 @@ def _get_parser(
84
84
os .path .join (self ._cache_dirpath , version , name ) + ".pickle"
85
85
)
86
86
grammar_filepath : str = os .path .join (self ._directory , grammar_filename )
87
- if not os .path .exists (cache_filepath ) or not self ._use_grammar_cache :
87
+
88
+ tree = None
89
+ if os .path .exists (cache_filepath ) and self ._use_grammar_cache :
90
+ try :
91
+ tree = self .load (cache_filepath )
92
+ except ValueError :
93
+ # pickle errors on unsupported protocols - newer python versions (#93)
94
+ pass
95
+ if tree is None :
88
96
tree = Lark .open (
89
97
grammar_filepath ,
90
98
parser = "lalr" ,
@@ -94,8 +102,7 @@ def _get_parser(
94
102
maybe_placeholders = False ,
95
103
)
96
104
self .save (tree , cache_filepath )
97
- else :
98
- tree = self .load (cache_filepath )
105
+
99
106
return tree
100
107
101
108
@cached_property
@@ -126,7 +133,7 @@ def save(a_parser: Tree, path: str) -> None:
126
133
if not os .path .exists (dirpath ):
127
134
os .makedirs (dirpath )
128
135
with open (path , "wb" ) as file_parser :
129
- pickle .dump (write_data , file_parser , pickle . HIGHEST_PROTOCOL )
136
+ pickle .dump (write_data , file_parser )
130
137
131
138
@staticmethod
132
139
def load (path : str ) -> Tree :
You can’t perform that action at this time.
0 commit comments