use crate::{error::EvalResult, value::Value};
pub const ABSTRACT_DECORATORS: &[&str] =
&["abstractmethod", "abstractproperty", "abstractclassmethod", "abstractstaticmethod"];
pub fn has_function(name: &str) -> bool {
ABSTRACT_DECORATORS.contains(&name)
}
pub fn constant(name: &str) -> Option<Value> {
match name {
"ABC" | "ABCMeta" => Some(Value::Type(format!("abc.{name}"))),
_ => None,
}
}
pub fn call(func: &str, args: &[Value]) -> EvalResult {
if ABSTRACT_DECORATORS.contains(&func) {
return Ok(args.first().cloned().unwrap_or(Value::None));
}
Err(crate::error::InterpreterError::AttributeError(format!(
"module 'abc' has no attribute '{func}'"
))
.into())
}
pub struct AbcModule;
#[async_trait::async_trait]
impl crate::eval::modules::Module for AbcModule {
fn name(&self) -> &'static str {
"abc"
}
fn constant(&self, name: &str) -> Option<Value> {
constant(name)
}
fn has_function(&self, name: &str) -> bool {
has_function(name)
}
async fn call(
&self,
_state: &mut crate::state::InterpreterState,
func: &str,
args: &[Value],
_kwargs: &indexmap::IndexMap<String, Value>,
_tools: &crate::tools::Tools,
) -> EvalResult {
call(func, args)
}
}