Skip to content

[pull] main from RustPython:main #777

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.

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
merged 7 commits into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
673 changes: 373 additions & 300 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ruff_source_file = { git = "https://github.com/astral-sh/ruff.git", tag = "0.11.

ahash = "0.8.11"
ascii = "1.1"
bitflags = "2.4.2"
bitflags = "2.9.1"
bstr = "1"
cfg-if = "1.0"
chrono = "0.4.39"
Expand All @@ -176,7 +176,7 @@ flame = "0.2.2"
getrandom = { version = "0.3", features = ["std"] }
glob = "0.3"
hex = "0.4.3"
indexmap = { version = "2.2.6", features = ["std"] }
indexmap = { version = "2.10.0", features = ["std"] }
insta = "1.42"
itertools = "0.14.0"
is-macro = "0.3.7"
Expand Down Expand Up @@ -222,7 +222,7 @@ unic-ucd-category = "0.9.0"
unic-ucd-ident = "0.9.0"
unicode_names2 = "1.3.0"
unicode-bidi-mirroring = "0.2"
widestring = "1.1.0"
widestring = "1.2.0"
windows-sys = "0.59.0"
wasm-bindgen = "0.2.100"

Expand Down
18 changes: 13 additions & 5 deletions Lib/bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from _bz2 import BZ2Compressor, BZ2Decompressor


_MODE_CLOSED = 0
# Value 0 no longer used
_MODE_READ = 1
# Value 2 no longer used
_MODE_WRITE = 3
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self, filename, mode="r", *, compresslevel=9):
"""
self._fp = None
self._closefp = False
self._mode = _MODE_CLOSED
self._mode = None

if not (1 <= compresslevel <= 9):
raise ValueError("compresslevel must be between 1 and 9")
Expand Down Expand Up @@ -100,7 +100,7 @@ def close(self):
May be called more than once without error. Once the file is
closed, any other operation on it will raise a ValueError.
"""
if self._mode == _MODE_CLOSED:
if self.closed:
return
try:
if self._mode == _MODE_READ:
Expand All @@ -115,13 +115,21 @@ def close(self):
finally:
self._fp = None
self._closefp = False
self._mode = _MODE_CLOSED
self._buffer = None

@property
def closed(self):
"""True if this file is closed."""
return self._mode == _MODE_CLOSED
return self._fp is None

@property
def name(self):
self._check_not_closed()
return self._fp.name

@property
def mode(self):
return 'wb' if self._mode == _MODE_WRITE else 'rb'

def fileno(self):
"""Return the file descriptor for the underlying file."""
Expand Down
58 changes: 36 additions & 22 deletions Lib/contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class AbstractContextManager(abc.ABC):

__class_getitem__ = classmethod(GenericAlias)

__slots__ = ()

def __enter__(self):
"""Return `self` upon entering the runtime context."""
return self
Expand All @@ -42,6 +44,8 @@ class AbstractAsyncContextManager(abc.ABC):

__class_getitem__ = classmethod(GenericAlias)

__slots__ = ()

async def __aenter__(self):
"""Return `self` upon entering the runtime context."""
return self
Expand Down Expand Up @@ -565,11 +569,12 @@ def __enter__(self):
return self

def __exit__(self, *exc_details):
received_exc = exc_details[0] is not None
exc = exc_details[1]
received_exc = exc is not None

# We manipulate the exception state so it behaves as though
# we were actually nesting multiple with statements
frame_exc = sys.exc_info()[1]
frame_exc = sys.exception()
def _fix_exception_context(new_exc, old_exc):
# Context may not be correct, so find the end of the chain
while 1:
Expand All @@ -592,24 +597,28 @@ def _fix_exception_context(new_exc, old_exc):
is_sync, cb = self._exit_callbacks.pop()
assert is_sync
try:
if exc is None:
exc_details = None, None, None
else:
exc_details = type(exc), exc, exc.__traceback__
if cb(*exc_details):
suppressed_exc = True
pending_raise = False
exc_details = (None, None, None)
except:
new_exc_details = sys.exc_info()
exc = None
except BaseException as new_exc:
# simulate the stack of exceptions by setting the context
_fix_exception_context(new_exc_details[1], exc_details[1])
_fix_exception_context(new_exc, exc)
pending_raise = True
exc_details = new_exc_details
exc = new_exc

if pending_raise:
try:
# bare "raise exc_details[1]" replaces our carefully
# bare "raise exc" replaces our carefully
# set-up context
fixed_ctx = exc_details[1].__context__
raise exc_details[1]
fixed_ctx = exc.__context__
raise exc
except BaseException:
exc_details[1].__context__ = fixed_ctx
exc.__context__ = fixed_ctx
raise
return received_exc and suppressed_exc

Expand Down Expand Up @@ -705,11 +714,12 @@ async def __aenter__(self):
return self

async def __aexit__(self, *exc_details):
received_exc = exc_details[0] is not None
exc = exc_details[1]
received_exc = exc is not None

# We manipulate the exception state so it behaves as though
# we were actually nesting multiple with statements
frame_exc = sys.exc_info()[1]
frame_exc = sys.exception()
def _fix_exception_context(new_exc, old_exc):
# Context may not be correct, so find the end of the chain
while 1:
Expand All @@ -731,6 +741,10 @@ def _fix_exception_context(new_exc, old_exc):
while self._exit_callbacks:
is_sync, cb = self._exit_callbacks.pop()
try:
if exc is None:
exc_details = None, None, None
else:
exc_details = type(exc), exc, exc.__traceback__
if is_sync:
cb_suppress = cb(*exc_details)
else:
Expand All @@ -739,21 +753,21 @@ def _fix_exception_context(new_exc, old_exc):
if cb_suppress:
suppressed_exc = True
pending_raise = False
exc_details = (None, None, None)
except:
new_exc_details = sys.exc_info()
exc = None
except BaseException as new_exc:
# simulate the stack of exceptions by setting the context
_fix_exception_context(new_exc_details[1], exc_details[1])
_fix_exception_context(new_exc, exc)
pending_raise = True
exc_details = new_exc_details
exc = new_exc

if pending_raise:
try:
# bare "raise exc_details[1]" replaces our carefully
# bare "raise exc" replaces our carefully
# set-up context
fixed_ctx = exc_details[1].__context__
raise exc_details[1]
fixed_ctx = exc.__context__
raise exc
except BaseException:
exc_details[1].__context__ = fixed_ctx
exc.__context__ = fixed_ctx
raise
return received_exc and suppressed_exc

Expand Down
2 changes: 1 addition & 1 deletion Lib/lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self, filename=None, mode="r", *,

if self._mode == _MODE_READ:
raw = _compression.DecompressReader(self._fp, LZMADecompressor,
trailing_error=LZMAError, format=format, filters=filters)
trailing_error=LZMAError, format=format, filters=filters)
self._buffer = io.BufferedReader(raw)

def close(self):
Expand Down
Loading