Skip to content

Commit 75ba6af

Browse files
committed
Add all_methods_ids property to ClassDefinition and update unique_id handling in PythonParser
1 parent bed09f2 commit 75ba6af

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

codetide/core/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ def references(self)->List[CodeReference]:
133133
sum([method.references for method in self.methods], [])
134134
)
135135
return all_references
136+
137+
@property
138+
def all_methods_ids(self)->List[str]:
139+
return [
140+
method.unique_id for method in self.methods
141+
]
136142

137143
class CodeFileModel(BaseModel):
138144
"""Representation of a single code file"""
@@ -658,7 +664,7 @@ def get(self, unique_id :Union[str, List[str]], degree :int=0, as_string :bool=F
658664
new_references_ids = []
659665
for reference in references_ids:
660666
element = self._cached_elements.get(reference)
661-
if element is not None and element.unique_id not in retrieved_ids:
667+
if element is not None and (element.unique_id not in retrieved_ids):
662668
retrieved_elements.append(element)
663669
retrieved_ids.append(element.unique_id)
664670

codetide/parsers/python_parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,19 @@ def _process_function_definition(cls, node: Node, code: bytes, codeFile: CodeFil
306306
if is_class_method:
307307
if raw is None:
308308
raw = cls._get_content(code, node, preserve_indentation=True)
309-
codeFile.classes[-1].add_method(
310-
MethodDefinition(
309+
310+
codeFile.classes[-1].add_method(MethodDefinition(
311311
name=definition,
312312
signature=signature,
313313
decorators=decorators,
314314
modifiers=modifiers,
315315
raw=raw
316316
)
317317
)
318+
currentMethod = codeFile.classes[-1].methods[-1]
319+
if currentMethod.unique_id in codeFile.classes[-1].all_methods_ids[:-1] and currentMethod.decorators:
320+
currentMethod.unique_id = f"{currentMethod.unique_id}{''.join(currentMethod.decorators)}"
321+
318322
else:
319323
if raw is None:
320324
raw = cls._get_content(code, node)

0 commit comments

Comments
 (0)