Repository: pyccel/pyccel (python)

Issue:
[DICT] Add Python support for copy
### Describe the feature
Syntactic and semantic support should be added for `copy`. 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}
    b = a.copy()
    return b
```

Pull request description:
Add Python support for dict.copy
Changes made to the files `dict_methods.py`, `class_defs.py`, `test_epyccel_dicts.py`, and `builtin-functions.md` to add Python support for `dict.copy`. Fixes #1881

Patch:
diff --git a/AUTHORS b/AUTHORS
index ebd23a77..18f3dc09 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -37,4 +37,5 @@ Contributors
 * Emmmanuel Ferdman
 * Mohammed Ayaz Shaikh
 * Amir Movassaghi
-* Leonardo Merlin Paloschi
\ No newline at end of file
+* Leonardo Merlin Paloschi
+* Joao Antonio Gomes
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8a52b3fc..5d814e78 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,8 +4,8 @@ All notable changes to this project will be documented in this file.
 ## \[UNRELEASED\]
 
 ### Added
-
--   #1880 : Add Python support for dict method `clear()`
+-   #1881 : Add Python support for dict method `copy()`.
+-   #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 8efc5e8a..ee0c9ca2 100644
--- a/docs/builtin-functions.md
+++ b/docs/builtin-functions.md
@@ -121,7 +121,7 @@ Python contains a limited number of builtin functions defined [here](https://doc
 | Method | Supported |
 |----------|-----------|
 | `clear` | Python-only |
-| `copy` | No |
+| `copy` | Python-only |
 | `get` | Python-only |
 | `items` | No |
 | `keys` | No |
diff --git a/pyccel/ast/builtin_methods/dict_methods.py b/pyccel/ast/builtin_methods/dict_methods.py
index 362f0bdf..4af7c271 100644
--- a/pyccel/ast/builtin_methods/dict_methods.py
+++ b/pyccel/ast/builtin_methods/dict_methods.py
@@ -15,6 +15,7 @@ from pyccel.ast.internals import PyccelFunction
 
 
 __all__ = ('DictClear',
+           'DictCopy',
            'DictGet',
            'DictMethod',
            'DictPop',
@@ -257,3 +258,25 @@ class DictClear(DictMethod) :
 
     def __init__(self, dict_obj):
         super().__init__(dict_obj)
+
+#==============================================================================
+
+class DictCopy(DictMethod):
+    """
+    Represents a call to the .copy() method.
+
+    The copy() method returns a shallow copy of the dictionary.
+
+    Parameters
+    ----------
+    dict_obj : TypedAstNode
+        The object from which the method is called.
+    """
+    __slots__ = ('_class_type',)
+    _shape = None
+    name = 'copy'
+
+    def __init__(self, dict_obj):
+        dict_type = dict_obj.class_type
+        self._class_type = dict_type
+        super().__init__(dict_obj)
diff --git a/pyccel/ast/class_defs.py b/pyccel/ast/class_defs.py
index 090a6088..a1997888 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, DictClear,
+from pyccel.ast.builtin_methods.dict_methods import (DictPop, DictPopitem, DictGet, DictClear,DictCopy,
                                                      DictSetDefault)
 
 from .builtins   import PythonImag, PythonReal, PythonConjugate
@@ -175,6 +175,7 @@ SetClass = ClassDef('set',
 
 DictClass = ClassDef('dict',
         methods=[
+            PyccelFunctionDef('copy', func_class = DictCopy),
             PyccelFunctionDef('clear', func_class = DictClear),
             PyccelFunctionDef('get', func_class = DictGet),
             PyccelFunctionDef('pop', func_class = DictPop),


Test patch:
diff --git a/tests/epyccel/test_epyccel_dicts.py b/tests/epyccel/test_epyccel_dicts.py
index 4e2cd69c..5f9d860a 100644
--- a/tests/epyccel/test_epyccel_dicts.py
+++ b/tests/epyccel/test_epyccel_dicts.py
@@ -58,6 +58,7 @@ def test_dict_copy(python_only_language):
     assert isinstance(python_result, type(pyccel_result))
     assert python_result == pyccel_result
 
+
 def test_dict_kwarg_init(python_only_language):
     def kwarg_init():
         b = dict(a=1, b=2) #pylint: disable=use-dict-literal
@@ -228,3 +229,14 @@ def test_dict_clear(python_only_language):
     python_result = dict_clear()
     assert python_result == pyccel_result
 
+
+def test_dict_copy_method(python_only_language):
+    def dict_copy():
+        a = {1:1.0, 2:2.0}
+        b = a.copy()
+        return b
+    epyc_dict_copy = epyccel(dict_copy, language = python_only_language)
+    pyccel_result = epyc_dict_copy()
+    python_result = dict_copy()
+    assert python_result == pyccel_result
+    
\ No newline at end of file