nac3core: top level class method self parameter fixed
This commit is contained in:
parent
917d447605
commit
9eef51f29f
@ -642,7 +642,6 @@ impl TopLevelComposer {
|
||||
let have_unique_fuction_parameter_name = args.args.iter().all(|x| {
|
||||
defined_paramter_name.insert(x.node.arg.clone())
|
||||
&& !keyword_list.contains(&x.node.arg)
|
||||
&& "self" != x.node.arg
|
||||
});
|
||||
if !have_unique_fuction_parameter_name {
|
||||
return Err("top level function must have unique parameter names \
|
||||
@ -837,17 +836,21 @@ impl TopLevelComposer {
|
||||
let mut defined_paramter_name: HashSet<String> = HashSet::new();
|
||||
let have_unique_fuction_parameter_name = args.args.iter().all(|x| {
|
||||
defined_paramter_name.insert(x.node.arg.clone())
|
||||
&& !keyword_list.contains(&x.node.arg)
|
||||
&& (!keyword_list.contains(&x.node.arg) || x.node.arg == "self")
|
||||
});
|
||||
if !have_unique_fuction_parameter_name {
|
||||
return Err("class method must have unique parameter names \
|
||||
and names thould not be the same as the keywords"
|
||||
.into());
|
||||
}
|
||||
if name == "__init__" && !defined_paramter_name.contains("self") {
|
||||
return Err("__init__ function must have a `self` parameter".into());
|
||||
}
|
||||
|
||||
let mut result = Vec::new();
|
||||
for x in &args.args {
|
||||
let name = x.node.arg.clone();
|
||||
if name != "self" {
|
||||
let type_ann = {
|
||||
let annotation_expr = x
|
||||
.node
|
||||
@ -864,7 +867,8 @@ impl TopLevelComposer {
|
||||
)?
|
||||
};
|
||||
// find type vars within this method parameter type annotation
|
||||
let type_vars_within = get_type_var_contained_in_type_annotation(&type_ann);
|
||||
let type_vars_within =
|
||||
get_type_var_contained_in_type_annotation(&type_ann);
|
||||
// handle the class type var and the method type var
|
||||
for type_var_within in type_vars_within {
|
||||
if let TypeAnnotation::TypeVarKind(ty) = type_var_within {
|
||||
@ -889,6 +893,7 @@ impl TopLevelComposer {
|
||||
type_var_to_concrete_def.insert(dummy_func_arg.ty, type_ann.clone());
|
||||
result.push(dummy_func_arg)
|
||||
}
|
||||
}
|
||||
result
|
||||
};
|
||||
|
||||
|
@ -156,7 +156,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
|
||||
vec![
|
||||
indoc! {"
|
||||
class A():
|
||||
def __init__():
|
||||
def __init__(self):
|
||||
self.a: int32 = 3
|
||||
def fun(b: B):
|
||||
pass
|
||||
@ -165,12 +165,12 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
|
||||
"},
|
||||
indoc! {"
|
||||
class B(C):
|
||||
def __init__():
|
||||
def __init__(self):
|
||||
pass
|
||||
"},
|
||||
indoc! {"
|
||||
class C(A):
|
||||
def __init__():
|
||||
def __init__(self):
|
||||
pass
|
||||
def fun(b: B):
|
||||
a = 1
|
||||
@ -273,16 +273,16 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
|
||||
vec![
|
||||
indoc! {"
|
||||
class Generic_A(Generic[V], B):
|
||||
def __init__():
|
||||
def __init__(self):
|
||||
self.a: int64 = 123123123123
|
||||
def fun(a: int32) -> V:
|
||||
def fun(self, a: int32) -> V:
|
||||
pass
|
||||
"},
|
||||
indoc! {"
|
||||
class B:
|
||||
def __init__():
|
||||
def __init__(self):
|
||||
self.aa: bool = False
|
||||
def foo(b: T):
|
||||
def foo(self, b: T):
|
||||
pass
|
||||
"}
|
||||
],
|
||||
@ -343,7 +343,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
|
||||
"},
|
||||
indoc! {"
|
||||
class A(Generic[T, V]):
|
||||
def __init__(v: V):
|
||||
def __init__(self, v: V):
|
||||
self.a: T = 1
|
||||
self.b: V = v
|
||||
def fun(a: T) -> V:
|
||||
@ -355,7 +355,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
|
||||
"},
|
||||
indoc! {"
|
||||
class B:
|
||||
def __init__():
|
||||
def __init__(self):
|
||||
pass
|
||||
"}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user