From 439ba1d28e13376d0590f0f4c7bfdf570d104879 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sat, 18 Nov 2023 17:06:22 +0900 Subject: [PATCH] feat: make`tqdm.Tqdm!` polymorphic --- .github/workflows/docs.yml | 1 + crates/erg_compiler/context/inquire.rs | 6 +++++- .../lib/external/tqdm.d/__init__.d.er | 10 +++++----- doc/scripts/sync_to_translation_status.er | 15 ++++++++------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6e67bd9b6..df9eb4bf5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -19,6 +19,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: "3.11" + - run: pip install tqdm - uses: erg-lang/setup-erg@v2.1 - run: | git config user.name github-actions[bot] diff --git a/crates/erg_compiler/context/inquire.rs b/crates/erg_compiler/context/inquire.rs index e94a38956..9b92360e4 100644 --- a/crates/erg_compiler/context/inquire.rs +++ b/crates/erg_compiler/context/inquire.rs @@ -2228,7 +2228,11 @@ impl Context { "{instance} is quantified subr" ); log!(info "Substituted:\ninstance: {instance}"); - debug_assert!(instance.has_no_qvar(), "{instance} has qvar"); + debug_assert!( + instance.is_type() || instance.has_no_qvar(), + "{instance} has qvar (obj: {obj}, attr: {}", + fmt_option!(attr_name) + ); if let Some((expected, instance)) = expected_return.zip(instance.return_t()) { let _res = self.sub_unify(instance, expected, obj, None); } diff --git a/crates/erg_compiler/lib/external/tqdm.d/__init__.d.er b/crates/erg_compiler/lib/external/tqdm.d/__init__.d.er index e2ec12b0a..9714d9aed 100644 --- a/crates/erg_compiler/lib/external/tqdm.d/__init__.d.er +++ b/crates/erg_compiler/lib/external/tqdm.d/__init__.d.er @@ -1,9 +1,9 @@ -.Tqdm! = 'tqdm': ClassType -.Tqdm! <: Iterable Int -.Tqdm!. +.Tqdm! = 'tqdm': (T: Type) -> ClassType +.Tqdm!(T) <: Iterable T +.Tqdm!(T). # TODO: iterable should be Comparable __call__: ( - iterable: Iterable(Int), + iterable: Iterable(T), desc := Str, total := Int or Float, leave := Bool, @@ -29,4 +29,4 @@ colour := Str, delay := Float, gui := Bool, - ) -> .Tqdm! + ) -> .Tqdm!(T) diff --git a/doc/scripts/sync_to_translation_status.er b/doc/scripts/sync_to_translation_status.er index 314bfa14f..13d8a184a 100644 --- a/doc/scripts/sync_to_translation_status.er +++ b/doc/scripts/sync_to_translation_status.er @@ -2,6 +2,7 @@ os = pyimport "os" re = pyimport "re" mylib = pyimport "mylib" # TODO: Make it work without this +tqdm = pyimport "tqdm" LANGUAGES_KEBAB_CASE = ["JA", "zh-TW", "zh-CN"] @@ -14,8 +15,8 @@ cwd = os.getcwd!() badge_pattern = re.compile("\\[!\\[badge\\]\\(([\\w.,@?^=%&:\\/~+#-]+)\\)\\]\\(([\\w.,@?^=%&:\\/~+#-]+)\\)") -get_bedge! file_path = - if! os.path.exists!(file_path): +get_badge! file_path = + if! os.path.exists!(file_path) and os.path.isfile!(file_path): do!: with! open!(file_path, encoding := "utf-8"), f => badge_match = badge_pattern.search(f.read!()) @@ -55,13 +56,13 @@ for! LANGUAGES_KEBAB_CASE, lang => add_table_row_text! "EN file name", "edit icon and badge" add_table_row_text! "---", "---" - add_table_row_text! "[README.md](../../README.md)", "[📝](../../README_\{lang}.md) \{get_bedge!(mylib.path_join(cwd, "../README_\{lang}.md"))}" - add_table_row_text! "[CODE_OF_CONDUCT.md](../../CODE_OF_CONDUCT.md)", "[📝](../CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md) \{get_bedge!(mylib.path_join(cwd, "./CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md"))}" - add_table_row_text! "[CONTRIBUTING.md](../../CONTRIBUTING.md)", "[📝](../CONTRIBUTING/CONTRIBUTING_\{lang}.md) \{get_bedge!(mylib.path_join(cwd, "./CONTRIBUTING/CONTRIBUTING_\{lang}.md"))}" + add_table_row_text! "[README.md](../../README.md)", "[📝](../../README_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "../README_\{lang}.md"))}" + add_table_row_text! "[CODE_OF_CONDUCT.md](../../CODE_OF_CONDUCT.md)", "[📝](../CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "./CODE_OF_CONDUCT/CODE_OF_CONDUCT_\{lang}.md"))}" + add_table_row_text! "[CONTRIBUTING.md](../../CONTRIBUTING.md)", "[📝](../CONTRIBUTING/CONTRIBUTING_\{lang}.md) \{get_badge!(mylib.path_join(cwd, "./CONTRIBUTING/CONTRIBUTING_\{lang}.md"))}" - for! doc_en_file_paths, en_path => + for! tqdm.Tqdm!(doc_en_file_paths), en_path => relative_file_path = "\{lang.replace "-", "_"}\{mylib.str_slice en_path, 2}" - add_table_row_text! "[\{mylib.str_slice en_path, 3}](../\{en_path})", "[📝](../\{relative_file_path}) \{get_bedge!(mylib.path_join(cwd, relative_file_path))}" + add_table_row_text! "[\{mylib.str_slice en_path, 3}](../\{en_path})", "[📝](../\{relative_file_path}) \{get_badge!(mylib.path_join(cwd, relative_file_path))}" with! open!(mylib.path_join(cwd, mylib.path_join("translation_status", "translation_status_\{lang}.md")), encoding := "utf-8", mode := "w"), f => discard f.write! str(result_text)