cool-easter-32542
03/10/2025, 6:26 PM[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`:
@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:
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.
[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/pantscool-easter-32542
03/10/2025, 6:26 PM