Skip to content

Commit 21caf6f

Browse files
authored
Merge pull request #526 from GreasySlug/feat-pathlib
Add glob! and resolve! Methods in Pathlib.d.er
2 parents 6890d82 + a2e8ba4 commit 21caf6f

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

crates/erg_compiler/context/initialize/classes.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -4045,10 +4045,14 @@ impl Context {
40454045
Immutable,
40464046
Visibility::BUILTIN_PRIVATE,
40474047
);
4048-
let mut g_generator = Self::builtin_mono_class(GENERIC_GENERATOR, 2);
4049-
g_generator.register_superclass(mono(SUBROUTINE), &subr);
4050-
let t_yield = fn1_met(mono(GENERIC_GENERATOR), Obj, Never).quantify();
4051-
g_generator.register_builtin_erg_impl(
4048+
let generator_t = poly(GENERATOR, vec![ty_tp(T.clone())]);
4049+
let mut generator = Self::builtin_poly_class(GENERATOR, vec![PS::t_nd(TY_T)], 2);
4050+
generator.register_superclass(mono(SUBROUTINE), &subr);
4051+
generator
4052+
.register_trait(self, poly(ITERATOR, vec![ty_tp(T.clone())]))
4053+
.unwrap();
4054+
let t_yield = fn1_met(generator_t.clone(), T.clone(), Never).quantify();
4055+
generator.register_builtin_erg_impl(
40524056
FUNC_YIELD,
40534057
t_yield,
40544058
Immutable,
@@ -4674,13 +4678,7 @@ impl Context {
46744678
self.register_builtin_type(dict_mut_t, dict_mut, vis.clone(), Const, Some(DICT));
46754679
self.register_builtin_type(set_mut_t, set_mut_, vis.clone(), Const, Some(SET));
46764680
self.register_builtin_type(mono(SUBROUTINE), subr, vis.clone(), Const, Some(SUBROUTINE));
4677-
self.register_builtin_type(
4678-
mono(GENERIC_GENERATOR),
4679-
g_generator,
4680-
vis.clone(),
4681-
Const,
4682-
Some(GENERATOR),
4683-
);
4681+
self.register_builtin_type(generator_t, generator, vis.clone(), Const, Some(GENERATOR));
46844682
self.register_builtin_type(dimension_t, dimension, vis.clone(), Const, Some(DIMENSION));
46854683
self.register_builtin_type(
46864684
mono(BASE_EXCEPTION),

crates/erg_compiler/context/initialize/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ const PROC_INVERT: &str = "invert!";
352352
const RANGE: &str = "Range";
353353
const GENERIC_CALLABLE: &str = "GenericCallable";
354354
const SUBROUTINE: &str = "Subroutine";
355-
const GENERIC_GENERATOR: &str = "GenericGenerator";
356355
const FUNC_RETURN: &str = "return";
357356
const FUNC_YIELD: &str = "yield";
358357
const PROC: &str = "Proc";

crates/erg_compiler/lib/pystd/pathlib.d.er

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@
4545
chmod!: (self: .Path, mode: Nat) => NoneType
4646
exists!: (self: .Path) => Bool
4747
expanduser!: (self: .Path) => .Path
48+
glob!: (self: .Path, pattern: Str) => Generator .Path
4849
home!: () => .Path
49-
iterdir!: (self: .Path) => Iterable .Path
50+
iterdir!: (self: .Path) => Generator .Path
5051
joinpath: (self: .Path, *other: PathLike) -> .Path
5152
mkdir!: (self: .Path, mode := Nat, parents := Bool, exist_ok := Bool) => NoneType
5253
open!: (self: .Path, mode := Str) => File!
5354
rmdir!: (self: .Path) => NoneType
5455
read_bytes!: (self: .Path) => Bytes
5556
read_text!: (self: .Path, encoding := Str, errors := Str) => Str
5657
rename!: (self: .Path, target: PathLike) => NoneType
58+
resolve!: (self: .Path, strict := Bool) => .Path
5759
samefile!: (self: .Path, other: PathLike) => Bool
5860
touch!: (self: .Path, mode := Nat, exist_ok := Bool) => NoneType
5961
unlink!: (self: .Path, missing_ok := Bool) => NoneType

0 commit comments

Comments
 (0)