Repository: pyccel/pyccel (python)

Issue:
[DICT] Add Python support for clear
### Describe the feature
Syntactic and semantic support should be added for `clear`. This should be tested by implementing Python printing

### Test Code
Provide code which does not currently work but which should do when this issue is fixed:
```python
def foo():
    a = {1,1.0, 2:2.0}
    a.clear()
    return a
```


Pull request description:
 [DICT] Add Python support for clear 
Files dict_methods.py, class_defs.py, test_epyccel_dicts.py and pycode.py were changed. Reference to issue #1880.
Closes #1880 

Patch:
diff --git a/AUTHORS b/AUTHORS
index 8ff6e447..ebd23a77 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -37,3 +37,4 @@ Contributors
 * Emmmanuel Ferdman
 * Mohammed Ayaz Shaikh
 * Amir Movassaghi
+* Leonardo Merlin Paloschi
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d7cee43..8a52b3fc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
 
 ### Added
 
+-   #1880 : Add Python support for dict method `clear()`
 -   #1720 : Add support for `Ellipsis` as the only index for an array.
 -   #1787 : Ensure STC is installed with Pyccel.
 -   #1656 : Ensure gFTL is installed with Pyccel.
diff --git a/docs/builtin-functions.md b/docs/builtin-functions.md
index 16e23cc2..8efc5e8a 100644
--- a/docs/builtin-functions.md
+++ b/docs/builtin-functions.md
@@ -120,7 +120,7 @@ Python contains a limited number of builtin functions defined [here](https://doc
 
 | Method | Supported |
 |----------|-----------|
-| `clear` | No |
+| `clear` | Python-only |
 | `copy` | No |
 | `get` | Python-only |
 | `items` | No |
diff --git a/pyccel/ast/builtin_methods/dict_methods.py b/pyccel/ast/builtin_methods/dict_methods.py
index 878c3a9e..362f0bdf 100644
--- a/pyccel/ast/builtin_methods/dict_methods.py
+++ b/pyccel/ast/builtin_methods/dict_methods.py
@@ -10,10 +10,12 @@ always available.
 This module contains objects which describe these methods within Pyccel's AST.
 """
 
-from pyccel.ast.datatypes import InhomogeneousTupleType
+from pyccel.ast.datatypes import InhomogeneousTupleType, VoidType
 from pyccel.ast.internals import PyccelFunction
 
-__all__ = ('DictGet',
+
+__all__ = ('DictClear',
+           'DictGet',
            'DictMethod',
            'DictPop',
            'DictPopitem',
@@ -178,7 +180,6 @@ class DictGet(DictMethod):
         return self._args[1]
 
 #==============================================================================
-
 class DictSetDefault(DictMethod):
     """
     Represents a call to the .setdefault() method.
@@ -236,3 +237,23 @@ class DictSetDefault(DictMethod):
         The value that should be returned if the key is not present in the dictionary.
         """
         return self._args[1]
+
+#==============================================================================
+class DictClear(DictMethod) :
+    """
+    Represents a call to the .clear() method.
+
+    The clear() method removes all items from the dictionary.
+
+    Parameters
+    ----------
+    dict_obj : TypedAstNode
+        The object from which the method is called.
+    """
+    __slots__ = ()
+    _shape = None
+    _class_type = VoidType()
+    name = 'clear'
+
+    def __init__(self, dict_obj):
+        super().__init__(dict_obj)
diff --git a/pyccel/ast/class_defs.py b/pyccel/ast/class_defs.py
index aafb30a7..090a6088 100644
--- a/pyccel/ast/class_defs.py
+++ b/pyccel/ast/class_defs.py
@@ -11,7 +11,7 @@ from pyccel.ast.builtin_methods.set_methods  import (SetAdd, SetClear, SetCopy,
 from pyccel.ast.builtin_methods.list_methods import (ListAppend, ListInsert, ListPop,
                                                      ListClear, ListExtend, ListRemove,
                                                      ListCopy, ListSort)
-from pyccel.ast.builtin_methods.dict_methods  import( DictPop, DictPopitem, DictGet,
+from pyccel.ast.builtin_methods.dict_methods import (DictPop, DictPopitem, DictGet, DictClear,
                                                      DictSetDefault)
 
 from .builtins   import PythonImag, PythonReal, PythonConjugate
@@ -175,6 +175,7 @@ SetClass = ClassDef('set',
 
 DictClass = ClassDef('dict',
         methods=[
+            PyccelFunctionDef('clear', func_class = DictClear),
             PyccelFunctionDef('get', func_class = DictGet),
             PyccelFunctionDef('pop', func_class = DictPop),
             PyccelFunctionDef('popitem', func_class = DictPopitem),


Test patch:
diff --git a/tests/epyccel/test_epyccel_dicts.py b/tests/epyccel/test_epyccel_dicts.py
index 74a87de8..4e2cd69c 100644
--- a/tests/epyccel/test_epyccel_dicts.py
+++ b/tests/epyccel/test_epyccel_dicts.py
@@ -217,3 +217,14 @@ def test_dict_ptr(python_only_language):
     python_result = dict_ptr()
     assert isinstance(python_result, type(pyccel_result))
     assert python_result == pyccel_result
+
+def test_dict_clear(python_only_language):
+    def dict_clear():
+        a = {1:1.0, 2:2.0}
+        a.clear()
+        return a
+    epyc_dict_clear = epyccel(dict_clear, language = python_only_language)
+    pyccel_result = epyc_dict_clear()
+    python_result = dict_clear()
+    assert python_result == pyccel_result
+