mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-23 23:13:00 +03:00
Ensure __all__ are consistent
This commit is contained in:
parent
2992a8e212
commit
cea9fc6c77
|
@ -1,8 +1,4 @@
|
||||||
from .client import Client
|
from .client import Client
|
||||||
from .net import Config
|
from .net import Config
|
||||||
|
|
||||||
__all__ = [
|
__all__ = ["Client", "Config"]
|
||||||
"InlineResult",
|
|
||||||
"Client",
|
|
||||||
"Config",
|
|
||||||
]
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ from .markdown import parse as parse_markdown_message
|
||||||
from .markdown import unparse as generate_markdown_message
|
from .markdown import unparse as generate_markdown_message
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"generate_html_message",
|
|
||||||
"parse_html_message",
|
"parse_html_message",
|
||||||
"generate_markdown_message",
|
"generate_html_message",
|
||||||
"parse_markdown_message",
|
"parse_markdown_message",
|
||||||
|
"generate_markdown_message",
|
||||||
]
|
]
|
||||||
|
|
|
@ -85,5 +85,4 @@ __all__ = [
|
||||||
"SwitchInline",
|
"SwitchInline",
|
||||||
"Text",
|
"Text",
|
||||||
"Url",
|
"Url",
|
||||||
"create",
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -80,13 +80,4 @@ def expand_peer(peer: abcs.Peer, *, broadcast: Optional[bool]) -> Chat:
|
||||||
raise RuntimeError("unexpected case")
|
raise RuntimeError("unexpected case")
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = ["Channel", "Chat", "Group", "User"]
|
||||||
"Chat",
|
|
||||||
"ChatLike",
|
|
||||||
"Channel",
|
|
||||||
"Group",
|
|
||||||
"User",
|
|
||||||
"build_chat_map",
|
|
||||||
"peer_id",
|
|
||||||
"expand_peer",
|
|
||||||
]
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ __all__ = [
|
||||||
"NO_UPDATES_TIMEOUT",
|
"NO_UPDATES_TIMEOUT",
|
||||||
"USER_CHANNEL_DIFF_LIMIT",
|
"USER_CHANNEL_DIFF_LIMIT",
|
||||||
"Gap",
|
"Gap",
|
||||||
|
"MessageBox",
|
||||||
"PossibleGap",
|
"PossibleGap",
|
||||||
"PrematureEndReason",
|
"PrematureEndReason",
|
||||||
"PtsInfo",
|
"PtsInfo",
|
||||||
|
@ -30,7 +31,6 @@ __all__ = [
|
||||||
"Session",
|
"Session",
|
||||||
"UpdateState",
|
"UpdateState",
|
||||||
"User",
|
"User",
|
||||||
"MessageBox",
|
|
||||||
"MemorySession",
|
"MemorySession",
|
||||||
"SqliteSession",
|
"SqliteSession",
|
||||||
"Storage",
|
"Storage",
|
||||||
|
|
|
@ -2,13 +2,4 @@ from . import abcs, functions, mtproto, types
|
||||||
from .core import Request
|
from .core import Request
|
||||||
from .layer import LAYER, TYPE_MAPPING
|
from .layer import LAYER, TYPE_MAPPING
|
||||||
|
|
||||||
__all__ = [
|
__all__ = ['abcs', 'functions', 'mtproto', 'types', 'Request', 'LAYER', 'TYPE_MAPPING']
|
||||||
"abcs",
|
|
||||||
"core",
|
|
||||||
"functions",
|
|
||||||
"mtproto",
|
|
||||||
"types",
|
|
||||||
"Request",
|
|
||||||
"LAYER",
|
|
||||||
"TYPE_MAPPING",
|
|
||||||
]
|
|
||||||
|
|
61
tools/copy_init_imports.py
Normal file
61
tools/copy_init_imports.py
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
"""
|
||||||
|
Scan the `client/` directory for __init__.py files.
|
||||||
|
For every depth-1 import, add it, in order, to the __all__ variable.
|
||||||
|
"""
|
||||||
|
import ast
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
class ImportVisitor(ast.NodeVisitor):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.imported_names: List[str] = []
|
||||||
|
|
||||||
|
def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
|
||||||
|
if node.level == 1:
|
||||||
|
for name in node.names:
|
||||||
|
self.imported_names.append(name.asname or name.name)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
impl_root = Path.cwd() / "client/src/telethon/_impl"
|
||||||
|
autogenerated_re = re.compile(
|
||||||
|
rf"(tl|mtproto){re.escape(os.path.sep)}(abcs|functions|types)"
|
||||||
|
)
|
||||||
|
|
||||||
|
files = []
|
||||||
|
for file in impl_root.rglob("__init__.py"):
|
||||||
|
file_str = str(file)
|
||||||
|
if autogenerated_re.search(file_str):
|
||||||
|
continue
|
||||||
|
|
||||||
|
files.append(file_str)
|
||||||
|
|
||||||
|
with file.open(encoding="utf-8") as fd:
|
||||||
|
contents = fd.read()
|
||||||
|
lines = contents.splitlines(True)
|
||||||
|
|
||||||
|
module = ast.parse(contents)
|
||||||
|
|
||||||
|
visitor = ImportVisitor()
|
||||||
|
visitor.visit(module)
|
||||||
|
|
||||||
|
for stmt in module.body:
|
||||||
|
match stmt:
|
||||||
|
case ast.Assign(targets=[ast.Name(id="__all__")], value=ast.List()):
|
||||||
|
# Not rewriting the AST to preserve comments and formatting.
|
||||||
|
lines[stmt.lineno - 1 : stmt.end_lineno] = [
|
||||||
|
"__all__ = ["
|
||||||
|
+ ", ".join(map(repr, visitor.imported_names))
|
||||||
|
+ "]\n"
|
||||||
|
]
|
||||||
|
break
|
||||||
|
|
||||||
|
with file.open("w", encoding="utf-8", newline="\n") as fd:
|
||||||
|
fd.writelines(lines)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user