bazel-contrib / bazel-contrib/rules_python

Gazelle will confuse stdlib packages/modules with sibling modules

Aperta
#3,097 1 commento 0 reazioni 1 assegnatario Rivendicata da @dougthor42 Vedi su GitHub
gazelle
Lingua principale
Starlark
Stelle
688
Fork
721
Merge medio
15h 7m
PR unite (30g)
76

Descrizione

# 🐞 bug report

### Affected Rule

gazelle

### Is this a regression?

It's been like this for as long as I've been using rules_python.

### Description

If there's a file called, say, `typing.py` and a sibling file `foo.py` has `from typing import TYPE_CHECKING` or similar, gazelle will add `:typing` to the `foo` target deps (or to the package `srcs` for package generation mode).

The correct behavior is to _not_ include `:typing` unless the import is `from . import typing` or `from .typing import MyType` or `import .typing as typing`.

## πŸ”¬ Minimal Reproduction

Dir structure:

```
$ tree gazelle/python/testdata/stdlib_confusion/
gazelle/python/testdata/stdlib_confusion/
β”œβ”€β”€ file_based
β”‚   β”œβ”€β”€ BUILD.in
β”‚   β”œβ”€β”€ BUILD.out
β”‚   β”œβ”€β”€ foo.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── typing.py
β”œβ”€β”€ package_based
β”‚   β”œβ”€β”€ BUILD.in
β”‚   β”œβ”€β”€ BUILD.out
β”‚   β”œβ”€β”€ foo.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── typing.py
β”œβ”€β”€ README.md
β”œβ”€β”€ test.yaml
└── WORKSPACE
```

```
--- FAIL: TestGazelleBinary (0.00s)
--- FAIL: TestGazelleBinary/stdlib_confusion (0.02s)
python_test.go:186: stdlib_confusion/file_based/BUILD diff (-want,+got):
  (
   """
   ... // 6 identical lines
   srcs = ["foo.py"],
   visibility = ["//:__subpackages__"],
+  deps = [":typing"],
   )
  
   ... // 5 identical lines
   """
  )
python_test.go:186: stdlib_confusion/package_based/BUILD diff (-want,+got):
  (
   """
   ... // 5 identical lines
   "__init__.py",
   "foo.py",
+  "typing.py",
   ],
   visibility = ["//:__subpackages__"],
   )
   """
  )
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non Γ¨ ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.