8000 Merge branch 'main' into complex_format · RustPython/RustPython@ecc7ae4 · GitHub
[go: up one dir, main page]

Skip to content

Commit ecc7ae4

Browse files
committed
Merge branch 'main' into complex_format
2 parents fc47ac8 + 5b20bb8 commit ecc7ae4

File tree

130 files changed

+1543
-3107
lines changed

Some content is hidden

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

130 files changed

+1543
-3107
lines changed

Lib/test/test_resource.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import sys
33
import unittest
44
from test import support
5-
from test.support import os_helper, import_helper
5+
from test.support import import_helper
6+
from test.support import os_helper
67
import time
78

89
resource = import_helper.import_module('resource')
@@ -99,6 +100,7 @@ def test_fsize_toobig(self):
99100
except (OverflowError, ValueError):
100101
pass
101102

103+
@unittest.skipUnless(hasattr(resource, "getrusage"), "needs getrusage")
102104
def test_getrusage(self):
103105
self.assertRaises(TypeError, resource.getrusage)
104106
self.assertRaises(TypeError, resource.getrusage, 42, 42)
@@ -140,7 +142,7 @@ def test_pagesize(self):
140142
self.assertIsInstance(pagesize, int)
141143
self.assertGreaterEqual(pagesize, 0)
142144

143-
@unittest.skipUnless(sys.platform == 'linux', 'test requires Linux')
145+
@unittest.skipUnless(sys.platform in ('linux', 'android'), 'Linux only')
144146
def test_linux_constants(self):
145147
for attr in ['MSGQUEUE', 'NICE', 'RTPRIO', 'RTTIME', 'SIGPENDING']:
146148
with contextlib.suppress(AttributeError):
@@ -177,8 +179,5 @@ def __getitem__(self, key):
177179
limits)
178180

179181

180-
def test_main(verbose=None):
181-
support.run_unittest(ResourceTest)
182-
183182
if __name__ == "__main__":
184-
test_main()
183+
unittest.main()

