mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
fix: external pylib bugs
This commit is contained in:
parent
20935796fd
commit
fb0248fdf1
7 changed files with 41 additions and 5 deletions
|
@ -1687,6 +1687,7 @@ impl Context {
|
||||||
let mut errs = TyCheckErrors::empty();
|
let mut errs = TyCheckErrors::empty();
|
||||||
// method: obj: 1, subr: (self: Int, other: Int) -> Int
|
// method: obj: 1, subr: (self: Int, other: Int) -> Int
|
||||||
// non-method: obj: Int, subr: (self: Int, other: Int) -> Int
|
// non-method: obj: Int, subr: (self: Int, other: Int) -> Int
|
||||||
|
// FIXME: staticmethod
|
||||||
let is_method = subr
|
let is_method = subr
|
||||||
.self_t()
|
.self_t()
|
||||||
.map_or(false, |self_t| self.subtype_of(obj.ref_t(), self_t));
|
.map_or(false, |self_t| self.subtype_of(obj.ref_t(), self_t));
|
||||||
|
|
|
@ -49,8 +49,8 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
|
||||||
hir::Expr::TypeAsc(tasc) => enum_unwrap!(tasc.expr.as_ref(), hir::Expr::Accessor)
|
hir::Expr::TypeAsc(tasc) => enum_unwrap!(tasc.expr.as_ref(), hir::Expr::Accessor)
|
||||||
.local_name()
|
.local_name()
|
||||||
.map(Str::rc),
|
.map(Str::rc),
|
||||||
hir::Expr::Accessor(acc) => acc.var_info().py_name.clone(),
|
hir::Expr::Accessor(hir::Accessor::Ident(ident)) => ident.vi.py_name.clone(),
|
||||||
_ => sig.inspect().cloned(),
|
_ => sig.escaped(),
|
||||||
};
|
};
|
||||||
let found_body_t = chunk.ref_t();
|
let found_body_t = chunk.ref_t();
|
||||||
let ident = match &sig.pat {
|
let ident = match &sig.pat {
|
||||||
|
|
|
@ -805,12 +805,18 @@ passed keyword args: {kw_args_len}"
|
||||||
"english" =>sup_type.push_str("supertype: "),
|
"english" =>sup_type.push_str("supertype: "),
|
||||||
);
|
);
|
||||||
sup_type.push_str_with_color_and_attr(format!("{sup_t}"), ERR, ATTR);
|
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(
|
Self::new(
|
||||||
ErrorCore::new(
|
ErrorCore::new(
|
||||||
vec![SubMessage::ambiguous_new(
|
vec![SubMessage::ambiguous_new(
|
||||||
loc,
|
loc,
|
||||||
vec![sub_type.to_string(), sup_type.to_string()],
|
vec![sub_type.to_string(), sup_type.to_string()],
|
||||||
None,
|
Some(hint.to_string()),
|
||||||
)],
|
)],
|
||||||
switch_lang!(
|
switch_lang!(
|
||||||
"japanese" => "不変な型パラメータを一意に決定できません",
|
"japanese" => "不変な型パラメータを一意に決定できません",
|
||||||
|
|
|
@ -9,15 +9,21 @@
|
||||||
ndim: Nat
|
ndim: Nat
|
||||||
dtype: Type
|
dtype: Type
|
||||||
size: Nat
|
size: Nat
|
||||||
|
copy: |T, S: [Nat; _]|(self: .NDArray(T, S),) -> .NDArray(T, S)
|
||||||
reshape: |T, Old: [Nat; _], S: [Nat; _]|(
|
reshape: |T, Old: [Nat; _], S: [Nat; _]|(
|
||||||
self: .NDArray(T, Old),
|
self: .NDArray(T, Old),
|
||||||
shape: {S},
|
shape: {S},
|
||||||
) -> .NDArray(T, 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
|
||||||
.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)
|
.add: |T, S: [Nat; _]|(object: .NDArray(T, S), other: .NDArray(T, S)) -> .NDArray(T, S)
|
||||||
.all: |T <: Num|(object: .NDArray(T),) -> Bool
|
.all: |T <: Num|(object: .NDArray(T),) -> Bool
|
||||||
.any: |T <: Num|(object: .NDArray(T),) -> Bool
|
.any: |T <: Num|(object: .NDArray(T),) -> Bool
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
.Tqdm! = 'tqdm': (T: Type) -> ClassType
|
.Tqdm! = 'tqdm': (T: Type) -> ClassType
|
||||||
.Tqdm!(T) <: Iterable T
|
.Tqdm!(T) <: Iterable T
|
||||||
.Tqdm!(T).
|
.Tqdm!(T).
|
||||||
# TODO: iterable should be Comparable
|
|
||||||
__call__: (
|
__call__: (
|
||||||
iterable: Iterable(T),
|
iterable: Iterable(T),
|
||||||
desc := Str,
|
desc := Str,
|
||||||
|
@ -30,3 +29,5 @@
|
||||||
delay := Float,
|
delay := Float,
|
||||||
gui := Bool,
|
gui := Bool,
|
||||||
) -> .Tqdm!(T)
|
) -> .Tqdm!(T)
|
||||||
|
|
||||||
|
.tqdm = .Tqdm!.__call__
|
||||||
|
|
|
@ -4406,6 +4406,18 @@ impl VarPattern {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn escaped(&self) -> Option<Str> {
|
||||||
|
match self {
|
||||||
|
Self::Ident(ident) => {
|
||||||
|
let inspect = ident.inspect();
|
||||||
|
Some(Str::rc(
|
||||||
|
inspect.trim_end_matches('!').trim_start_matches('$'),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// _!(...) = ... is invalid
|
// _!(...) = ... is invalid
|
||||||
pub fn is_procedural(&self) -> bool {
|
pub fn is_procedural(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
|
@ -4502,6 +4514,10 @@ impl VarSignature {
|
||||||
self.pat.inspect()
|
self.pat.inspect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn escaped(&self) -> Option<Str> {
|
||||||
|
self.pat.escaped()
|
||||||
|
}
|
||||||
|
|
||||||
pub const fn vis(&self) -> &VisModifierSpec {
|
pub const fn vis(&self) -> &VisModifierSpec {
|
||||||
self.pat.vis()
|
self.pat.vis()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
time = pyimport "time"
|
time = pyimport "time"
|
||||||
tqdm = pyimport "tqdm"
|
tqdm = pyimport "tqdm"
|
||||||
j2 = pyimport "jinja2"
|
j2 = pyimport "jinja2"
|
||||||
|
np = pyimport "numpy"
|
||||||
|
|
||||||
for! tqdm.Tqdm!(0..<100), _ =>
|
for! tqdm.Tqdm!(0..<100), _ =>
|
||||||
time.sleep! 0.01
|
time.sleep! 0.01
|
||||||
|
for! tqdm.tqdm(0..<100), _ =>
|
||||||
|
time.sleep! 0.01
|
||||||
|
|
||||||
plt = pyimport "matplotlib/pyplot"
|
plt = pyimport "matplotlib/pyplot"
|
||||||
|
|
||||||
|
@ -14,3 +17,6 @@ plt.show!()
|
||||||
|
|
||||||
res = j2.Template("Hello {{ name }}!").render(name:="World")
|
res = j2.Template("Hello {{ name }}!").render(name:="World")
|
||||||
assert res == "Hello World!"
|
assert res == "Hello World!"
|
||||||
|
|
||||||
|
arr = np.array([1, 2, 3])
|
||||||
|
assert arr.sum() == 6
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue