cool-easter-32542
09/01/2023, 1:29 PM# pants: no-infer-dep on a conditional import:
if TYPE_CHECKING:
from a import ClassA # pants: no-infer-dep
Dependencies' diff below:
❯ pants --python-infer-no-use-rust-parser peek main.py
[
{
"address": "//main.py",
"target_type": "python_source",
"dependencies": [],
"dependencies_raw": null,
❯ 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
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
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from a import ClassA # pants: no-infer-dep
print('Hello, world!')
a.py
class ClassA:
pass
pants.toml
[GLOBAL]
pants_version = "2.17.0"
backend_packages = ["pants.backend.python"]
[python]
interpreter_constraints = ["==3.9.*"]
BUILD
python_sources()
pantsbuild/pantscool-easter-32542
09/08/2023, 10:11 PM