<#20324 [Python] The Pants Rust inference parser e...
# github-notifications
c
#20324 [Python] The Pants Rust inference parser exhibits some dependency misinterpretation issues when python-infer.string_imports is enabled. Issue created by liudonggalaxy ## Maintainer summary • find tree sitter incantantion required to handle concatenated strings with
[python-infer].string_imports
. (issue 1 in the orginal report) • strings that is not a valid python identifier:
a.b.
(issue 2 in original report) • Other strings that are not valid python identifiers
retrying...
(issue 3 in the orginal report) • Other strings that are not valid python identifiers (
.
,
..
, etc) (issue reported in comments) ## Original report Describe the bug The Pants
Rust
inference parser exhibits some dependency misinterpretation issues when
python-infer.string_imports
is enabled. This is evident in the following examples: 1. The Rust parser in Pants could not infer dependencies across multiple lines correctly. In the following example, the Rust parser identifies
a.b
as a dependency, whereas the classic parser correctly discerns `a.b.c.d`:
Copy code
@mock.patch(
    'a.b.' 
    'c.d', 
    new=mock.PropertyMock(return_value=0.7))
1. For the string
BASE_PATH = 'a.b.'
, the Rust parser mistakenly treats it as a dependency, unlike the classic parser. 2. In
print('retrying...')
, the Rust parser incorrectly interprets it as a dependency, while the classic parser does not. To compare the Rust and classic parsers, the following commands were executed on both MacOS and Linux:
Copy code
mkdir -p pants_inference
pants --python-infer-no-use-rust-parser peek :: > pants_inference/classic_parser.json
pants --python-infer-use-rust-parser peek :: > pants_inference/rust_parser.json
diff pants_inference/classic_parser.json pants_inference/rust_parser.json
Here is the pants configuration in pants.toml.
Copy code
[python-infer]
unowned_dependency_behavior = "error"
use_rust_parser = true
string_imports = true  # Infer a target's dependencies based on strings that look like dynamic dependencies
Pants version 2.17.0 OS Both MacOS and Linux. Additional info pantsbuild/pants