8000 typing upgrade to 3.13.2 by arihant2math · Pull Request #5590 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

typing upgrade to 3.13.2 #5590

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 23 commits into from
Apr 27, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
implement more of ParamSpec
  • Loading branch information
arihant2math committed Apr 18, 2025
commit 1b3ac3f05a3919d6b54b29baa0cd935cfda0b57c
77 changes: 76 additions & 1 deletion vm/src/stdlib/typing.rs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
#[allow(dead_code)]
pub(crate) struct ParamSpec {
name: PyObjectRef,
bound: Option<PyObjectRef>,
default_value: Option<PyObjectRef>,
evaluate_default: Option<PyObjectRef>,
covariant: bool,
contravariant: bool,
infer_variance: bool,
}

#[pyclass(flags(BASETYPE))]
Expand All @@ -90,10 +96,79 @@
fn name(&self) -> PyObjectRef {
self.name.clone()
}

#[pygetset(magic)]
fn bound(&self, vm: &VirtualMachine) -> PyObjectRef {
if let Some(bound) = self.bound.clone() {
return bound;
}
vm.ctx.none()
}

#[pygetset(magic)]
fn covariant(&self) -> bool {
self.covariant
}

#[pygetset(magic)]
fn contravariant(&self) -> bool {
self.contravariant
}

#[pygetset(magic)]
fn infer_variance(&self) -> bool {
self.infer_variance
}

#[pygetset(magic)]
fn default(&self, vm: &VirtualMachine) -> PyResult {
if let Some(default_value) = self.default_value.clone() {
return Ok(default_value);
}
// handle evaludate_default

Check warning on line 128 in vm/src/stdlib/typing.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (evaludate)
if let Some(evaluate_default) = self.evaluate_default.clone() {
let default_value = vm.call_method(evaluate_default.as_ref(), "__call__", ())?;
return Ok(default_value);
}
// TODO: this isn't up to spec
Ok(vm.ctx.none())
}

#[pygetset]
fn evaluate_default(&self, vm: &VirtualMachine) -> PyObjectRef {
if let Some(evaluate_default) = self.evaluate_default.clone() {
return evaluate_default;
}
// TODO: default_value case
vm.ctx.none()
}

#[pymethod(magic)]
fn reduce(&self) -> PyResult {
Ok(self.name.clone())
}

#[pymethod]
fn has_default(&self) -> PyResult<bool> {
// TODO: fix
if self.evaluate_default.is_some() || self.default_value.is_some() {
Ok(true)
} else {
Ok(false)
}
}
}

pub(crate) fn make_paramspec(name: PyObjectRef) -> ParamSpec {
ParamSpec { name }
ParamSpec {
name,
bound: None,
default_value: None,
evaluate_default: None,
covariant: false,
contravariant: false,
infer_variance: false,
}
}

#[pyattr]
Expand Down
Loading
0