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" (#36334) (#36356)

#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 <chenh1024@gmail.com>
  • Loading branch information
raulchen authored Jun 13, 2023
1 parent 1d09d67 commit a03efd9
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 @@ -192,7 +192,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 @@ -223,7 +224,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 @@ -263,15 +264,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 a03efd9

Please sign in to comment.