Repository: RustPython/RustPython (language: rust)

Issue:
Add `co_freevars` to code object
Opening this separately from #1838 since it also seems like a good first issue.

Currently, code objects are missing the `co_freevars` attribute:

```python
def foo(a, b):
    def bar(c, d):
        print(a, b, c, d)
```

In RustPython:

```python
>>>>> foo.__code__.co_freevars
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'code' object has no attribute 'co_freevars'
```

While in Python:

```python
>>> foo.__code__.co_freevars
('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..97c32dbe07 100644
--- a/vm/src/builtins/code.rs
+++ b/vm/src/builtins/code.rs
@@ -262,6 +262,18 @@ impl PyRef<PyCode> {
         vm.ctx.new_tuple(varnames)
     }
 
+    #[pygetset]
+    pub fn co_freevars(self, vm: &VirtualMachine) -> PyTupleRef {
+        let names = self
+            .code
+            .freevars
+            .deref()
+            .iter()
+            .map(|name| name.to_pyobject(vm))
+            .collect();
+        vm.ctx.new_tuple(names)
+    }
+
     #[pymethod]
     pub fn replace(self, args: ReplaceArgs, vm: &VirtualMachine) -> PyResult<PyCode> {
         let posonlyarg_count = match args.co_posonlyargcount {


Test patch: