mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-27 18:36:35 +00:00
[ty] add legacy namespace package support (#20897)
Some checks are pending
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / mkdocs (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (macos) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / ty completion evaluation (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks walltime (medium|multithreaded) (push) Blocked by required conditions
CI / benchmarks walltime (small|large) (push) Blocked by required conditions
Some checks are pending
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / mkdocs (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (macos) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / ty completion evaluation (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks walltime (medium|multithreaded) (push) Blocked by required conditions
CI / benchmarks walltime (small|large) (push) Blocked by required conditions
Detect legacy namespace packages and treat them like namespace packages when looking them up as the *parent* of the module we're interested in. In all other cases treat them like a regular package. (This PR is coauthored by @MichaReiser in a shared coding session) Fixes https://github.com/astral-sh/ty/issues/838 --------- Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
96b156303b
commit
64edfb6ef6
2 changed files with 405 additions and 2 deletions
|
|
@ -0,0 +1,221 @@
|
|||
# Legacy namespace packages
|
||||
|
||||
## `__import__("pkgutil").extend_path`
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
extra-paths = ["/airflow-core/src", "/providers/amazon/src/"]
|
||||
```
|
||||
|
||||
`/airflow-core/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
||||
__version__ = "3.2.0"
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/amazon/__init__.py`:
|
||||
|
||||
```py
|
||||
__version__ = "9.15.0"
|
||||
```
|
||||
|
||||
`test.py`:
|
||||
|
||||
```py
|
||||
from airflow import __version__ as airflow_version
|
||||
from airflow.providers.amazon import __version__ as amazon_provider_version
|
||||
|
||||
reveal_type(airflow_version) # revealed: Literal["3.2.0"]
|
||||
reveal_type(amazon_provider_version) # revealed: Literal["9.15.0"]
|
||||
```
|
||||
|
||||
## `pkgutil.extend_path`
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
extra-paths = ["/airflow-core/src", "/providers/amazon/src/"]
|
||||
```
|
||||
|
||||
`/airflow-core/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
import pkgutil
|
||||
|
||||
__path__ = pkgutil.extend_path(__path__, __name__)
|
||||
__version__ = "3.2.0"
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
import pkgutil
|
||||
|
||||
__path__ = pkgutil.extend_path(__path__, __name__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/__init__.py`:
|
||||
|
||||
```py
|
||||
import pkgutil
|
||||
|
||||
__path__ = pkgutil.extend_path(__path__, __name__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/amazon/__init__.py`:
|
||||
|
||||
```py
|
||||
__version__ = "9.15.0"
|
||||
```
|
||||
|
||||
`test.py`:
|
||||
|
||||
```py
|
||||
from airflow import __version__ as airflow_version
|
||||
from airflow.providers.amazon import __version__ as amazon_provider_version
|
||||
|
||||
reveal_type(airflow_version) # revealed: Literal["3.2.0"]
|
||||
reveal_type(amazon_provider_version) # revealed: Literal["9.15.0"]
|
||||
```
|
||||
|
||||
## `extend_path` with keyword arguments
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
extra-paths = ["/airflow-core/src", "/providers/amazon/src/"]
|
||||
```
|
||||
|
||||
`/airflow-core/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
import pkgutil
|
||||
|
||||
__path__ = pkgutil.extend_path(name=__name__, path=__path__)
|
||||
__version__ = "3.2.0"
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
import pkgutil
|
||||
|
||||
__path__ = pkgutil.extend_path(name=__name__, path=__path__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/__init__.py`:
|
||||
|
||||
```py
|
||||
import pkgutil
|
||||
|
||||
__path__ = pkgutil.extend_path(name=__name__, path=__path__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/amazon/__init__.py`:
|
||||
|
||||
```py
|
||||
__version__ = "9.15.0"
|
||||
```
|
||||
|
||||
`test.py`:
|
||||
|
||||
```py
|
||||
from airflow import __version__ as airflow_version
|
||||
from airflow.providers.amazon import __version__ as amazon_provider_version
|
||||
|
||||
reveal_type(airflow_version) # revealed: Literal["3.2.0"]
|
||||
reveal_type(amazon_provider_version) # revealed: Literal["9.15.0"]
|
||||
```
|
||||
|
||||
## incorrect `__import__` arguments
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
extra-paths = ["/airflow-core/src", "/providers/amazon/src/"]
|
||||
```
|
||||
|
||||
`/airflow-core/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("not_pkgutil").extend_path(__path__, __name__)
|
||||
__version__ = "3.2.0"
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("not_pkgutil").extend_path(__path__, __name__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("not_pkgutil").extend_path(__path__, __name__)
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/amazon/__init__.py`:
|
||||
|
||||
```py
|
||||
__version__ = "9.15.0"
|
||||
```
|
||||
|
||||
`test.py`:
|
||||
|
||||
```py
|
||||
from airflow.providers.amazon import __version__ as amazon_provider_version # error: [unresolved-import]
|
||||
from airflow import __version__ as airflow_version
|
||||
|
||||
reveal_type(airflow_version) # revealed: Literal["3.2.0"]
|
||||
```
|
||||
|
||||
## incorrect `extend_path` arguments
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
extra-paths = ["/airflow-core/src", "/providers/amazon/src/"]
|
||||
```
|
||||
|
||||
`/airflow-core/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("pkgutil").extend_path(__path__, "other_module")
|
||||
__version__ = "3.2.0"
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("pkgutil").extend_path(__path__, "other_module")
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/__init__.py`:
|
||||
|
||||
```py
|
||||
__path__ = __import__("pkgutil").extend_path(__path__, "other_module")
|
||||
```
|
||||
|
||||
`/providers/amazon/src/airflow/providers/amazon/__init__.py`:
|
||||
|
||||
```py
|
||||
__version__ = "9.15.0"
|
||||
```
|
||||
|
||||
`test.py`:
|
||||
|
||||
```py
|
||||
from airflow.providers.amazon import __version__ as amazon_provider_version # error: [unresolved-import]
|
||||
from airflow import __version__ as airflow_version
|
||||
|
||||
reveal_type(airflow_version) # revealed: Literal["3.2.0"]
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue