We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Importing from distributed shows pyright error
**What happened**:
When type-checking a program that imports from distributed with pyright, an error is accused:

```python
# foo.py
from distributed import Client
print(Client)
```

```
pyright foo.py
...
  /tmp/test-area/foo.py:1:25 - error: "Client" is not exported from module "distributed"
    Import from "distributed.client" instead (reportPrivateImportUsage)
1 error, 0 warnings, 0 informations
```

**What you expected to happen**:
I expect the package to be correctly typed, following PEP 484


**Anything else we need to know?**:

PEP 484 states that

> Modules and variables imported into the stub are not considered exported from the stub unless the import uses the `import ... as ... form` or the equivalent `from ... import ... as ... form`

and Pyright follows this guideline, although mypy doesn't.

**Environment**:

- Dask version: 2022.8.0
- Python version: 3.10.5
- Operating System: Arch linux
- Install method (conda, pip, source): pip inside an environment

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `distributed/__init__.py`
Content:
```
1 from __future__ import annotations
2 
3 # isort: off
4 from distributed import config  # load distributed configuration first
5 from distributed import widgets  # load distributed widgets second
6 
7 # isort: on
8 
9 import atexit
10 
11 import dask
12 from dask.config import config  # type: ignore
13 
14 from distributed._version import get_versions
15 from distributed.actor import Actor, ActorFuture, BaseActorFuture
16 from distributed.client import (
17     Client,
18     CompatibleExecutor,
19     Future,
20     as_completed,
21     default_client,
22     fire_and_forget,
23     futures_of,
24     get_task_metadata,
25     get_task_stream,
26     performance_report,
27     wait,
28 )
29 from distributed.core import Status, connect, rpc
30 from distributed.deploy import Adaptive, LocalCluster, SpecCluster, SSHCluster
31 from distributed.diagnostics.plugin import (
32     Environ,
33     NannyPlugin,
34     PipInstall,
35     SchedulerPlugin,
36     UploadDirectory,
37     UploadFile,
38     WorkerPlugin,
39 )
40 from distributed.diagnostics.progressbar import progress
41 from distributed.event import Event
42 from distributed.lock import Lock
43 from distributed.multi_lock import MultiLock
44 from distributed.nanny import Nanny
45 from distributed.pubsub import Pub, Sub
46 from distributed.queues import Queue
47 from distributed.scheduler import KilledWorker, Scheduler
48 from distributed.security import Security
49 from distributed.semaphore import Semaphore
50 from distributed.threadpoolexecutor import rejoin
51 from distributed.utils import CancelledError, TimeoutError, sync
52 from distributed.variable import Variable
53 from distributed.worker import (
54     Reschedule,
55     Worker,
56     get_client,
57     get_worker,
58     print,
59     secede,
60     warn,
61 )
62 from distributed.worker_client import local_client, worker_client
63 
64 
65 def __getattr__(name):
66     global __version__, __git_revision__
67 
68     if name == "__version__":
69         from importlib.metadata import version
70 
71         __version__ = version("distributed")
72         return __version__
73 
74     if name == "__git_revision__":
75         from distributed._version import get_versions
76 
77         __git_revision__ = get_versions()["full-revisionid"]
78         return __git_revision__
79 
80     raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
81 
82 
83 _python_shutting_down = False
84 
85 
86 @atexit.register
87 def _():
88     """Set a global when Python shuts down.
89 
90     Note
91     ----
92     This function must be registered with atexit *after* any class that invokes
93     ``dstributed.utils.is_python_shutting_down`` has been defined. This way it
94     will be called before the ``__del__`` method of those classes.
95 
96     See Also
97     --------
98     distributed.utils.is_python_shutting_down
99     """
100     global _python_shutting_down
101     _python_shutting_down = True
102
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/distributed/__init__.py b/distributed/__init__.py
--- a/distributed/__init__.py
+++ b/distributed/__init__.py
@@ -99,3 +99,65 @@
     """
     global _python_shutting_down
     _python_shutting_down = True
+
+
+__all__ = [
+    "Actor",
+    "ActorFuture",
+    "Adaptive",
+    "BaseActorFuture",
+    "CancelledError",
+    "Client",
+    "CompatibleExecutor",
+    "Environ",
+    "Event",
+    "Future",
+    "KilledWorker",
+    "LocalCluster",
+    "Lock",
+    "MultiLock",
+    "Nanny",
+    "NannyPlugin",
+    "PipInstall",
+    "Pub",
+    "Queue",
+    "Reschedule",
+    "SSHCluster",
+    "Scheduler",
+    "SchedulerPlugin",
+    "Security",
+    "Semaphore",
+    "SpecCluster",
+    "Status",
+    "Sub",
+    "TimeoutError",
+    "UploadDirectory",
+    "UploadFile",
+    "Variable",
+    "Worker",
+    "WorkerPlugin",
+    "as_completed",
+    "config",
+    "connect",
+    "dask",
+    "default_client",
+    "fire_and_forget",
+    "futures_of",
+    "get_client",
+    "get_task_metadata",
+    "get_task_stream",
+    "get_versions",
+    "get_worker",
+    "local_client",
+    "performance_report",
+    "print",
+    "progress",
+    "rejoin",
+    "rpc",
+    "secede",
+    "sync",
+    "wait",
+    "warn",
+    "widgets",
+    "worker_client",
+]

{"golden_diff": "diff --git a/distributed/__init__.py b/distributed/__init__.py\n--- a/distributed/__init__.py\n+++ b/distributed/__init__.py\n@@ -99,3 +99,65 @@\n     \"\"\"\n     global _python_shutting_down\n     _python_shutting_down = True\n+\n+\n+__all__ = [\n+    \"Actor\",\n+    \"ActorFuture\",\n+    \"Adaptive\",\n+    \"BaseActorFuture\",\n+    \"CancelledError\",\n+    \"Client\",\n+    \"CompatibleExecutor\",\n+    \"Environ\",\n+    \"Event\",\n+    \"Future\",\n+    \"KilledWorker\",\n+    \"LocalCluster\",\n+    \"Lock\",\n+    \"MultiLock\",\n+    \"Nanny\",\n+    \"NannyPlugin\",\n+    \"PipInstall\",\n+    \"Pub\",\n+    \"Queue\",\n+    \"Reschedule\",\n+    \"SSHCluster\",\n+    \"Scheduler\",\n+    \"SchedulerPlugin\",\n+    \"Security\",\n+    \"Semaphore\",\n+    \"SpecCluster\",\n+    \"Status\",\n+    \"Sub\",\n+    \"TimeoutError\",\n+    \"UploadDirectory\",\n+    \"UploadFile\",\n+    \"Variable\",\n+    \"Worker\",\n+    \"WorkerPlugin\",\n+    \"as_completed\",\n+    \"config\",\n+    \"connect\",\n+    \"dask\",\n+    \"default_client\",\n+    \"fire_and_forget\",\n+    \"futures_of\",\n+    \"get_client\",\n+    \"get_task_metadata\",\n+    \"get_task_stream\",\n+    \"get_versions\",\n+    \"get_worker\",\n+    \"local_client\",\n+    \"performance_report\",\n+    \"print\",\n+    \"progress\",\n+    \"rejoin\",\n+    \"rpc\",\n+    \"secede\",\n+    \"sync\",\n+    \"wait\",\n+    \"warn\",\n+    \"widgets\",\n+    \"worker_client\",\n+]\n", "issue": "Importing from distributed shows pyright error\n**What happened**:\r\nWhen type-checking a program that imports from distributed with pyright, an error is accused:\r\n\r\n```python\r\n# foo.py\r\nfrom distributed import Client\r\nprint(Client)\r\n```\r\n\r\n```\r\npyright foo.py\r\n...\r\n  /tmp/test-area/foo.py:1:25 - error: \"Client\" is not exported from module \"distributed\"\r\n  \u00a0\u00a0Import from \"distributed.client\" instead (reportPrivateImportUsage)\r\n1 error, 0 warnings, 0 informations\r\n```\r\n\r\n**What you expected to happen**:\r\nI expect the package to be correctly typed, following PEP 484\r\n\r\n\r\n**Anything else we need to know?**:\r\n\r\nPEP 484 states that\r\n\r\n> Modules and variables imported into the stub are not considered exported from the stub unless the import uses the `import ... as ... form` or the equivalent `from ... import ... as ... form`\r\n\r\nand Pyright follows this guideline, although mypy doesn't.\r\n\r\n**Environment**:\r\n\r\n- Dask version: 2022.8.0\r\n- Python version: 3.10.5\r\n- Operating System: Arch linux\r\n- Install method (conda, pip, source): pip inside an environment\n", "before_files": [{"content": "from __future__ import annotations\n\n# isort: off\nfrom distributed import config  # load distributed configuration first\nfrom distributed import widgets  # load distributed widgets second\n\n# isort: on\n\nimport atexit\n\nimport dask\nfrom dask.config import config  # type: ignore\n\nfrom distributed._version import get_versions\nfrom distributed.actor import Actor, ActorFuture, BaseActorFuture\nfrom distributed.client import (\n    Client,\n    CompatibleExecutor,\n    Future,\n    as_completed,\n    default_client,\n    fire_and_forget,\n    futures_of,\n    get_task_metadata,\n    get_task_stream,\n    performance_report,\n    wait,\n)\nfrom distributed.core import Status, connect, rpc\nfrom distributed.deploy import Adaptive, LocalCluster, SpecCluster, SSHCluster\nfrom distributed.diagnostics.plugin import (\n    Environ,\n    NannyPlugin,\n    PipInstall,\n    SchedulerPlugin,\n    UploadDirectory,\n    UploadFile,\n    WorkerPlugin,\n)\nfrom distributed.diagnostics.progressbar import progress\nfrom distributed.event import Event\nfrom distributed.lock import Lock\nfrom distributed.multi_lock import MultiLock\nfrom distributed.nanny import Nanny\nfrom distributed.pubsub import Pub, Sub\nfrom distributed.queues import Queue\nfrom distributed.scheduler import KilledWorker, Scheduler\nfrom distributed.security import Security\nfrom distributed.semaphore import Semaphore\nfrom distributed.threadpoolexecutor import rejoin\nfrom distributed.utils import CancelledError, TimeoutError, sync\nfrom distributed.variable import Variable\nfrom distributed.worker import (\n    Reschedule,\n    Worker,\n    get_client,\n    get_worker,\n    print,\n    secede,\n    warn,\n)\nfrom distributed.worker_client import local_client, worker_client\n\n\ndef __getattr__(name):\n    global __version__, __git_revision__\n\n    if name == \"__version__\":\n        from importlib.metadata import version\n\n        __version__ = version(\"distributed\")\n        return __version__\n\n    if name == \"__git_revision__\":\n        from distributed._version import get_versions\n\n        __git_revision__ = get_versions()[\"full-revisionid\"]\n        return __git_revision__\n\n    raise AttributeError(f\"module {__name__!r} has no attribute {name!r}\")\n\n\n_python_shutting_down = False\n\n\n@atexit.register\ndef _():\n    \"\"\"Set a global when Python shuts down.\n\n    Note\n    ----\n    This function must be registered with atexit *after* any class that invokes\n    ``dstributed.utils.is_python_shutting_down`` has been defined. This way it\n    will be called before the ``__del__`` method of those classes.\n\n    See Also\n    --------\n    distributed.utils.is_python_shutting_down\n    \"\"\"\n    global _python_shutting_down\n    _python_shutting_down = True\n", "path": "distributed/__init__.py"}], "after_files": [{"content": "from __future__ import annotations\n\n# isort: off\nfrom distributed import config  # load distributed configuration first\nfrom distributed import widgets  # load distributed widgets second\n\n# isort: on\n\nimport atexit\n\nimport dask\nfrom dask.config import config  # type: ignore\n\nfrom distributed._version import get_versions\nfrom distributed.actor import Actor, ActorFuture, BaseActorFuture\nfrom distributed.client import (\n    Client,\n    CompatibleExecutor,\n    Future,\n    as_completed,\n    default_client,\n    fire_and_forget,\n    futures_of,\n    get_task_metadata,\n    get_task_stream,\n    performance_report,\n    wait,\n)\nfrom distributed.core import Status, connect, rpc\nfrom distributed.deploy import Adaptive, LocalCluster, SpecCluster, SSHCluster\nfrom distributed.diagnostics.plugin import (\n    Environ,\n    NannyPlugin,\n    PipInstall,\n    SchedulerPlugin,\n    UploadDirectory,\n    UploadFile,\n    WorkerPlugin,\n)\nfrom distributed.diagnostics.progressbar import progress\nfrom distributed.event import Event\nfrom distributed.lock import Lock\nfrom distributed.multi_lock import MultiLock\nfrom distributed.nanny import Nanny\nfrom distributed.pubsub import Pub, Sub\nfrom distributed.queues import Queue\nfrom distributed.scheduler import KilledWorker, Scheduler\nfrom distributed.security import Security\nfrom distributed.semaphore import Semaphore\nfrom distributed.threadpoolexecutor import rejoin\nfrom distributed.utils import CancelledError, TimeoutError, sync\nfrom distributed.variable import Variable\nfrom distributed.worker import (\n    Reschedule,\n    Worker,\n    get_client,\n    get_worker,\n    print,\n    secede,\n    warn,\n)\nfrom distributed.worker_client import local_client, worker_client\n\n\ndef __getattr__(name):\n    global __version__, __git_revision__\n\n    if name == \"__version__\":\n        from importlib.metadata import version\n\n        __version__ = version(\"distributed\")\n        return __version__\n\n    if name == \"__git_revision__\":\n        from distributed._version import get_versions\n\n        __git_revision__ = get_versions()[\"full-revisionid\"]\n        return __git_revision__\n\n    raise AttributeError(f\"module {__name__!r} has no attribute {name!r}\")\n\n\n_python_shutting_down = False\n\n\n@atexit.register\ndef _():\n    \"\"\"Set a global when Python shuts down.\n\n    Note\n    ----\n    This function must be registered with atexit *after* any class that invokes\n    ``dstributed.utils.is_python_shutting_down`` has been defined. This way it\n    will be called before the ``__del__`` method of those classes.\n\n    See Also\n    --------\n    distributed.utils.is_python_shutting_down\n    \"\"\"\n    global _python_shutting_down\n    _python_shutting_down = True\n\n\n__all__ = [\n    \"Actor\",\n    \"ActorFuture\",\n    \"Adaptive\",\n    \"BaseActorFuture\",\n    \"CancelledError\",\n    \"Client\",\n    \"CompatibleExecutor\",\n    \"Environ\",\n    \"Event\",\n    \"Future\",\n    \"KilledWorker\",\n    \"LocalCluster\",\n    \"Lock\",\n    \"MultiLock\",\n    \"Nanny\",\n    \"NannyPlugin\",\n    \"PipInstall\",\n    \"Pub\",\n    \"Queue\",\n    \"Reschedule\",\n    \"SSHCluster\",\n    \"Scheduler\",\n    \"SchedulerPlugin\",\n    \"Security\",\n    \"Semaphore\",\n    \"SpecCluster\",\n    \"Status\",\n    \"Sub\",\n    \"TimeoutError\",\n    \"UploadDirectory\",\n    \"UploadFile\",\n    \"Variable\",\n    \"Worker\",\n    \"WorkerPlugin\",\n    \"as_completed\",\n    \"config\",\n    \"connect\",\n    \"dask\",\n    \"default_client\",\n    \"fire_and_forget\",\n    \"futures_of\",\n    \"get_client\",\n    \"get_task_metadata\",\n    \"get_task_stream\",\n    \"get_versions\",\n    \"get_worker\",\n    \"local_client\",\n    \"performance_report\",\n    \"print\",\n    \"progress\",\n    \"rejoin\",\n    \"rpc\",\n    \"secede\",\n    \"sync\",\n    \"wait\",\n    \"warn\",\n    \"widgets\",\n    \"worker_client\",\n]\n", "path": "distributed/__init__.py"}]}