Skip to content

Commit 43ea678

Browse files
committed
Fix more warnings
1 parent 2fac506 commit 43ea678

File tree

11 files changed

+544
-189
lines changed

11 files changed

+544
-189
lines changed

Lib/test/test_warnings/__init__.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,6 @@ class CWarnTests(WarnTests, unittest.TestCase):
807807

808808
# As an early adopter, we sanity check the
809809
# test.import_helper.import_fresh_module utility function
810-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 'function' object has unexpected attribute '__code__'
811810
def test_accelerated(self):
812811
self.assertIsNot(original_warnings, self.module)
813812
self.assertNotHasAttr(self.module.warn, '__code__')
@@ -1012,7 +1011,6 @@ def test_showwarning_missing(self):
10121011
result = stream.getvalue()
10131012
self.assertIn(text, result)
10141013

1015-
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module 'warnings' has no attribute '_showwarnmsg'. Did you mean: 'showwarning'?
10161014
def test_showwarnmsg_missing(self):
10171015
# Test that _showwarnmsg() missing is okay.
10181016
text = 'del _showwarnmsg test'
@@ -1458,15 +1456,13 @@ class PyCatchWarningTests(CatchWarningTests, unittest.TestCase):
14581456

14591457
class EnvironmentVariableTests(BaseTest):
14601458

1461-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: b'[]' != b"['ignore::DeprecationWarning']"
14621459
def test_single_warning(self):
14631460
rc, stdout, stderr = assert_python_ok("-c",
14641461
"import sys; sys.stdout.write(str(sys.warnoptions))",
14651462
PYTHONWARNINGS="ignore::DeprecationWarning",
14661463
PYTHONDEVMODE="")
14671464
self.assertEqual(stdout, b"['ignore::DeprecationWarning']")
14681465

1469-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: b'[]' != b"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']"
14701466
def test_comma_separated_warnings(self):
14711467
rc, stdout, stderr = assert_python_ok("-c",
14721468
"import sys; sys.stdout.write(str(sys.warnoptions))",
@@ -1475,7 +1471,6 @@ def test_comma_separated_warnings(self):
14751471
self.assertEqual(stdout,
14761472
b"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']")
14771473

1478-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: b"['ignore::UnicodeWarning']" != b"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']"
14791474
@force_not_colorized
14801475
def test_envvar_and_command_line(self):
14811476
rc, stdout, stderr = assert_python_ok("-Wignore::UnicodeWarning", "-c",
@@ -1535,7 +1530,6 @@ def test_default_filter_configuration(self):
15351530
self.assertEqual(stdout_lines, expected_output)
15361531

15371532

1538-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: b'[]' != b"['ignore:DeprecationWarning\xc3\xa6']"
15391533
@unittest.skipUnless(sys.getfilesystemencoding() != 'ascii',
15401534
'requires non-ascii filesystemencoding')
15411535
def test_nonascii(self):
@@ -1851,7 +1845,6 @@ def h(x):
18511845
self.assertEqual(len(overloads), 2)
18521846
self.assertEqual(overloads[0].__deprecated__, "no more ints")
18531847

1854-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
18551848
def test_class(self):
18561849
@deprecated("A will go away soon")
18571850
class A:
@@ -1863,7 +1856,6 @@ class A:
18631856
with self.assertRaises(TypeError):
18641857
A(42)
18651858

1866-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
18671859
def test_class_with_init(self):
18681860
@deprecated("HasInit will go away soon")
18691861
class HasInit:
@@ -1874,7 +1866,6 @@ def __init__(self, x):
18741866
instance = HasInit(42)
18751867
self.assertEqual(instance.x, 42)
18761868

1877-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
18781869
def test_class_with_new(self):
18791870
has_new_called = False
18801871

@@ -1893,7 +1884,6 @@ def __init__(self, x) -> None:
18931884
self.assertEqual(instance.x, 42)
18941885
self.assertTrue(has_new_called)
18951886

1896-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
18971887
def test_class_with_inherited_new(self):
18981888
new_base_called = False
18991889

@@ -1915,7 +1905,6 @@ class HasInheritedNew(NewBase):
19151905
self.assertEqual(instance.x, 42)
19161906
self.assertTrue(new_base_called)
19171907

1918-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
19191908
def test_class_with_new_but_no_init(self):
19201909
new_called = False
19211910

@@ -1933,7 +1922,6 @@ def __new__(cls, x):
19331922
self.assertEqual(instance.x, 42)
19341923
self.assertTrue(new_called)
19351924

1936-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
19371925
def test_mixin_class(self):
19381926
@deprecated("Mixin will go away soon")
19391927
class Mixin:
@@ -1950,7 +1938,6 @@ class Child(Base, Mixin):
19501938
instance = Child(42)
19511939
self.assertEqual(instance.a, 42)
19521940

1953-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
19541941
def test_do_not_shadow_user_arguments(self):
19551942
new_called = False
19561943
new_called_cls = None
@@ -1970,7 +1957,6 @@ class Foo(metaclass=MyMeta, cls='haha'):
19701957
self.assertTrue(new_called)
19711958
self.assertEqual(new_called_cls, 'haha')
19721959

1973-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
19741960
def test_existing_init_subclass(self):
19751961
@deprecated("C will go away soon")
19761962
class C:
@@ -1987,7 +1973,6 @@ class D(C):
19871973
self.assertTrue(D.inited)
19881974
self.assertIsInstance(D(), D) # no deprecation
19891975

1990-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
19911976
def test_existing_init_subclass_in_base(self):
19921977
class Base:
19931978
def __init_subclass__(cls, x) -> None:
@@ -2008,7 +1993,6 @@ class D(C, x=3):
20081993

20091994
self.assertEqual(D.inited, 3)
20101995

2011-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
20121996
def test_existing_init_subclass_in_sibling_base(self):
20131997
@deprecated("A will go away soon")
20141998
class A:
@@ -2028,7 +2012,6 @@ class D(B, A, x=42):
20282012
pass
20292013
self.assertEqual(D.inited, 42)
20302014

2031-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
20322015
def test_init_subclass_has_correct_cls(self):
20332016
init_subclass_saw = None
20342017

@@ -2046,7 +2029,6 @@ class C(Base):
20462029

20472030
self.assertIs(init_subclass_saw, C)
20482031

2049-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
20502032
def test_init_subclass_with_explicit_classmethod(self):
20512033
init_subclass_saw = None
20522034

@@ -2065,7 +2047,6 @@ class C(Base):
20652047

20662048
self.assertIs(init_subclass_saw, C)
20672049

2068-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
20692050
def test_function(self):
20702051
@deprecated("b will go away soon")
20712052
def b():
@@ -2074,7 +2055,6 @@ def b():
20742055
with self.assertWarnsRegex(DeprecationWarning, "b will go away soon"):
20752056
b()
20762057

2077-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
20782058
def test_method(self):
20792059
class Capybara:
20802060
@deprecated("x will go away soon")
@@ -2085,7 +2065,6 @@ def x(self):
20852065
with self.assertWarnsRegex(DeprecationWarning, "x will go away soon"):
20862066
instance.x()
20872067

2088-
@unittest.expectedFailure # TODO: RUSTPYTHON; DeprecationWarning not triggered
20892068
def test_property(self):
20902069
class Capybara:
20912070
@property
@@ -2113,7 +2092,6 @@ def no_more_setting(self, value):
21132092
with self.assertWarnsRegex(DeprecationWarning, "no more setting"):
21142093
instance.no_more_setting = 42
21152094

2116-
@unittest.expectedFailure # TODO: RUSTPYTHON; RuntimeWarning not triggered
21172095
def test_category(self):
21182096
@deprecated("c will go away soon", category=RuntimeWarning)
21192097
def c():

crates/stdlib/src/_asyncio.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,12 @@ pub(crate) mod _asyncio {
10141014
// Warn about deprecated (type, val, tb) signature
10151015
if exc_val.is_present() || exc_tb.is_present() {
10161016
warn::warn(
1017-
vm.ctx.new_str(
1018-
"the (type, val, tb) signature of throw() is deprecated, \
1017+
vm.ctx
1018+
.new_str(
1019+
"the (type, val, tb) signature of throw() is deprecated, \
10191020
use throw(val) instead",
1020-
),
1021+
)
1022+
.into(),
10211023
Some(vm.ctx.exceptions.deprecation_warning.to_owned()),
10221024
1,
10231025
None,

crates/stdlib/src/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ mod _socket {
21442144
laddr
21452145
);
21462146
let _ = crate::vm::warn::warn(
2147-
vm.ctx.new_str(msg),
2147+
vm.ctx.new_str(msg).into(),
21482148
Some(vm.ctx.exceptions.resource_warning.to_owned()),
21492149
1,
21502150
None,

crates/vm/src/coroutine.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,12 @@ pub fn warn_deprecated_throw_signature(
300300
) -> PyResult<()> {
301301
if exc_val.is_present() || exc_tb.is_present() {
302302
crate::warn::warn(
303-
vm.ctx.new_str(
304-
"the (type, val, tb) signature of throw() is deprecated, \
303+
vm.ctx
304+
.new_str(
305+
"the (type, val, tb) signature of throw() is deprecated, \
305306
use throw(val) instead",
306-
),
307+
)
308+
.into(),
307309
Some(vm.ctx.exceptions.deprecation_warning.to_owned()),
308310
1,
309311
None,

crates/vm/src/frame.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,14 @@ impl Py<Frame> {
328328
}
329329

330330
pub fn next_external_frame(&self, vm: &VirtualMachine) -> Option<FrameRef> {
331-
self.f_back(vm).map(|mut back| {
332-
loop {
333-
back = if let Some(back) = back.to_owned().f_back(vm) {
334-
back
335-
} else {
336-
break back;
337-
};
338-
339-
if !back.is_internal_frame() {
340-
break back;
341-
}
331+
let mut frame = self.f_back(vm);
332+
while let Some(ref f) = frame {
333+
if !f.is_internal_frame() {
334+
break;
342335
}
343-
})
336+
frame = f.f_back(vm);
337+
}
338+
frame
344339
}
345340
}
346341

crates/vm/src/stdlib/ast/python.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ Support for arbitrary keyword arguments is deprecated and will be removed in Pyt
336336
key
337337
));
338338
warn::warn(
339-
message,
339+
message.into(),
340340
Some(vm.ctx.exceptions.deprecation_warning.to_owned()),
341341
1,
342342
None,
@@ -387,7 +387,7 @@ Support for arbitrary keyword arguments is deprecated and will be removed in Pyt
387387
field.as_str()
388388
));
389389
warn::warn(
390-
message,
390+
message.into(),
391391
Some(vm.ctx.exceptions.deprecation_warning.to_owned()),
392392
1,
393393
None,

crates/vm/src/stdlib/ast/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn warn_invalid_escape_sequences_in_format_spec(
224224
"\"\\{next}\" is an invalid escape sequence. Such sequences will not work in the future. Did you mean \"\\\\{next}\"? A raw string is also an option."
225225
));
226226
let _ = warn::warn(
227-
message,
227+
message.into(),
228228
Some(vm.ctx.exceptions.syntax_warning.to_owned()),
229229
1,
230230
None,

0 commit comments

Comments
 (0)