diff --git a/Cargo.lock b/Cargo.lock index 8e8ea49..fcbf093 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,9 +136,9 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "els" -version = "0.1.53" +version = "0.1.54-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97104e067d1a4432a49a18da26af10a0f51d8d99f69e46aeb9890440f6a36457" +checksum = "4fb27dc0754e2490b8984d95f4fe6368258de544eedd37798a314acfeb5ccfc6" dependencies = [ "erg_common", "erg_compiler", @@ -150,9 +150,9 @@ dependencies = [ [[package]] name = "erg_common" -version = "0.6.41" +version = "0.6.42-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3868e184db0bb4a69538aa0744f6b19e51c43233f5369f8e7e114c263b9ff996" +checksum = "415899164e7873f66eecad5ad37683c5fa31c038802033f35ad08f3fa38882dc" dependencies = [ "backtrace-on-stack-overflow", "erg_proc_macros", @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "erg_compiler" -version = "0.6.41" +version = "0.6.42-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fcd5809b7797e85a87555cbe5d79580749a8b9ba8edf0ac7a422ad90c67793" +checksum = "048b3d74d5ca2c5279e18f15fd5997fe0cdfcad0a8d6ff2e4e238a8b76d86b36" dependencies = [ "erg_common", "erg_parser", @@ -172,9 +172,9 @@ dependencies = [ [[package]] name = "erg_parser" -version = "0.6.41" +version = "0.6.42-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f986e2ca5c640c39083fcfe97009f11138458b1f1e3aa17595c81e9ae9e33d0" +checksum = "ca774922a3555cb1973ead24f9ad27056057480bbcfff2ccab0b8b3637517054" dependencies = [ "erg_common", "erg_proc_macros", @@ -183,9 +183,9 @@ dependencies = [ [[package]] name = "erg_proc_macros" -version = "0.6.41" +version = "0.6.42-nightly.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e828d1dcb5ee351dcba9707a8ecd46e9ba510367595e922a26528fa0d2853920" +checksum = "a7500b1a02978ccf36cef9eecb31f99911a0b56753589e375f0a51b6ff57b750" dependencies = [ "quote", "syn 1.0.109", diff --git a/Cargo.toml b/Cargo.toml index 9e1b012..b0427de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ edition = "2021" repository = "https://github.com/mtshiba/pylyzer" [workspace.dependencies] -erg_common = { version = "0.6.41", features = ["py_compat", "els"] } -erg_compiler = { version = "0.6.41", features = ["py_compat", "els"] } -els = { version = "0.1.53", features = ["py_compat"] } +erg_common = { version = "0.6.42-nightly.0", features = ["py_compat", "els"] } +erg_compiler = { version = "0.6.42-nightly.0", features = ["py_compat", "els"] } +els = { version = "0.1.54-nightly.0", features = ["py_compat"] } # rustpython-parser = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } # rustpython-ast = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } rustpython-parser = { git = "https://github.com/RustPython/Parser", version = "0.4.0", features = ["all-nodes-with-ranges", "location"] } diff --git a/README.md b/README.md index f112b57..77a436d 100644 --- a/README.md +++ b/README.md @@ -41,12 +41,6 @@ On average, pylyzer can inspect Python scripts more than __100 times faster__ th ![performance](https://raw.githubusercontent.com/mtshiba/pylyzer/main/images/performance.png) -* Detailed analysis 🩺 - -pylyzer can do more than the type checking. For example, it can detect out-of-bounds accesses to lists and accesses to nonexistent keys in dicts. - -![analysis](https://raw.githubusercontent.com/mtshiba/pylyzer/main/images/analysis.png) - * Reports readability 📖 While pytype/pyright's error reports are illegible, pylyzer shows where the error occurred and provides clear error messages. diff --git a/src/handle_err.rs b/src/handle_err.rs index 290ed7f..583a456 100644 --- a/src/handle_err.rs +++ b/src/handle_err.rs @@ -12,6 +12,19 @@ pub(crate) fn filter_errors(ctx: &ModuleContext, errors: CompileErrors) -> Compi .collect() } +fn handle_name_error(error: CompileError) -> Option { + if error.core.main_message.contains("is already declared") + || error + .core + .main_message + .contains("cannot be assigned more than once") + { + None + } else { + Some(error) + } +} + fn filter_error(_ctx: &ModuleContext, mut error: CompileError) -> Option { match error.core.kind { ErrorKind::FeatureError => { @@ -39,7 +52,7 @@ fn filter_error(_ctx: &ModuleContext, mut error: CompileError) -> Option handle_assign_error(error), + ErrorKind::NameError | ErrorKind::AssignError => handle_name_error(error), _ => Some(error), } } diff --git a/tests/list.py b/tests/list.py index 87e6150..2a9ca78 100644 --- a/tests/list.py +++ b/tests/list.py @@ -1,10 +1,11 @@ l = [1, 2, 3] _ = l[1:2] -print(l[4]) # ERR +print(l[2]) +print(l["a"]) # ERR # OK for i in range(3): print(l[i]) # ERR -for i in range(4): +for i in "abcd": print(l[i]) diff --git a/tests/narrowing.py b/tests/narrowing.py index de4b284..812cc65 100644 --- a/tests/narrowing.py +++ b/tests/narrowing.py @@ -7,3 +7,9 @@ def f(x: int | None): return None f(1) + +from typing import Optional + +x: Optional[int] = None +if x is not None: + x += 1 diff --git a/tests/shadowing.py b/tests/shadowing.py index 0c6de7c..61ac34e 100644 --- a/tests/shadowing.py +++ b/tests/shadowing.py @@ -12,3 +12,28 @@ while False: def f(x: int): i = 1 # OK return x + i + +if True: + pass +elif True: + for i in []: pass + pass +elif True: + for i in []: pass + pass + +if True: + pass +elif True: + with open("") as x: + pass + pass +elif True: + with open("") as x: + pass + pass + +if True: + left, right = 1, 2 +if True: + left, _ = 1, 2 diff --git a/tests/test.py b/tests/test.py index da826ad..9b2c359 100644 --- a/tests/test.py +++ b/tests/test.py @@ -36,10 +36,6 @@ def f(d1, d2: dict[str, int]): _ = d2[1] # ERR dic = {"a": 1} _ = dic["b"] # ERR - arr = [1, 2, 3] - _ = arr[4] # ERR - for i in range(4): - print(arr[i]) # ERR i, j = 1, 2 assert i == 1 diff --git a/tests/test.rs b/tests/test.rs index f339b26..da8ee62 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -55,7 +55,7 @@ pub fn expect(file_path: &'static str, warns: usize, errors: usize) -> Result<() #[test] fn exec_test() -> Result<(), String> { - expect("tests/test.py", 0, 13) + expect("tests/test.py", 0, 11) } #[test]