fix: external pylib bugs

This commit is contained in:
Shunsuke Shibayama 2023-12-06 18:31:03 +09:00
parent 20935796fd
commit fb0248fdf1
7 changed files with 41 additions and 5 deletions

View file

@ -1687,6 +1687,7 @@ impl Context {
let mut errs = TyCheckErrors::empty();
// method: obj: 1, subr: (self: Int, other: Int) -> Int
// non-method: obj: Int, subr: (self: Int, other: Int) -> Int
// FIXME: staticmethod
let is_method = subr
.self_t()
.map_or(false, |self_t| self.subtype_of(obj.ref_t(), self_t));

View file

@ -49,8 +49,8 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
hir::Expr::TypeAsc(tasc) => enum_unwrap!(tasc.expr.as_ref(), hir::Expr::Accessor)
.local_name()
.map(Str::rc),
hir::Expr::Accessor(acc) => acc.var_info().py_name.clone(),
_ => sig.inspect().cloned(),
hir::Expr::Accessor(hir::Accessor::Ident(ident)) => ident.vi.py_name.clone(),
_ => sig.escaped(),
};
let found_body_t = chunk.ref_t();
let ident = match &sig.pat {

View file

@ -805,12 +805,18 @@ passed keyword args: {kw_args_len}"
"english" =>sup_type.push_str("supertype: "),
);
sup_type.push_str_with_color_and_attr(format!("{sup_t}"), ERR, ATTR);
let hint = switch_lang!(
"japanese" => "これがあなたの定義した型ならば、型を共変もしくは反変にしてみてください(<: Output T もしくは <: Input T)",
"simplified_chinese" => "如果这是您定义的类型,请尝试将类型变为协变或逆变(<: Output T 或 <: Input T)",
"traditional_chinese" => "如果這是您定義的類型,請嘗試將類型變為協變或逆變(<: Output T 或 <: Input T)",
"english" => "If this is the type you defined, try to make the type covariant or contravariant (<: Output T or <: Input T)",
);
Self::new(
ErrorCore::new(
vec![SubMessage::ambiguous_new(
loc,
vec![sub_type.to_string(), sup_type.to_string()],
None,
Some(hint.to_string()),
)],
switch_lang!(
"japanese" => "不変な型パラメータを一意に決定できません",

View file

@ -9,15 +9,21 @@
ndim: Nat
dtype: Type
size: Nat
copy: |T, S: [Nat; _]|(self: .NDArray(T, S),) -> .NDArray(T, S)
reshape: |T, Old: [Nat; _], S: [Nat; _]|(
self: .NDArray(T, Old),
shape: {S},
) -> .NDArray(T, S)
sum: |T <: Num|(self: .NDArray(T, _),) -> T
take: (|T|(self: .NDArray(T, _), indice: Nat) -> T) \
and (|T|(self: .NDArray(T, _), indices: .NDArray(Nat) or [Nat; _]) -> .NDArray(T, _))
tobytes: |T|(self: .NDArray(T, _),) -> Bytes
tolist: |T|(self: .NDArray(T, _),) -> [T; _]
.nan: Float
.Nan: Float
.abs: |T|(object: .NDArray(T),) -> .NDArray(T)
.abs: |T, S: [Nat; _]|(object: .NDArray(T, S),) -> .NDArray(T, S)
.add: |T, S: [Nat; _]|(object: .NDArray(T, S), other: .NDArray(T, S)) -> .NDArray(T, S)
.all: |T <: Num|(object: .NDArray(T),) -> Bool
.any: |T <: Num|(object: .NDArray(T),) -> Bool

View file

@ -1,7 +1,6 @@
.Tqdm! = 'tqdm': (T: Type) -> ClassType
.Tqdm!(T) <: Iterable T
.Tqdm!(T).
# TODO: iterable should be Comparable
__call__: (
iterable: Iterable(T),
desc := Str,
@ -30,3 +29,5 @@
delay := Float,
gui := Bool,
) -> .Tqdm!(T)
.tqdm = .Tqdm!.__call__