Skip to content

Commit f99bacf

Browse files
authored
Merge branch 'RustPython:main' into main
2 parents 1aa28a6 + 4841776 commit f99bacf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4037
-1135
lines changed

Cargo.lock

Lines changed: 373 additions & 300 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ruff_source_file = { git = "https://github.com/astral-sh/ruff.git", tag = "0.11.
165165

166166
ahash = "0.8.11"
167167
ascii = "1.1"
168-
bitflags = "2.4.2"
168+
bitflags = "2.9.1"
169169
bstr = "1"
170170
cfg-if = "1.0"
171171
chrono = "0.4.39"
@@ -176,7 +176,7 @@ flame = "0.2.2"
176176
getrandom = { version = "0.3", features = ["std"] }
177177
glob = "0.3"
178178
hex = "0.4.3"
179-
indexmap = { version = "2.2.6", features = ["std"] }
179+
indexmap = { version = "2.10.0", features = ["std"] }
180180
insta = "1.42"
181181
itertools = "0.14.0"
182182
is-macro = "0.3.7"
@@ -222,7 +222,7 @@ unic-ucd-category = "0.9.0"
222222
unic-ucd-ident = "0.9.0"
223223
unicode_names2 = "1.3.0"
224224
unicode-bidi-mirroring = "0.2"
225-
widestring = "1.1.0"
225+
widestring = "1.2.0"
226226
windows-sys = "0.59.0"
227227
wasm-bindgen = "0.2.100"
228228

Lib/bz2.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from _bz2 import BZ2Compressor, BZ2Decompressor
1818

1919

20-
_MODE_CLOSED = 0
20+
# Value 0 no longer used
2121
_MODE_READ = 1
2222
# Value 2 no longer used
2323
_MODE_WRITE = 3
@@ -54,7 +54,7 @@ def __init__(self, filename, mode="r", *, compresslevel=9):
5454
"""
5555
self._fp = None
5656
self._closefp = False
57-
self._mode = _MODE_CLOSED
57+
self._mode = None
5858

5959
if not (1 <= compresslevel <= 9):
6060
raise ValueError("compresslevel must be between 1 and 9")
@@ -100,7 +100,7 @@ def close(self):
100100
May be called more than once without error. Once the file is
101101
closed, any other operation on it will raise a ValueError.
102102
"""
103-
if self._mode == _MODE_CLOSED:
103+
if self.closed:
104104
return
105105
try:
106106
if self._mode == _MODE_READ:
@@ -115,13 +115,21 @@ def close(self):
115115
finally:
116116
self._fp = None
117117
self._closefp = False
118-
self._mode = _MODE_CLOSED
119118
self._buffer = None
120119

121120
@property
122121
def closed(self):
123122
"""True if this file is closed."""
124-
return self._mode == _MODE_CLOSED
123+
return self._fp is None
124+
125+
@property
126+
def name(self):
127+
self._check_not_closed()
128+
return self._fp.name
129+
130+
@property
131+
def mode(self):
132+
return 'wb' if self._mode == _MODE_WRITE else 'rb'
125133

126134
def fileno(self):
127135
"""Return the file descriptor for the underlying file."""

Lib/contextlib.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class AbstractContextManager(abc.ABC):
2020

2121
__class_getitem__ = classmethod(GenericAlias)
2222

23+
__slots__ = ()
24+
2325
def __enter__(self):
2426
"""Return `self` upon entering the runtime context."""
2527
return self
@@ -42,6 +44,8 @@ class AbstractAsyncContextManager(abc.ABC):
4244

4345
__class_getitem__ = classmethod(GenericAlias)
4446

47+
__slots__ = ()
48+
4549
async def __aenter__(self):
4650
"""Return `self` upon entering the runtime context."""
4751
return self
@@ -565,11 +569,12 @@ def __enter__(self):
565569
return self
566570

567571
def __exit__(self, *exc_details):
568-
received_exc = exc_details[0] is not None
572+
exc = exc_details[1]
573+
received_exc = exc is not None
569574

570575
# We manipulate the exception state so it behaves as though
571576
# we were actually nesting multiple with statements
572-
frame_exc = sys.exc_info()[1]
577+
frame_exc = sys.exception()
573578
def _fix_exception_context(new_exc, old_exc):
574579
# Context may not be correct, so find the end of the chain
575580
while 1:
@@ -592,24 +597,28 @@ def _fix_exception_context(new_exc, old_exc):
592597
is_sync, cb = self._exit_callbacks.pop()
593598
assert is_sync
594599
try:
600+
if exc is None:
601+
exc_details = None, None, None
602+
else:
603+
exc_details = type(exc), exc, exc.__traceback__
595604
if cb(*exc_details):
596605
suppressed_exc = True
597606
pending_raise = False
598-
exc_details = (None, None, None)
599-
except:
600-
new_exc_details = sys.exc_info()
607+
exc = None
608+
except BaseException as new_exc:
601609
# simulate the stack of exceptions by setting the context
602-
_fix_exception_context(new_exc_details[1], exc_details[1])
610+
_fix_exception_context(new_exc, exc)
603611
pending_raise = True
604-
exc_details = new_exc_details
612+
exc = new_exc
613+
605614
if pending_raise:
606615
try:
607-
# bare "raise exc_details[1]" replaces our carefully
616+
# bare "raise exc" replaces our carefully
608617
# set-up context
609-
fixed_ctx = exc_details[1].__context__
610-
raise exc_details[1]
618+
fixed_ctx = exc.__context__
619+
raise exc
611620
except BaseException:
612-
exc_details[1].__context__ = fixed_ctx
621+
exc.__context__ = fixed_ctx
613622
raise
614623
return received_exc and suppressed_exc
615624

@@ -705,11 +714,12 @@ async def __aenter__(self):
705714
return self
706715

707716
async def __aexit__(self, *exc_details):
708-
received_exc = exc_details[0] is not None
717+
exc = exc_details[1]
718+
received_exc = exc is not None
709719

710720
# We manipulate the exception state so it behaves as though
711721
# we were actually nesting multiple with statements
712-
frame_exc = sys.exc_info()[1]
722+
frame_exc = sys.exception()
713723
def _fix_exception_context(new_exc, old_exc):
714724
# Context may not be correct, so find the end of the chain
715725
while 1:
@@ -731,6 +741,10 @@ def _fix_exception_context(new_exc, old_exc):
731741
while self._exit_callbacks:
732742
is_sync, cb = self._exit_callbacks.pop()
733743
try:
744+
if exc is None:
745+
exc_details = None, None, None
746+
else:
747+
exc_details = type(exc), exc, exc.__traceback__
734748
if is_sync:
735749
cb_suppress = cb(*exc_details)
736750
else:
@@ -739,21 +753,21 @@ def _fix_exception_context(new_exc, old_exc):
739753
if cb_suppress:
740754
suppressed_exc = True
741755
pending_raise = False
742-
exc_details = (None, None, None)
743-
except:
744-
new_exc_details = sys.exc_info()
756+
exc = None
757+
except BaseException as new_exc:
745758
# simulate the stack of exceptions by setting the context
746-
_fix_exception_context(new_exc_details[1], exc_details[1])
759+
_fix_exception_context(new_exc, exc)
747760
pending_raise = True
748-
exc_details = new_exc_details
761+
exc = new_exc
762+
749763
if pending_raise:
750764
try:
751-
# bare "raise exc_details[1]" replaces our carefully
765+
# bare "raise exc" replaces our carefully
752766
# set-up context
753-
fixed_ctx = exc_details[1].__context__
754-
raise exc_details[1]
767+
fixed_ctx = exc.__context__
768+
raise exc
755769
except BaseException:
756-
exc_details[1].__context__ = fixed_ctx
770+
exc.__context__ = fixed_ctx
757771
raise
758772
return received_exc and suppressed_exc
759773

Lib/lzma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__(self, filename=None, mode="r", *,
128128

129129
if self._mode == _MODE_READ:
130130
raw = _compression.DecompressReader(self._fp, LZMADecompressor,
131-
trailing_error=LZMAError, format=format, filters=filters)
131+
trailing_error=LZMAError, format=format, filters=filters)
132132
self._buffer = io.BufferedReader(raw)
133133

134134
def close(self):

0 commit comments

Comments
 (0)