Skip to content

Commit

Permalink
Fix mypy error: Module "ray" does not explicitly export attribute "re…
Browse files Browse the repository at this point in the history
…mote" (ray-project#36334)

ray-project#34730 changed `__all__` in `__init__.py` to a computed list. mypy doesn't support this. Reverting it back to a literal list to fix this issue.

Repro:
`mypy --strict --follow-imports=skip --ignore-missing-imports 1.py`

```python
# 1.py
import ray

@ray.remote
def foo() -> None:
    pass
```

Note, the reason why CI didn't catch this issue is because we don't enable strict mode, see [here](https://github.com/ray-project/ray/blob/407062499038344b0f3edb54b2c7985c3320d1ec/ci/lint/format.sh#L135). Currently we have too many issues if enabling strict mode. 

Signed-off-by: Hao Chen <[email protected]>
  • Loading branch information
raulchen authored Jun 12, 2023
1 parent b935406 commit 9a45d1e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions python/ray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def __getattr__(self, attr):
state = _DeprecationWrapper("state", ray._private.state)


RAY_APIS = {
# Pulic Ray APIs
__all__ = [
"__version__",
"_config",
"get_runtime_context",
Expand Down Expand Up @@ -214,7 +215,7 @@ def __getattr__(self, attr):
"LOCAL_MODE",
"SCRIPT_MODE",
"WORKER_MODE",
}
]

# Public APIs that should automatically trigger ray.init().
AUTO_INIT_APIS = {
Expand Down Expand Up @@ -254,15 +255,12 @@ def __getattr__(self, attr):
"timeline",
}

assert RAY_APIS == AUTO_INIT_APIS | NON_AUTO_INIT_APIS
assert set(__all__) == AUTO_INIT_APIS | NON_AUTO_INIT_APIS
from ray._private.auto_init_hook import wrap_auto_init_for_all_apis # noqa: E402

wrap_auto_init_for_all_apis(AUTO_INIT_APIS)
del wrap_auto_init_for_all_apis


__all__ = list(RAY_APIS)

# Subpackages
__all__ += [
"actor",
Expand Down

0 comments on commit 9a45d1e

Please sign in to comment.