GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix PyCode constructor/replace by youknowone · Pull Request #6193 · RustPython/RustPython

Fix PyCode constructor/replace #6193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
youknowone merged 2 commits into RustPython:main from youknowone:code
Oct 22, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fix PyCode constructor/replace #6193

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
f2e19bd
Fix PyCode constructor
youknowone Oct 16, 2025
2166a05
Reuse MarshalError
youknowone Oct 22, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

6 changes: 0 additions & 6 deletions 6 Lib/test/test_code.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ class List(list):
obj = List([1, 2, 3])
self.assertEqual(obj[0], "Foreign getitem: 1")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_constructor(self):
def func(): pass
co = func.__code__
Expand Down Expand Up @@ -255,8 +253,6 @@ def test_qualname(self):
CodeTest.test_qualname.__qualname__
)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_replace(self):
def func():
x = 1
Expand Down Expand Up @@ -297,8 +293,6 @@ def func2():
self.assertEqual(new_code.co_varnames, code2.co_varnames)
self.assertEqual(new_code.co_nlocals, code2.co_nlocals)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_nlocals_mismatch(self):
def func():
x = 1
Expand Down
2 changes: 0 additions & 2 deletions 2 Lib/test/test_funcattrs.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def duplicate():
return 3
self.assertNotEqual(self.b, duplicate)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_copying___code__(self):
def test(): pass
self.assertEqual(test(), None)
Expand Down
22 changes: 14 additions & 8 deletions 22 compiler/core/src/marshal.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ impl<'a> ReadBorrowed<'a> for &'a [u8] {
}
}

/// Parses bytecode bytes into CodeUnit instructions.
/// Each instruction is 2 bytes: opcode and argument.
pub fn parse_instructions_from_bytes(bytes: &[u8]) -> Result<Box<[CodeUnit]>> {
bytes
.chunks_exact(2)
.map(|cu| {
let op = Instruction::try_from(cu[0])?;
let arg = OpArgByte(cu[1]);
Ok(CodeUnit { op, arg })
})
.collect()
}

pub struct Cursor<B> {
pub data: B,
pub position: usize,
Expand All @@ -185,14 +198,7 @@ pub fn deserialize_code<R: Read, Bag: ConstantBag>(
) -> Result<CodeObject<Bag::Constant>> {
let len = rdr.read_u32()?;
let instructions = rdr.read_slice(len * 2)?;
let instructions = instructions
.chunks_exact(2)
.map(|cu| {
let op = Instruction::try_from(cu[0])?;
let arg = OpArgByte(cu[1]);
Ok(CodeUnit { op, arg })
})
.collect::<Result<Box<[CodeUnit]>>>()?;
let instructions = parse_instructions_from_bytes(instructions)?;

let len = rdr.read_u32()?;
let locations = (0..len)
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.