Skip to content

Commit 1ca1bd8

Browse files
authored
Fix translation of classes containing comments (pyccel#2079)
Fix translation of classes containing comments by discarding the comments. Fixes pyccel#2078
1 parent 3e2f5f1 commit 1ca1bd8

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ All notable changes to this project will be documented in this file.
7979
- #2008 : Ensure list/set/dict assignment is recognised as a reference.
8080
- #2039 : Ensure any expressions in the iterable of a for loop are calculated before the loop.
8181
- #2013 : Stop limiting the length of strings to 128 characters.
82+
- #2078 : Fix translation of classes containing comments.
8283

8384
### Changed
8485

pyccel/parser/syntactic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,9 @@ def _visit_ClassDef(self, stmt):
10301030
if isinstance(visited_i, FunctionDef):
10311031
methods.append(visited_i)
10321032
visited_i.arguments[0].bound_argument = True
1033-
elif isinstance(visited_i, Pass):
1033+
elif isinstance(visited_i, (Pass, Comment)):
1034+
continue
1035+
elif isinstance(visited_i, CodeBlock) and all(isinstance(x, Comment) for x in visited_i.body):
10341036
continue
10351037
elif isinstance(visited_i, AnnotatedPyccelSymbol):
10361038
attributes.append(visited_i)

tests/epyccel/classes/classes_1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ def __init__(self, x : 'float[:]'):
66
self._X = 10
77
self._x = x
88

9+
#--------------------------------------
910
def __del__(self):
1011
pass
1112

13+
#--------------------------------------
1214
def translate(self, a : 'float[:]'):
1315
self._x[:] = self._x + a
1416

17+
#--------------------------------------
1518
def get_x(self):
1619
return self._x
1720

21+
#--------------------------------------
22+
#--------------------------------------
1823
def get_X(self):
1924
return self._X
2025

0 commit comments

Comments
 (0)