Skip to content

Commit 593b9d2

Browse files
committed
Merge remote-tracking branch 'upstream/main' into constify
2 parents 4e91f6a + 5b20bb8 commit 593b9d2

144 files changed

Lines changed: 1717 additions & 3290 deletions

File tree

Some content is hidden

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

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: 10 additions & 10 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

@@ -136,7 +136,7 @@ bitflags! {
136136

137137
impl CConversionFlags {
138138
#[inline]
139-
pub const fn sign_string(&self) -> &'static str {
139+
pub fn sign_string(&self) -> &'static str {
140140
if self.contains(Self::SIGN_CHAR) {
141141
"+"
142142
} else if self.contains(Self::BLANK_SIGN) {
@@ -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/encodings.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ struct DecodeError<'a> {
137137

138138
/// # Safety
139139
/// `v[..valid_up_to]` must be valid utf8
140-
const unsafe fn make_decode_err(
141-
v: &[u8],
142-
valid_up_to: usize,
143-
err_len: Option<usize>,
144-
) -> DecodeError<'_> {
140+
unsafe fn make_decode_err(v: &[u8], valid_up_to: usize, err_len: Option<usize>) -> DecodeError<'_> {
145141
let (valid_prefix, rest) = unsafe { v.split_at_unchecked(valid_up_to) };
146142
let valid_prefix = unsafe { core::str::from_utf8_unchecked(valid_prefix) };
147143
DecodeError {

common/src/format.rs

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

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

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

57-
FormatConversion::from_char(chars.next()?)
57+
Self::from_char(chars.next()?)
5858
}
5959
}
6060

@@ -67,12 +67,12 @@ pub enum FormatAlign {
6767
}
6868

6969
impl FormatAlign {
70-
fn from_char(c: CodePoint) -> Option<FormatAlign> {
70+
fn from_char(c: CodePoint) -> Option<Self> {
7171
match c.to_char_lossy() {
72-
'<' => Some(FormatAlign::Left),
73-
'>' => Some(FormatAlign::Right),
74-
'=' => Some(FormatAlign::AfterSign),
75-
'^' => Some(FormatAlign::Center),
72+
'<' => Some(Self::Left),
73+
'>' => Some(Self::Right),
74+
'=' => Some(Self::AfterSign),
75+
'^' => Some(Self::Center),
7676
_ => None,
7777
}
7878
}
@@ -141,7 +141,7 @@ pub enum FormatType {
141141
}
142142

143143
impl From<&FormatType> for char {
144-
fn from(from: &FormatType) -> char {
144+
fn from(from: &FormatType) -> Self {
145145
match from {
146146
FormatType::String => 's',
147147
FormatType::Binary => 'b',
@@ -299,7 +299,7 @@ impl FormatSpec {
299299
align = align.or(Some(FormatAlign::AfterSign));
300300
}
301301

302-
Ok(FormatSpec {
302+
Ok(Self {
303303
conversion,
304304
fill,
305305
align,
@@ -327,7 +327,7 @@ impl FormatSpec {
327327
let magnitude_int_str = parts.next().unwrap().to_string();
328328
let dec_digit_cnt = magnitude_str.len() as i32 - magnitude_int_str.len() as i32;
329329
let int_digit_cnt = disp_digit_cnt - dec_digit_cnt;
330-
let mut result = FormatSpec::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
330+
let mut result = Self::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
331331
if let Some(part) = parts.next() {
332332
result.push_str(&format!(".{part}"))
333333
}
@@ -350,11 +350,11 @@ impl FormatSpec {
350350
// separate with 0 padding
351351
let padding = "0".repeat(diff as usize);
352352
let padded_num = format!("{padding}{magnitude_str}");
353-
FormatSpec::insert_separator(padded_num, inter, sep, sep_cnt)
353+
Self::insert_separator(padded_num, inter, sep, sep_cnt)
354354
} else {
355355
// separate without padding
356356
let sep_cnt = (magnitude_len - 1) / inter;
357-
FormatSpec::insert_separator(magnitude_str, inter, sep, sep_cnt)
357+
Self::insert_separator(magnitude_str, inter, sep, sep_cnt)
358358
}
359359
}
360360

@@ -412,12 +412,7 @@ impl FormatSpec {
412412
let magnitude_len = magnitude_str.len();
413413
let width = self.width.unwrap_or(magnitude_len) as i32 - prefix.len() as i32;
414414
let disp_digit_cnt = cmp::max(width, magnitude_len as i32);
415-
FormatSpec::add_magnitude_separators_for_char(
416-
magnitude_str,
417-
inter,
418-
sep,
419-
disp_digit_cnt,
420-
)
415+
Self::add_magnitude_separators_for_char(magnitude_str, inter, sep, disp_digit_cnt)
421416
}
422417
None => magnitude_str,
423418
}
@@ -640,27 +635,26 @@ impl FormatSpec {
640635
"{}{}{}",
641636
sign_str,
642637
magnitude_str,
643-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed)
638+
Self::compute_fill_string(fill_char, fill_chars_needed)
644639
),
645640
FormatAlign::Right => format!(
646641
"{}{}{}",
647-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed),
642+
Self::compute_fill_string(fill_char, fill_chars_needed),
648643
sign_str,
649644
magnitude_str
650645
),
651646
FormatAlign::AfterSign => format!(
652647
"{}{}{}",
653648
sign_str,
654-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed),
649+
Self::compute_fill_string(fill_char, fill_chars_needed),
655650
magnitude_str
656651
),
657652
FormatAlign::Center => {
658653
let left_fill_chars_needed = fill_chars_needed / 2;
659654
let right_fill_chars_needed = fill_chars_needed - left_fill_chars_needed;
660-
let left_fill_string =
661-
FormatSpec::compute_fill_string(fill_char, left_fill_chars_needed);
655+
let left_fill_string = Self::compute_fill_string(fill_char, left_fill_chars_needed);
662656
let right_fill_string =
663-
FormatSpec::compute_fill_string(fill_char, right_fill_chars_needed);
657+
Self::compute_fill_string(fill_char, right_fill_chars_needed);
664658
format!("{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}")
665659
}
666660
})
@@ -725,7 +719,7 @@ pub enum FormatParseError {
725719
impl FromStr for FormatSpec {
726720
type Err = FormatSpecError;
727721
fn from_str(s: &str) -> Result<Self, Self::Err> {
728-
FormatSpec::parse(s)
722+
Self::parse(s)
729723
}
730724
}
731725

@@ -739,7 +733,7 @@ pub enum FieldNamePart {
739733
impl FieldNamePart {
740734
fn parse_part(
741735
chars: &mut impl PeekingNext<Item = CodePoint>,
742-
) -> Result<Option<FieldNamePart>, FormatParseError> {
736+
) -> Result<Option<Self>, FormatParseError> {
743737
chars
744738
.next()
745739
.map(|ch| match ch.to_char_lossy() {
@@ -751,7 +745,7 @@ impl FieldNamePart {
751745
if attribute.is_empty() {
752746
Err(FormatParseError::EmptyAttribute)
753747
} else {
754-
Ok(FieldNamePart::Attribute(attribute))
748+
Ok(Self::Attribute(attribute))
755749
}
756750
}
757751
'[' => {
@@ -761,9 +755,9 @@ impl FieldNamePart {
761755
return if index.is_empty() {
762756
Err(FormatParseError::EmptyAttribute)
763757
} else if let Some(index) = parse_usize(&index) {
764-
Ok(FieldNamePart::Index(index))
758+
Ok(Self::Index(index))
765759
} else {
766-
Ok(FieldNamePart::StringIndex(index))
760+
Ok(Self::StringIndex(index))
767761
};
768762
}
769763
index.push(ch);
@@ -794,7 +788,7 @@ fn parse_usize(s: &Wtf8) -> Option<usize> {
794788
}
795789

796790
impl FieldName {
797-
pub fn parse(text: &Wtf8) -> Result<FieldName, FormatParseError> {
791+
pub fn parse(text: &Wtf8) -> Result<Self, FormatParseError> {
798792
let mut chars = text.code_points().peekable();
799793
let first: Wtf8Buf = chars
800794
.peeking_take_while(|ch| *ch != '.' && *ch != '[')
@@ -813,7 +807,7 @@ impl FieldName {
813807
parts.push(part)
814808
}
815809

816-
Ok(FieldName { field_type, parts })
810+
Ok(Self { field_type, parts })
817811
}
818812
}
819813

@@ -854,7 +848,7 @@ impl FormatString {
854848
let mut cur_text = text;
855849
let mut result_string = Wtf8Buf::new();
856850
while !cur_text.is_empty() {
857-
match FormatString::parse_literal_single(cur_text) {
851+
match Self::parse_literal_single(cur_text) {
858852
Ok((next_char, remaining)) => {
859853
result_string.push(next_char);
860854
cur_text = remaining;
@@ -968,7 +962,7 @@ impl FormatString {
968962
}
969963
if let Some(pos) = end_bracket_pos {
970964
let right = &text[pos..];
971-
let format_part = FormatString::parse_part_in_brackets(&left)?;
965+
let format_part = Self::parse_part_in_brackets(&left)?;
972966
Ok((format_part, &right[1..]))
973967
} else {
974968
Err(FormatParseError::UnmatchedBracket)
@@ -990,14 +984,14 @@ impl<'a> FromTemplate<'a> for FormatString {
990984
while !cur_text.is_empty() {
991985
// Try to parse both literals and bracketed format parts until we
992986
// run out of text
993-
cur_text = FormatString::parse_literal(cur_text)
994-
.or_else(|_| FormatString::parse_spec(cur_text))
987+
cur_text = Self::parse_literal(cur_text)
988+
.or_else(|_| Self::parse_spec(cur_text))
995989
.map(|(part, new_text)| {
996990
parts.push(part);
997991
new_text
998992
})?;
999993
}
1000-
Ok(FormatString {
994+
Ok(Self {
1001995
format_parts: parts,
1002996
})
1003997
}

0 commit comments

Comments
 (0)