Repository: RustPython/RustPython (language: rust)

Issue:
Add `co_nlocals` 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, c): pass
```

In RustPython:

```python
>>>>> foo.__code__.co_nlocals
AttributeError: 'code' object has no attribute 'co_nlocals'
```

While in Python:

```python
>>> foo.__code__.co_nlocals
3
```

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. 

As the linked issue states, this does indeed appear to be `len(self.varnames)` (see [this invariant](https://github.com/python/cpython/blob/3ba7743b0696202e9caa283a0be253fd26a5cfbd/Objects/codeobject.c#L676) in the CPython source)



Discussion / hints:

Fix patch:
diff --git a/vm/src/builtins/code.rs b/vm/src/builtins/code.rs
index 19d586bd0d..2258af473f 100644
--- a/vm/src/builtins/code.rs
+++ b/vm/src/builtins/code.rs
@@ -230,6 +230,11 @@ impl PyRef<PyCode> {
         vm.ctx.new_tuple(cellvars)
     }
 
+    #[pygetset]
+    fn co_nlocals(self) -> usize {
+        self.varnames.len()
+    }
+
     #[pygetset]
     fn co_firstlineno(self) -> usize {
         self.code.first_line_number


Test patch: