mirror of https://github.com/mtshiba/pylyzer
fix: false positive name errors
This commit is contained in:
parent
55d44bc5a4
commit
8cf472f469
|
|
@ -136,9 +136,9 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "els"
|
name = "els"
|
||||||
version = "0.1.53"
|
version = "0.1.54-nightly.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "97104e067d1a4432a49a18da26af10a0f51d8d99f69e46aeb9890440f6a36457"
|
checksum = "4fb27dc0754e2490b8984d95f4fe6368258de544eedd37798a314acfeb5ccfc6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
|
|
@ -150,9 +150,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_common"
|
name = "erg_common"
|
||||||
version = "0.6.41"
|
version = "0.6.42-nightly.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3868e184db0bb4a69538aa0744f6b19e51c43233f5369f8e7e114c263b9ff996"
|
checksum = "415899164e7873f66eecad5ad37683c5fa31c038802033f35ad08f3fa38882dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace-on-stack-overflow",
|
"backtrace-on-stack-overflow",
|
||||||
"erg_proc_macros",
|
"erg_proc_macros",
|
||||||
|
|
@ -162,9 +162,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_compiler"
|
name = "erg_compiler"
|
||||||
version = "0.6.41"
|
version = "0.6.42-nightly.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f7fcd5809b7797e85a87555cbe5d79580749a8b9ba8edf0ac7a422ad90c67793"
|
checksum = "048b3d74d5ca2c5279e18f15fd5997fe0cdfcad0a8d6ff2e4e238a8b76d86b36"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_parser",
|
"erg_parser",
|
||||||
|
|
@ -172,9 +172,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_parser"
|
name = "erg_parser"
|
||||||
version = "0.6.41"
|
version = "0.6.42-nightly.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f986e2ca5c640c39083fcfe97009f11138458b1f1e3aa17595c81e9ae9e33d0"
|
checksum = "ca774922a3555cb1973ead24f9ad27056057480bbcfff2ccab0b8b3637517054"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_proc_macros",
|
"erg_proc_macros",
|
||||||
|
|
@ -183,9 +183,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_proc_macros"
|
name = "erg_proc_macros"
|
||||||
version = "0.6.41"
|
version = "0.6.42-nightly.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e828d1dcb5ee351dcba9707a8ecd46e9ba510367595e922a26528fa0d2853920"
|
checksum = "a7500b1a02978ccf36cef9eecb31f99911a0b56753589e375f0a51b6ff57b750"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ edition = "2021"
|
||||||
repository = "https://github.com/mtshiba/pylyzer"
|
repository = "https://github.com/mtshiba/pylyzer"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
erg_common = { version = "0.6.41", features = ["py_compat", "els"] }
|
erg_common = { version = "0.6.42-nightly.0", features = ["py_compat", "els"] }
|
||||||
erg_compiler = { version = "0.6.41", features = ["py_compat", "els"] }
|
erg_compiler = { version = "0.6.42-nightly.0", features = ["py_compat", "els"] }
|
||||||
els = { version = "0.1.53", features = ["py_compat"] }
|
els = { version = "0.1.54-nightly.0", features = ["py_compat"] }
|
||||||
# rustpython-parser = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] }
|
# 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-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"] }
|
rustpython-parser = { git = "https://github.com/RustPython/Parser", version = "0.4.0", features = ["all-nodes-with-ranges", "location"] }
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,6 @@ On average, pylyzer can inspect Python scripts more than __100 times faster__ th
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
* 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.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
* Reports readability 📖
|
* Reports readability 📖
|
||||||
|
|
||||||
While pytype/pyright's error reports are illegible, pylyzer shows where the error occurred and provides clear error messages.
|
While pytype/pyright's error reports are illegible, pylyzer shows where the error occurred and provides clear error messages.
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,19 @@ pub(crate) fn filter_errors(ctx: &ModuleContext, errors: CompileErrors) -> Compi
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_name_error(error: CompileError) -> Option<CompileError> {
|
||||||
|
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<CompileError> {
|
fn filter_error(_ctx: &ModuleContext, mut error: CompileError) -> Option<CompileError> {
|
||||||
match error.core.kind {
|
match error.core.kind {
|
||||||
ErrorKind::FeatureError => {
|
ErrorKind::FeatureError => {
|
||||||
|
|
@ -39,7 +52,7 @@ fn filter_error(_ctx: &ModuleContext, mut error: CompileError) -> Option<Compile
|
||||||
Some(error)
|
Some(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ErrorKind::AssignError => handle_assign_error(error),
|
ErrorKind::NameError | ErrorKind::AssignError => handle_name_error(error),
|
||||||
_ => Some(error),
|
_ => Some(error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
l = [1, 2, 3]
|
l = [1, 2, 3]
|
||||||
_ = l[1:2]
|
_ = l[1:2]
|
||||||
print(l[4]) # ERR
|
print(l[2])
|
||||||
|
print(l["a"]) # ERR
|
||||||
|
|
||||||
# OK
|
# OK
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
print(l[i])
|
print(l[i])
|
||||||
# ERR
|
# ERR
|
||||||
for i in range(4):
|
for i in "abcd":
|
||||||
print(l[i])
|
print(l[i])
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,9 @@ def f(x: int | None):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
f(1)
|
f(1)
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
x: Optional[int] = None
|
||||||
|
if x is not None:
|
||||||
|
x += 1
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,28 @@ while False:
|
||||||
def f(x: int):
|
def f(x: int):
|
||||||
i = 1 # OK
|
i = 1 # OK
|
||||||
return x + i
|
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
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,6 @@ def f(d1, d2: dict[str, int]):
|
||||||
_ = d2[1] # ERR
|
_ = d2[1] # ERR
|
||||||
dic = {"a": 1}
|
dic = {"a": 1}
|
||||||
_ = dic["b"] # ERR
|
_ = dic["b"] # ERR
|
||||||
arr = [1, 2, 3]
|
|
||||||
_ = arr[4] # ERR
|
|
||||||
for i in range(4):
|
|
||||||
print(arr[i]) # ERR
|
|
||||||
|
|
||||||
i, j = 1, 2
|
i, j = 1, 2
|
||||||
assert i == 1
|
assert i == 1
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ pub fn expect(file_path: &'static str, warns: usize, errors: usize) -> Result<()
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exec_test() -> Result<(), String> {
|
fn exec_test() -> Result<(), String> {
|
||||||
expect("tests/test.py", 0, 13)
|
expect("tests/test.py", 0, 11)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue