Skip to content

Commit

Permalink
fix: minor bugs
Browse files Browse the repository at this point in the history
update deps
  • Loading branch information
mtshiba committed Sep 26, 2024
1 parent a1ffcf0 commit 702df27
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ edition = "2021"
repository = "https://github.com/mtshiba/pylyzer"

[workspace.dependencies]
erg_common = { version = "0.6.45-nightly.0", features = ["py_compat", "els"] }
erg_compiler = { version = "0.6.45-nightly.0", features = ["py_compat", "els"] }
els = { version = "0.1.57-nightly.0", features = ["py_compat"] }
erg_common = { version = "0.6.45-nightly.2", features = ["py_compat", "els"] }
erg_compiler = { version = "0.6.45-nightly.2", features = ["py_compat", "els"] }
els = { version = "0.1.57-nightly.2", 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"] }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pylyzer converts Python ASTs to Erg ASTs and passes them to Erg's type checker.
* [x] `Callable`
* [ ] `TypedDict`
* [x] `TypeVar`
* [ ] `ClassVar`
* [ ] `Generic`
* [ ] `Protocol`
* [ ] `Final`
Expand Down
6 changes: 5 additions & 1 deletion crates/py2erg/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl ASTConverter {
name_info.defined_in = DefinedPlace::Known(cur_namespace);
name_info.defined_times += 1; // 0 -> 1
}
if name_info.defined_block_id == cur_block_id {
if name_info.defined_block_id == cur_block_id || name_info.defined_times == 0 {
CanShadow::Yes
} else {
CanShadow::No
Expand Down Expand Up @@ -1388,6 +1388,10 @@ impl ASTConverter {
);
method.call1(self.convert_expr(*subs.slice))
}
// [start:] == [slice(start, None)]
// [:stop] == [slice(stop)]
// [start:stop] == [slice(start, stop)]
// [start:stop:step] == [slice(start, stop, step)]
py_ast::Expr::Slice(slice) => {
let loc = slice.location();
let start = slice.lower.map(|ex| self.convert_expr(*ex));
Expand Down
1 change: 1 addition & 0 deletions tests/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ def f(s: Str): return None
assert 1 in {1, 2}
assert 1 in {1: "a"}
assert 1 in (1, 2)
assert 1 in map(lambda x: x + 1, [0, 1, 2])
11 changes: 11 additions & 0 deletions tests/decl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
i: int
if True:
i = 1
else:
i = 2

j: int
if True:
j = "1" # ERR
else:
j = "2"
10 changes: 10 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use pylyzer_core::PythonAnalyzer;
pub fn exec_analyzer(file_path: &'static str) -> Result<CompleteArtifact, IncompleteArtifact> {
let cfg = ErgConfig {
input: Input::file(PathBuf::from(file_path)),
effect_check: false,
ownership_check: false,
..Default::default()
};
let mut analyzer = PythonAnalyzer::new(cfg);
Expand All @@ -21,6 +23,7 @@ fn _expect(file_path: &'static str, warns: usize, errors: usize) -> Result<(), S
match exec_analyzer(file_path) {
Ok(artifact) => {
if artifact.warns.len() != warns {
eprintln!("warns: {}", artifact.warns);
return Err(format!(
"Expected {warns} warnings, found {}",
artifact.warns.len()
Expand All @@ -33,12 +36,14 @@ fn _expect(file_path: &'static str, warns: usize, errors: usize) -> Result<(), S
}
Err(artifact) => {
if artifact.warns.len() != warns {
eprintln!("warns: {}", artifact.warns);
return Err(format!(
"Expected {warns} warnings, found {}",
artifact.warns.len()
));
}
if artifact.errors.len() != errors {
eprintln!("errors: {}", artifact.errors);
return Err(format!(
"Expected {errors} errors, found {}",
artifact.errors.len()
Expand Down Expand Up @@ -137,6 +142,11 @@ fn exec_call() -> Result<(), String> {
expect("tests/call.py", 0, 6)
}

#[test]
fn exec_decl() -> Result<(), String> {
expect("tests/decl.py", 0, 1)
}

#[test]
fn exec_shadowing() -> Result<(), String> {
expect("tests/shadowing.py", 0, 3)
Expand Down
4 changes: 4 additions & 0 deletions tests/union.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@

def f(x: str | bytes):
return x.isalnum()

def check(s: str | bytes | bytearray):
if isinstance(s, (bytes, bytearray)):
pass

0 comments on commit 702df27

Please sign in to comment.