common/src/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<T> Default for OncePtr<T> {
6565
impl<T> OncePtr<T> {
6666
#[inline]
6767
pub fn new() -> Self {
68-
OncePtr {
68+
Self {
6969
inner: Radium::new(ptr::null_mut()),
7070
}
7171
}

common/src/boxvec.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ macro_rules! panic_oob {
3838
}
3939

4040
impl<T> BoxVec<T> {
41-
pub fn new(n: usize) -> BoxVec<T> {
42-
BoxVec {
41+
pub fn new(n: usize) -> Self {
42+
Self {
4343
xs: Box::new_uninit_slice(n),
4444
len: 0,
4545
}
@@ -593,7 +593,7 @@ where
593593
T: Clone,
594594
{
595595
fn clone(&self) -> Self {
596-
let mut new = BoxVec::new(self.capacity());
596+
let mut new = Self::new(self.capacity());
597597
new.extend(self.iter().cloned());
598598
new
599599
}
@@ -676,8 +676,8 @@ pub struct CapacityError<T = ()> {
676676

677677
impl<T> CapacityError<T> {
678678
/// Create a new `CapacityError` from `element`.
679-
pub const fn new(element: T) -> CapacityError<T> {
680-
CapacityError { element }
679+
pub const fn new(element: T) -> Self {
680+
Self { element }
681681
}
682682

683683
/// Extract the overflowing element

common/src/cformat.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ pub enum CFormatType {
103103
impl CFormatType {
104104
pub const fn to_char(self) -> char {
105105
match self {
106-
CFormatType::Number(x) => x as u8 as char,
107-
CFormatType::Float(x) => x as u8 as char,
108-
CFormatType::Character(x) => x as u8 as char,
109-
CFormatType::String(x) => x as u8 as char,
106+
Self::Number(x) => x as u8 as char,
107+
Self::Float(x) => x as u8 as char,
108+
Self::Character(x) => x as u8 as char,
109+
Self::String(x) => x as u8 as char,
110110
}
111111
}
112112
}
@@ -119,7 +119,7 @@ pub enum CFormatPrecision {
119119

120120
impl From<CFormatQuantity> for CFormatPrecision {
121121
fn from(quantity: CFormatQuantity) -> Self {
122-
CFormatPrecision::Quantity(quantity)
122+
Self::Quantity(quantity)
123123
}
124124
}
125125

@@ -338,7 +338,7 @@ impl CFormatSpec {
338338
_ => &num_chars,
339339
};
340340
let fill_chars_needed = width.saturating_sub(num_chars);
341-
let fill_string: T = CFormatSpec::compute_fill_string(fill_char, fill_chars_needed);
341+
let fill_string: T = Self::compute_fill_string(fill_char, fill_chars_needed);
342342

343343
if !fill_string.is_empty() {
344344
if self.flags.contains(CConversionFlags::LEFT_ADJUST) {
@@ -361,7 +361,7 @@ impl CFormatSpec {
361361
_ => &num_chars,
362362
};
363363
let fill_chars_needed = width.saturating_sub(num_chars);
364-
let fill_string: T = CFormatSpec::compute_fill_string(fill_char, fill_chars_needed);
364+
let fill_string: T = Self::compute_fill_string(fill_char, fill_chars_needed);
365365

366366
if !fill_string.is_empty() {
367367
// Don't left-adjust if precision-filling: that will always be prepending 0s to %d
@@ -721,13 +721,13 @@ pub enum CFormatPart<T> {
721721
impl<T> CFormatPart<T> {
722722
#[inline]
723723
pub const fn is_specifier(&self) -> bool {
724-
matches!(self, CFormatPart::Spec { .. })
724+
matches!(self, Self::Spec { .. })
725725
}
726726

727727
#[inline]
728728
pub const fn has_key(&self) -> bool {
729729
match self {
730-
CFormatPart::Spec(s) => s.mapping_key.is_some(),
730+
Self::Spec(s) => s.mapping_key.is_some(),
731731
_ => false,
732732
}
733733
}

common/src/format.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ impl FormatParse for FormatConversion {
4040
}
4141

4242
impl FormatConversion {
43-
pub fn from_char(c: CodePoint) -> Option<FormatConversion> {
43+
pub fn from_char(c: CodePoint) -> Option<Self> {
4444
match c.to_char_lossy() {
45-
's' => Some(FormatConversion::Str),
46-
'r' => Some(FormatConversion::Repr),
47-
'a' => Some(FormatConversion::Ascii),
48-
'b' => Some(FormatConversion::Bytes),
45+
's' => Some(Self::Str),
46+
'r' => Some(Self::Repr),
47+
'a' => Some(Self::Ascii),
48+
'b' => Some(Self::Bytes),
4949
_ => None,
5050
}
5151
}
5252

53-
fn from_string(text: &Wtf8) -> Option<FormatConversion> {
53+
fn from_string(text: &Wtf8) -> Option<Self> {
5454
let mut chars = text.code_points();
5555
if chars.next()? != '!' {
5656
return None;
5757
}
5858

59-
FormatConversion::from_char(chars.next()?)
59+
Self::from_char(chars.next()?)
6060
}
6161
}
6262

@@ -69,12 +69,12 @@ pub enum FormatAlign {
6969
}
7070

7171
impl FormatAlign {
72-
fn from_char(c: CodePoint) -> Option<FormatAlign> {
72+
fn from_char(c: CodePoint) -> Option<Self> {
7373
match c.to_char_lossy() {
74-
'<' => Some(FormatAlign::Left),
75-
'>' => Some(FormatAlign::Right),
76-
'=' => Some(FormatAlign::AfterSign),
77-
'^' => Some(FormatAlign::Center),
74+
'<' => Some(Self::Left),
75+
'>' => Some(Self::Right),
76+
'=' => Some(Self::AfterSign),
77+
'^' => Some(Self::Center),
7878
_ => None,
7979
}
8080
}
@@ -143,7 +143,7 @@ pub enum FormatType {
143143
}
144144

145145
impl From<&FormatType> for char {
146-
fn from(from: &FormatType) -> char {
146+
fn from(from: &FormatType) -> Self {
147147
match from {
148148
FormatType::String => 's',
149149
FormatType::Binary => 'b',
@@ -301,7 +301,7 @@ impl FormatSpec {
301301
align = align.or(Some(FormatAlign::AfterSign));
302302
}
303303

304-
Ok(FormatSpec {
304+
Ok(Self {
305305
conversion,
306306
fill,
307307
align,
@@ -329,7 +329,7 @@ impl FormatSpec {
329329
let magnitude_int_str = parts.next().unwrap().to_string();
330330
let dec_digit_cnt = magnitude_str.len() as i32 - magnitude_int_str.len() as i32;
331331
let int_digit_cnt = disp_digit_cnt - dec_digit_cnt;
332-
let mut result = FormatSpec::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
332+
let mut result = Self::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
333333
if let Some(part) = parts.next() {
334334
result.push_str(&format!(".{part}"))
335335
}
@@ -352,11 +352,11 @@ impl FormatSpec {
352352
// separate with 0 padding
353353
let padding = "0".repeat(diff as usize);
354354
let padded_num = format!("{padding}{magnitude_str}");
355-
FormatSpec::insert_separator(padded_num, inter, sep, sep_cnt)
355+
Self::insert_separator(padded_num, inter, sep, sep_cnt)
356356
} else {
357357
// separate without padding
358358
let sep_cnt = (magnitude_len - 1) / inter;
359-
FormatSpec::insert_separator(magnitude_str, inter, sep, sep_cnt)
359+
Self::insert_separator(magnitude_str, inter, sep, sep_cnt)
360360
}
361361
}
362362

@@ -414,12 +414,7 @@ impl FormatSpec {
414414
let magnitude_len = magnitude_str.len();
415415
let width = self.width.unwrap_or(magnitude_len) as i32 - prefix.len() as i32;
416416
let disp_digit_cnt = cmp::max(width, magnitude_len as i32);
417-
FormatSpec::add_magnitude_separators_for_char(
418-
magnitude_str,
419-
inter,
420-
sep,
421-
disp_digit_cnt,
422-
)
417+
Self::add_magnitude_separators_for_char(magnitude_str, inter, sep, disp_digit_cnt)
423418
}
424419
None => magnitude_str,
425420
}
@@ -762,27 +757,26 @@ impl FormatSpec {
762757
"{}{}{}",
763758
sign_str,
764759
magnitude_str,
765-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed)
760+
Self::compute_fill_string(fill_char, fill_chars_needed)
766761
),
767762
FormatAlign::Right => format!(
768763
"{}{}{}",
769-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed),
764+
Self::compute_fill_string(fill_char, fill_chars_needed),
770765
sign_str,
771766
magnitude_str
772767
),
773768
FormatAlign::AfterSign => format!(
774769
"{}{}{}",
775770
sign_str,
776-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed),
771+
Self::compute_fill_string(fill_char, fill_chars_needed),
777772
magnitude_str
778773
),
779774
FormatAlign::Center => {
780775
let left_fill_chars_needed = fill_chars_needed / 2;
781776
let right_fill_chars_needed = fill_chars_needed - left_fill_chars_needed;
782-
let left_fill_string =
783-
FormatSpec::compute_fill_string(fill_char, left_fill_chars_needed);
777+
let left_fill_string = Self::compute_fill_string(fill_char, left_fill_chars_needed);
784778
let right_fill_string =
785-
FormatSpec::compute_fill_string(fill_char, right_fill_chars_needed);
779+
Self::compute_fill_string(fill_char, right_fill_chars_needed);
786780
format!("{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}")
787781
}
788782
})
@@ -849,7 +843,7 @@ pub enum FormatParseError {
849843
impl FromStr for FormatSpec {
850844
type Err = FormatSpecError;
851845
fn from_str(s: &str) -> Result<Self, Self::Err> {
852-
FormatSpec::parse(s)
846+
Self::parse(s)
853847
}
854848
}
855849

@@ -863,7 +857,7 @@ pub enum FieldNamePart {
863857
impl FieldNamePart {
864858
fn parse_part(
865859
chars: &mut impl PeekingNext<Item = CodePoint>,
866-
) -> Result<Option<FieldNamePart>, FormatParseError> {
860+
) -> Result<Option<Self>, FormatParseError> {
867861
chars
868862
.next()
869863
.map(|ch| match ch.to_char_lossy() {
@@ -875,7 +869,7 @@ impl FieldNamePart {
875869
if attribute.is_empty() {
876870
Err(FormatParseError::EmptyAttribute)
877871
} else {
878-
Ok(FieldNamePart::Attribute(attribute))
872+
Ok(Self::Attribute(attribute))
879873
}
880874
}
881875
'[' => {
@@ -885,9 +879,9 @@ impl FieldNamePart {
885879
return if index.is_empty() {
886880
Err(FormatParseError::EmptyAttribute)
887881
} else if let Some(index) = parse_usize(&index) {
888-
Ok(FieldNamePart::Index(index))
882+
Ok(Self::Index(index))
889883
} else {
890-
Ok(FieldNamePart::StringIndex(index))
884+
Ok(Self::StringIndex(index))
891885
};
892886
}
893887
index.push(ch);
@@ -918,7 +912,7 @@ fn parse_usize(s: &Wtf8) -> Option<usize> {
918912
}
919913

920914
impl FieldName {
921-
pub fn parse(text: &Wtf8) -> Result<FieldName, FormatParseError> {
915+
pub fn parse(text: &Wtf8) -> Result<Self, FormatParseError> {
922916
let mut chars = text.code_points().peekable();
923917
let first: Wtf8Buf = chars
924918
.peeking_take_while(|ch| *ch != '.' && *ch != '[')
@@ -937,7 +931,7 @@ impl FieldName {
937931
parts.push(part)
938932
}
939933

940-
Ok(FieldName { field_type, parts })
934+
Ok(Self { field_type, parts })
941935
}
942936
}
943937

@@ -978,7 +972,7 @@ impl FormatString {
978972
let mut cur_text = text;
979973
let mut result_string = Wtf8Buf::new();
980974
while !cur_text.is_empty() {
981-
match FormatString::parse_literal_single(cur_text) {
975+
match Self::parse_literal_single(cur_text) {
982976
Ok((next_char, remaining)) => {
983977
result_string.push(next_char);
984978
cur_text = remaining;
@@ -1092,7 +1086,7 @@ impl FormatString {
10921086
}
10931087
if let Some(pos) = end_bracket_pos {
10941088
let right = &text[pos..];
1095-
let format_part = FormatString::parse_part_in_brackets(&left)?;
1089+
let format_part = Self::parse_part_in_brackets(&left)?;
10961090
Ok((format_part, &right[1..]))
10971091
} else {
10981092
Err(FormatParseError::UnmatchedBracket)
@@ -1114,14 +1108,14 @@ impl<'a> FromTemplate<'a> for FormatString {
11141108
while !cur_text.is_empty() {
11151109
// Try to parse both literals and bracketed format parts until we
11161110
// run out of text
1117-
cur_text = FormatString::parse_literal(cur_text)
1118-
.or_else(|_| FormatString::parse_spec(cur_text))
1111+
cur_text = Self::parse_literal(cur_text)
1112+
.or_else(|_| Self::parse_spec(cur_text))
11191113
.map(|(part, new_text)| {
11201114
parts.push(part);
11211115
new_text
11221116
})?;
11231117
}
1124-
Ok(FormatString {
1118+
Ok(Self {
11251119
format_parts: parts,
11261120
})
11271121
}

common/src/linked_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ unsafe impl<T: Sync> Sync for Pointers<T> {}
140140

141141
impl<L, T> LinkedList<L, T> {
142142
/// Creates an empty linked list.
143-
pub const fn new() -> LinkedList<L, T> {
144-
LinkedList {
143+
pub const fn new() -> Self {
144+
Self {
145145
head: None,
146146
// tail: None,
147147
_marker: PhantomData,
@@ -323,8 +323,8 @@ where
323323

324324
impl<T> Pointers<T> {
325325
/// Create a new set of empty pointers
326-
pub fn new() -> Pointers<T> {
327-
Pointers {
326+
pub fn new() -> Self {
327+
Self {
328328
inner: UnsafeCell::new(PointersInner {
329329
prev: None,
330330
next: None,

0 commit comments

Comments
 (0)
0