Repository: Textualize/rich

Issue:
pyright: "Table" is not exported from module "rich.table"
Running [pyright](https://github.com/microsoft/pyright) 1.1.172 on
```
from rich.table import Table
```
gives
```
/tmp/b.py:1:24 - error: "Table" is not exported from module "rich.table" (reportPrivateImportUsage)
```


Discussion:
What version of pyright are you using? There have been changes to this specific check in pyright recently

pyright 1.1.169

_Edit:_ Also occurs with 1.1.172.
I suspect that may be because of the code in the main block, which imports Table. I don’t think it’s a real error to be concerned about, but I’ll see if there is a workaround.
I looked into this longer than i would have liked.
The check is very new. The solution could be to import it like this

`from rich.table import Table as Table`

its called a redundant alias and it signals pyright that this symbol has to be re-exported ..

though i dont know why it would matter that we import it in `__main__.py`. Why would this matter if we import from rich.table.
This check is a few weeks old its not out of the question that this is a pyright bug.

Relevant links
https://github.com/microsoft/pyright/issues/2277
https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#library-interface
I also see what I think is the same issue, but in pylance:
`"Table" is not exported from module "rich.table"`

Despite that, the Intellisense seems to still work - it can autocomplete methods/attributes of `Table`, I can cmd+click into the library in site-packages, so I'm not sure what's going on.

Full VS Code output:

```
{
	"resource": "/path/to/source.py",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": {
		"value": "reportPrivateImportUsage",
		"target": {
			"$mid": 1,
			"external": "https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules",
			"path": "/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md",
			"scheme": "https",
			"authority": "github.com",
			"fragment": "diagnostic-severity-rules"
		}
	},
	"severity": 8,
	"message": "\"Table\" is not exported from module \"rich.table\"",
	"source": "Pylance",
	"startLineNumber": 8,
	"startColumn": 24,
	"endLineNumber": 8,
	"endColumn": 29
}
```
I get a similar issue with Live: `/home/gregory/Documents/projects/pyffstream/src/pyffstream/cli.py:486:24 - error: "Live" is not exported from module "rich.box.live" (reportPrivateImportUsage)`
Upstream pyright has affirmatively clarified the behavior is intended and the libraries need to be redundantly imported to be correctly marked as exported. See https://github.com/microsoft/pyright/issues/2277#issuecomment-937468789

I'm working on a PR that will close this issue by adding the appropriate `TYPE_CHECKING` guards to the `if __name__ == __main__` blocks following the suggestion here https://github.com/microsoft/pyright/issues/2392#issuecomment-937522830

Resolving patch:
diff --git a/rich/box.py b/rich/box.py
--- a/rich/box.py
+++ b/rich/box.py
@@ -435,7 +435,7 @@ def get_bottom(self, widths: Iterable[int]) -> str:
     from rich.columns import Columns
     from rich.panel import Panel
 
-    from . import box
+    from . import box as box
     from .console import Console
     from .table import Table
     from .text import Text
diff --git a/rich/live.py b/rich/live.py
--- a/rich/live.py
+++ b/rich/live.py
@@ -276,7 +276,7 @@ def process_renderables(
 
     from .align import Align
     from .console import Console
-    from .live import Live
+    from .live import Live as Live
     from .panel import Panel
     from .rule import Rule
     from .syntax import Syntax
diff --git a/rich/table.py b/rich/table.py
--- a/rich/table.py
+++ b/rich/table.py
@@ -845,7 +845,7 @@ def _render(
 if __name__ == "__main__":  # pragma: no cover
     from rich.console import Console
     from rich.highlighter import ReprHighlighter
-    from rich.table import Table
+    from rich.table import Table as Table
 
     table = Table(
         title="Star Wars Movies",


Test patch: