Repository: RustPython/RustPython (language: rust)

Issue:
Add `co_stacksize` to code objects.
Opening this separately from #1838 since it also seems like a good first issue.

Currently, code objects are missing the `co_stacksize` attribute:

```python
def foo(a, b): pass
```

In RustPython:

```python
>>>>> foo.__code__.co_stacksize
AttributeError: 'code' object has no attribute 'co_stacksize'
```

While in Python:

```python
>>> foo.__code__.co_stacksize
1
```

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 those (also related #4502 #4501)



Discussion / hints:

Fix patch:
diff --git a/vm/src/builtins/code.rs b/vm/src/builtins/code.rs
index 19d586bd0d..3c937593fc 100644
--- a/vm/src/builtins/code.rs
+++ b/vm/src/builtins/code.rs
@@ -213,6 +213,11 @@ impl PyRef<PyCode> {
         self.code.arg_count
     }
 
+    #[pygetset]
+    fn co_stacksize(self) -> u32 {
+        self.code.max_stackdepth
+    }
+
     #[pygetset]
     pub fn co_filename(self) -> PyStrRef {
         self.code.source_path.to_owned()


Test patch:
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index fb3cbb8b76..b3ef7993c6 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -851,8 +851,6 @@ def compile_snippet(i):
             self.fail("stack sizes diverge with # of consecutive snippets: "
                       "%s\n%s\n%s" % (sizes, snippet, out.getvalue()))
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_if(self):
         snippet = """
             if x:
@@ -860,8 +858,6 @@ def test_if(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_if_else(self):
         snippet = """
             if x:
@@ -873,8 +869,6 @@ def test_if_else(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_try_except_bare(self):
         snippet = """
             try:
@@ -884,8 +878,6 @@ def test_try_except_bare(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_try_except_qualified(self):
         snippet = """
             try:
@@ -899,8 +891,6 @@ def test_try_except_qualified(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_try_except_as(self):
         snippet = """
             try:
@@ -914,8 +904,6 @@ def test_try_except_as(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_try_finally(self):
         snippet = """
                 try:
@@ -925,8 +913,6 @@ def test_try_finally(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_with(self):
         snippet = """
             with x as y:
@@ -934,8 +920,6 @@ def test_with(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_while_else(self):
         snippet = """
             while x:
@@ -945,8 +929,6 @@ def test_while_else(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for(self):
         snippet = """
             for x in y:
@@ -954,8 +936,6 @@ def test_for(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for_else(self):
         snippet = """
             for x in y:
@@ -965,8 +945,6 @@ def test_for_else(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for_break_continue(self):
         snippet = """
             for x in y:
@@ -981,8 +959,6 @@ def test_for_break_continue(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for_break_continue_inside_try_finally_block(self):
         snippet = """
             for x in y:
@@ -1000,8 +976,6 @@ def test_for_break_continue_inside_try_finally_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for_break_continue_inside_finally_block(self):
         snippet = """
             for x in y:
@@ -1019,8 +993,6 @@ def test_for_break_continue_inside_finally_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for_break_continue_inside_except_block(self):
         snippet = """
             for x in y:
@@ -1038,8 +1010,6 @@ def test_for_break_continue_inside_except_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for_break_continue_inside_with_block(self):
         snippet = """
             for x in y:
@@ -1055,8 +1025,6 @@ def test_for_break_continue_inside_with_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_return_inside_try_finally_block(self):
         snippet = """
             try:
@@ -1069,8 +1037,6 @@ def test_return_inside_try_finally_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_return_inside_finally_block(self):
         snippet = """
             try:
@@ -1083,8 +1049,6 @@ def test_return_inside_finally_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_return_inside_except_block(self):
         snippet = """
             try:
@@ -1097,8 +1061,6 @@ def test_return_inside_except_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_return_inside_with_block(self):
         snippet = """
             with c:
@@ -1109,8 +1071,6 @@ def test_return_inside_with_block(self):
             """
         self.check_stack_size(snippet)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_async_with(self):
         snippet = """
             async with x as y:
@@ -1118,8 +1078,6 @@ def test_async_with(self):
             """
         self.check_stack_size(snippet, async_=True)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_async_for(self):
         snippet = """
             async for x in y:
@@ -1127,8 +1085,6 @@ def test_async_for(self):
             """
         self.check_stack_size(snippet, async_=True)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_async_for_else(self):
         snippet = """
             async for x in y:
@@ -1138,8 +1094,6 @@ def test_async_for_else(self):
             """
         self.check_stack_size(snippet, async_=True)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_for_break_continue_inside_async_with_block(self):
         snippet = """
             for x in y:
@@ -1155,8 +1109,6 @@ def test_for_break_continue_inside_async_with_block(self):
             """
         self.check_stack_size(snippet, async_=True)
 
-    # TODO: RUSTPYTHON
-    @unittest.expectedFailure
     def test_return_inside_async_with_block(self):
         snippet = """
             async with c: