Repository: RustPython/RustPython (language: rust)

Issue:
Add `co_cellvars` to code object
Opening this separately from #1838 since it seems like a good first issue.

Currently, code objects are missing the `co_cellvars` attribute:

```python
def foo(a, b):
    def bar(c, d):
        print(a, b, c, d)
```

In RustPython:

```python
>>>>> foo.__code__.co_cellvars
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'code' object has no attribute 'co_cellvars'
```

While in Python:

```python
>>> foo.__code__.co_cellvars
('a', 'b')
```

looking at the other methods on [`PyCode`](https://github.com/RustPython/RustPython/blob/1fd557d549cd72e7da83608b99e5464273abd4b3/vm/src/builtins/code.rs#L188) should help, the implementation should be similar to others there that return a tuple.


Discussion / hints:

Fix patch:
diff --git a/vm/src/builtins/code.rs b/vm/src/builtins/code.rs
index 24cb970077..6e4c71e12f 100644
--- a/vm/src/builtins/code.rs
+++ b/vm/src/builtins/code.rs
@@ -218,6 +218,18 @@ impl PyRef<PyCode> {
         self.code.source_path.to_owned()
     }
 
+    #[pygetset]
+    pub fn co_cellvars(self, vm: &VirtualMachine) -> PyTupleRef {
+        let cellvars = self
+            .code
+            .cellvars
+            .deref()
+            .iter()
+            .map(|name| name.to_pyobject(vm))
+            .collect();
+        vm.ctx.new_tuple(cellvars)
+    }
+
     #[pygetset]
     fn co_firstlineno(self) -> usize {
         self.code.first_line_number


Test patch: