Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Replace direct use of once_cell to std #5627

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 2 commits into from
Mar 27, 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
2 changes: 0 additions & 2 deletions 2 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion 1 derive-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ rustpython-compiler-core = { workspace = true }
rustpython-doc = { workspace = true }

itertools = { workspace = true }
once_cell = { workspace = true }
syn = { workspace = true, features = ["full", "extra-traits"] }

maplit = "1.0.2"
Expand Down
4 changes: 2 additions & 2 deletions 4 derive-impl/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
//! ```

use crate::Diagnostic;
use once_cell::sync::Lazy;
use proc_macro2::{Span, TokenStream};
use quote::quote;
use rustpython_compiler_core::{Mode, bytecode::CodeObject, frozen};
use std::sync::LazyLock;
use std::{
collections::HashMap,
env, fs,
Expand All @@ -29,7 +29,7 @@ use syn::{
spanned::Spanned,
};

static CARGO_MANIFEST_DIR: Lazy<PathBuf> = Lazy::new(|| {
static CARGO_MANIFEST_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present"))
});

Expand Down
1 change: 0 additions & 1 deletion 1 stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ malachite-bigint = { workspace = true }
num-integer = { workspace = true }
num-traits = { workspace = true }
num_enum = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
thread_local = { workspace = true }

Expand Down
4 changes: 2 additions & 2 deletions 4 stdlib/src/contextvars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod _contextvars {
};
use crossbeam_utils::atomic::AtomicCell;
use indexmap::IndexMap;
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use std::{
cell::{Cell, RefCell, UnsafeCell},
sync::atomic::Ordering,
Expand Down Expand Up @@ -274,7 +274,7 @@ mod _contextvars {

impl AsSequence for PyContext {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
contains: atomic_func!(|seq, target, vm| {
let target = target.try_to_value(vm)?;
PyContext::sequence_downcast(seq).contains(target)
Expand Down
6 changes: 3 additions & 3 deletions 6 stdlib/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ mod _csv {
};
use csv_core::Terminator;
use itertools::{self, Itertools};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use rustpython_vm::match_class;
use std::sync::LazyLock;
use std::{collections::HashMap, fmt};

#[pyattr]
Expand All @@ -41,11 +41,11 @@ mod _csv {
)
}

static GLOBAL_HASHMAP: Lazy<Mutex<HashMap<String, PyDialect>>> = Lazy::new(|| {
static GLOBAL_HASHMAP: LazyLock<Mutex<HashMap<String, PyDialect>>> = LazyLock::new(|| {
let m = HashMap::new();
Mutex::new(m)
});
static GLOBAL_FIELD_LIMIT: Lazy<Mutex<isize>> = Lazy::new(|| Mutex::new(131072));
static GLOBAL_FIELD_LIMIT: LazyLock<Mutex<isize>> = LazyLock::new(|| Mutex::new(131072));

fn new_csv_error(vm: &VirtualMachine, msg: String) -> PyBaseExceptionRef {
vm.new_exception_msg(super::_csv::error(vm), msg)
Expand Down
4 changes: 2 additions & 2 deletions 4 stdlib/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ mod mmap {

impl AsSequence for PyMmap {
fn as_sequence() -> &'static PySequenceMethods {
use once_cell::sync::Lazy;
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
use std::sync::LazyLock;
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyMmap::sequence_downcast(seq).len())),
item: atomic_func!(|seq, i, vm| {
let zelf = PyMmap::sequence_downcast(seq);
Expand Down
8 changes: 4 additions & 4 deletions 8 stdlib/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,8 +1953,8 @@ mod _sqlite {

impl AsMapping for Row {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: once_cell::sync::Lazy<PyMappingMethods> =
once_cell::sync::Lazy::new(|| PyMappingMethods {
static AS_MAPPING: std::sync::LazyLock<PyMappingMethods> =
std::sync::LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, _vm| Ok(Row::mapping_downcast(mapping)
.data
.len())),
Expand All @@ -1969,8 +1969,8 @@ mod _sqlite {

impl AsSequence for Row {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: once_cell::sync::Lazy<PySequenceMethods> =
once_cell::sync::Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: std::sync::LazyLock<PySequenceMethods> =
std::sync::LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(Row::sequence_downcast(seq).data.len())),
item: atomic_func!(|seq, i, vm| Row::sequence_downcast(seq)
.data
Expand Down
4 changes: 2 additions & 2 deletions 4 stdlib/src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) use _uuid::make_module;
mod _uuid {
use crate::{builtins::PyNone, vm::VirtualMachine};
use mac_address::get_mac_address;
use once_cell::sync::OnceCell;
use std::sync::OnceLock;
use uuid::{Context, Uuid, timestamp::Timestamp};

fn get_node_id() -> [u8; 6] {
Expand All @@ -19,7 +19,7 @@ mod _uuid {
static CONTEXT: Context = Context::new(0);
let ts = Timestamp::now(&CONTEXT);

static NODE_ID: OnceCell<[u8; 6]> = OnceCell::new();
static NODE_ID: OnceLock<[u8; 6]> = OnceLock::new();
let unique_node_id = NODE_ID.get_or_init(get_node_id);

(Uuid::new_v1(ts, unique_node_id).as_bytes().to_vec(), PyNone)
Expand Down
6 changes: 3 additions & 3 deletions 6 vm/src/builtins/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
},
};
use bstr::ByteSlice;
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use std::{mem::size_of, ops::Deref};

#[pyclass(module = false, name = "bytes")]
Expand Down Expand Up @@ -568,7 +568,7 @@ impl AsBuffer for PyBytes {

impl AsMapping for PyBytes {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, _vm| Ok(PyBytes::mapping_downcast(mapping).len())),
subscript: atomic_func!(
|mapping, needle, vm| PyBytes::mapping_downcast(mapping)._getitem(needle, vm)
Expand All @@ -581,7 +581,7 @@ impl AsMapping for PyBytes {

impl AsSequence for PyBytes {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyBytes::sequence_downcast(seq).len())),
concat: atomic_func!(|seq, other, vm| {
PyBytes::sequence_downcast(seq)
Expand Down
10 changes: 5 additions & 5 deletions 10 vm/src/builtins/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use crate::{
},
vm::VirtualMachine,
};
use once_cell::sync::Lazy;
use rustpython_common::lock::PyMutex;
use std::fmt;
use std::sync::LazyLock;

pub type DictContentType = dictdatatype::Dict;

Expand Down Expand Up @@ -443,7 +443,7 @@ impl AsMapping for PyDict {

impl AsSequence for PyDict {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
contains: atomic_func!(|seq, target, vm| PyDict::sequence_downcast(seq)
.entries
.contains(vm, target)),
Expand Down Expand Up @@ -1133,7 +1133,7 @@ impl Comparable for PyDictKeys {

impl AsSequence for PyDictKeys {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyDictKeys::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, target, vm| {
PyDictKeys::sequence_downcast(seq)
Expand Down Expand Up @@ -1196,7 +1196,7 @@ impl Comparable for PyDictItems {

impl AsSequence for PyDictItems {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyDictItems::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, target, vm| {
let needle: &Py<PyTuple> = match target.downcast_ref() {
Expand Down Expand Up @@ -1246,7 +1246,7 @@ impl Unconstructible for PyDictValues {}

impl AsSequence for PyDictValues {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyDictValues::sequence_downcast(seq).len())),
..PySequenceMethods::NOT_IMPLEMENTED
});
Expand Down
4 changes: 2 additions & 2 deletions 4 vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;

use super::type_;
use crate::{
Expand Down Expand Up @@ -325,7 +325,7 @@ pub fn subs_parameters<F: Fn(&VirtualMachine) -> PyResult<String>>(

impl AsMapping for PyGenericAlias {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
subscript: atomic_func!(|mapping, needle, vm| {
PyGenericAlias::mapping_downcast(mapping).getitem(needle.to_owned(), vm)
}),
Expand Down
6 changes: 3 additions & 3 deletions 6 vm/src/builtins/mappingproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
Representable,
},
};
use once_cell::sync::Lazy;
use std::sync::LazyLock;

#[pyclass(module = false, name = "mappingproxy", traverse)]
#[derive(Debug)]
Expand Down Expand Up @@ -221,7 +221,7 @@ impl Comparable for PyMappingProxy {

impl AsMapping for PyMappingProxy {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, vm| PyMappingProxy::mapping_downcast(mapping).len(vm)),
subscript: atomic_func!(|mapping, needle, vm| {
PyMappingProxy::mapping_downcast(mapping).getitem(needle.to_owned(), vm)
Expand All @@ -234,7 +234,7 @@ impl AsMapping for PyMappingProxy {

impl AsSequence for PyMappingProxy {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
contains: atomic_func!(
|seq, target, vm| PyMappingProxy::sequence_downcast(seq)._contains(target, vm)
),
Expand Down
4 changes: 2 additions & 2 deletions 4 vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use crate::{
};
use crossbeam_utils::atomic::AtomicCell;
use itertools::Itertools;
use once_cell::sync::Lazy;
use rustpython_common::lock::PyMutex;
use std::sync::LazyLock;
use std::{cmp::Ordering, fmt::Debug, mem::ManuallyDrop, ops::Range};

#[derive(FromArgs)]
Expand Down Expand Up @@ -993,7 +993,7 @@ impl AsMapping for PyMemoryView {

impl AsSequence for PyMemoryView {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, vm| {
let zelf = PyMemoryView::sequence_downcast(seq);
zelf.try_not_released(vm)?;
Expand Down
6 changes: 3 additions & 3 deletions 6 vm/src/builtins/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crossbeam_utils::atomic::AtomicCell;
use malachite_bigint::{BigInt, Sign};
use num_integer::Integer;
use num_traits::{One, Signed, ToPrimitive, Zero};
use once_cell::sync::Lazy;
use std::cmp::max;
use std::sync::LazyLock;

// Search flag passed to iter_search
enum SearchType {
Expand Down Expand Up @@ -385,7 +385,7 @@ impl PyRange {

impl AsMapping for PyRange {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(
|mapping, vm| PyRange::mapping_downcast(mapping).protocol_length(vm)
),
Expand All @@ -400,7 +400,7 @@ impl AsMapping for PyRange {

impl AsSequence for PyRange {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, vm| PyRange::sequence_downcast(seq).protocol_length(vm)),
item: atomic_func!(|seq, i, vm| {
PyRange::sequence_downcast(seq)
Expand Down
6 changes: 3 additions & 3 deletions 6 vm/src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use crate::{
utils::collection_repr,
vm::VirtualMachine,
};
use once_cell::sync::Lazy;
use rustpython_common::{
atomic::{Ordering, PyAtomic, Radium},
hash,
};
use std::sync::LazyLock;
use std::{fmt, ops::Deref};

pub type SetContentType = dictdatatype::Dict<()>;
Expand Down Expand Up @@ -794,7 +794,7 @@ impl Initializer for PySet {

impl AsSequence for PySet {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PySet::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, needle, vm| PySet::sequence_downcast(seq)
.inner
Expand Down Expand Up @@ -1112,7 +1112,7 @@ impl PyFrozenSet {

impl AsSequence for PyFrozenSet {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyFrozenSet::sequence_downcast(seq).len())),
contains: atomic_func!(|seq, needle, vm| PyFrozenSet::sequence_downcast(seq)
.inner
Expand Down
6 changes: 3 additions & 3 deletions 6 vm/src/builtins/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use ascii::{AsciiChar, AsciiStr, AsciiString};
use bstr::ByteSlice;
use itertools::Itertools;
use num_traits::ToPrimitive;
use once_cell::sync::Lazy;
use rustpython_common::{
ascii,
atomic::{self, PyAtomic, Radium},
Expand All @@ -38,6 +37,7 @@ use rustpython_common::{
str::DeduceStrKind,
wtf8::{CodePoint, Wtf8, Wtf8Buf, Wtf8Chunk},
};
use std::sync::LazyLock;
use std::{borrow::Cow, char, fmt, ops::Range};
use unic_ucd_bidi::BidiClass;
use unic_ucd_category::GeneralCategory;
Expand Down Expand Up @@ -1495,7 +1495,7 @@ impl Iterable for PyStr {

impl AsMapping for PyStr {
fn as_mapping() -> &'static PyMappingMethods {
static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {
static AS_MAPPING: LazyLock<PyMappingMethods> = LazyLock::new(|| PyMappingMethods {
length: atomic_func!(|mapping, _vm| Ok(PyStr::mapping_downcast(mapping).len())),
subscript: atomic_func!(
|mapping, needle, vm| PyStr::mapping_downcast(mapping)._getitem(needle, vm)
Expand Down Expand Up @@ -1524,7 +1524,7 @@ impl AsNumber for PyStr {

impl AsSequence for PyStr {
fn as_sequence() -> &'static PySequenceMethods {
static AS_SEQUENCE: Lazy<PySequenceMethods> = Lazy::new(|| PySequenceMethods {
static AS_SEQUENCE: LazyLock<PySequenceMethods> = LazyLock::new(|| PySequenceMethods {
length: atomic_func!(|seq, _vm| Ok(PyStr::sequence_downcast(seq).len())),
concat: atomic_func!(|seq, other, vm| {
let zelf = PyStr::sequence_downcast(seq);
Expand Down
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.