<#19751 `# pants: no-infer-dep` not always respect...
# github-notifications
c
#19751 `# pants: no-infer-dep` not always respected by the 2.17 Rust parser Issue created by lowvoltage Describe the bug The new Rust inference parser disrespects a
# pants: no-infer-dep
on a conditional import:
Copy code
if TYPE_CHECKING:
    from a import ClassA  # pants: no-infer-dep
Dependencies' diff below:
Copy code
❯ pants --python-infer-no-use-rust-parser peek main.py
[
  {
    "address": "//main.py",
    "target_type": "python_source",
    "dependencies": [],
    "dependencies_raw": null,
Copy code
❯ pants --python-infer-use-rust-parser peek main.py
[
  {
    "address": "//main.py",
    "target_type": "python_source",
    "dependencies": [
      "//a.py"
    ],
    "dependencies_raw": null,
    "description": null,
Note and workarounds This seems to break only when
# pants: no-infer-dep
is on the last line inside the
if
block: • With mulitple import statements, only the last one is handled incorrectly • A multiline import seems to work fine
Copy code
from a import (
        ClassA,  # pants: no-infer-dep
    )
• A placeholder
pass
statement at the end of the
if TYPE_CHECKING
block also results in a correct behavior Pants version 2.17.0 OS Both: MacOS and Linux Additional info Minimalist setup to reproduce
main.py
Copy code
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from a import ClassA  # pants: no-infer-dep

print('Hello, world!')
a.py
Copy code
class ClassA:
    pass
pants.toml
Copy code
[GLOBAL]
pants_version = "2.17.0"
backend_packages = ["pants.backend.python"]

[python]
interpreter_constraints = ["==3.9.*"]
BUILD
Copy code
python_sources()
pantsbuild/pants