-
Notifications
You must be signed in to change notification settings - Fork 5
Beta #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Beta #78
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ecad6ef
InkyPinkyPonky [no ci]
5hojib 4e1cbc0
refactor(types): resolve ty type checker errors and improve core anno…
5hojib 1d5e80e
Fix comprehensive type errors and improve architectural type safety (…
5hojib bdfb1a2
InkyPinkyPonky [no ci]
5hojib a61baf2
re
5hojib 7694bbc
Resolve type checker diagnostics across the codebase (#77)
5hojib d8f951d
InkyPinkyPonky [no ci]
5hojib 3e08432
re
5hojib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |||||||||
| import json | ||||||||||
| import re | ||||||||||
| import shutil | ||||||||||
| from functools import partial | ||||||||||
| from pathlib import Path | ||||||||||
| from typing import NamedTuple | ||||||||||
|
|
||||||||||
|
|
@@ -45,7 +44,10 @@ | |||||||||
| # # # # # # # # # # # # # # # # # # # # # # # # | ||||||||||
| """.strip() | ||||||||||
|
|
||||||||||
| open = partial(open, encoding="utf-8") | ||||||||||
|
|
||||||||||
| def open_utf8(path: str | Path, mode: str = "r", *args, **kwargs): | ||||||||||
| return open(path, mode, encoding="utf-8", *args, **kwargs) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| types_to_constructors: dict[str, list[str]] = {} | ||||||||||
| types_to_functions: dict[str, list[str]] = {} | ||||||||||
|
|
@@ -55,7 +57,7 @@ | |||||||||
| namespaces_to_functions: dict[str, list[str]] = {} | ||||||||||
|
|
||||||||||
| try: | ||||||||||
| with open(API_HOME_PATH / "docs.json") as f: | ||||||||||
| with open_utf8(API_HOME_PATH / "docs.json") as f: | ||||||||||
| docs = json.load(f) | ||||||||||
| except FileNotFoundError: | ||||||||||
| docs = {"type": {}, "constructor": {}, "method": {}} | ||||||||||
|
|
@@ -184,465 +186,479 @@ | |||||||||
| return ("\n ".join(items), len(items)) if items else (None, 0) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def start() -> None: # noqa: C901 | ||||||||||
| shutil.rmtree(DESTINATION_PATH / "types", ignore_errors=True) | ||||||||||
| shutil.rmtree(DESTINATION_PATH / "functions", ignore_errors=True) | ||||||||||
| shutil.rmtree(DESTINATION_PATH / "base", ignore_errors=True) | ||||||||||
|
|
||||||||||
| with ( | ||||||||||
| open(API_HOME_PATH / "source/auth_key.tl") as f1, | ||||||||||
| open(API_HOME_PATH / "source/sys_msgs.tl") as f2, | ||||||||||
| open(API_HOME_PATH / "source/main_api.tl") as f3, | ||||||||||
| open_utf8(API_HOME_PATH / "source/auth_key.tl") as f1, | ||||||||||
| open_utf8(API_HOME_PATH / "source/sys_msgs.tl") as f2, | ||||||||||
| open_utf8(API_HOME_PATH / "source/main_api.tl") as f3, | ||||||||||
| ): | ||||||||||
| schema = (f1.read() + f2.read() + f3.read()).splitlines() | ||||||||||
| schema = (str(f1.read()) + str(f2.read()) + str(f3.read())).splitlines() | ||||||||||
|
|
||||||||||
| with ( | ||||||||||
| open(API_HOME_PATH / "template/type.txt") as f1, | ||||||||||
| open(API_HOME_PATH / "template/combinator.txt") as f2, | ||||||||||
| open_utf8(API_HOME_PATH / "template/type.txt") as f1, | ||||||||||
| open_utf8(API_HOME_PATH / "template/combinator.txt") as f2, | ||||||||||
| ): | ||||||||||
| type_tmpl = f1.read() | ||||||||||
| combinator_tmpl = f2.read() | ||||||||||
| type_tmpl = str(f1.read()) | ||||||||||
| combinator_tmpl = str(f2.read()) | ||||||||||
|
Comment on lines
+205
to
+206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||
|
|
||||||||||
| layer = None | ||||||||||
| combinators: list[Combinator] = [] | ||||||||||
|
|
||||||||||
| section = None | ||||||||||
| section = "" | ||||||||||
| for line in schema: | ||||||||||
| if section_match := SECTION_RE.match(line): | ||||||||||
| section = section_match.group(1) | ||||||||||
| continue | ||||||||||
|
|
||||||||||
| if layer_match := LAYER_RE.match(line): | ||||||||||
| layer = layer_match.group(1) | ||||||||||
| continue | ||||||||||
|
|
||||||||||
| if combinator_match := COMBINATOR_RE.match(line): | ||||||||||
| qualname, id, qualtype = combinator_match.groups() | ||||||||||
|
|
||||||||||
| namespace, name = ( | ||||||||||
| qualname.split(".") if "." in qualname else ("", qualname) | ||||||||||
| ) | ||||||||||
| name = camel(name) | ||||||||||
| qualname = ".".join([namespace, name]).lstrip(".") | ||||||||||
|
|
||||||||||
| typespace, type = ( | ||||||||||
| qualtype.split(".") if "." in qualtype else ("", qualtype) | ||||||||||
| ) | ||||||||||
| type = camel(type) | ||||||||||
| qualtype = ".".join([typespace, type]).lstrip(".") | ||||||||||
|
|
||||||||||
| has_flags = bool(FLAGS_RE_3.findall(line)) | ||||||||||
|
|
||||||||||
| args = ARGS_RE.findall(line) | ||||||||||
|
|
||||||||||
| # Fix arg name being "self" or "from" (reserved python keywords) | ||||||||||
| for i, item in enumerate(args): | ||||||||||
| if item[0] == "self": | ||||||||||
| args[i] = ("is_self", item[1]) | ||||||||||
| if item[0] == "from": | ||||||||||
| args[i] = ("from_peer", item[1]) | ||||||||||
|
|
||||||||||
| combinator = Combinator( | ||||||||||
| section=section, | ||||||||||
| qualname=qualname, | ||||||||||
| namespace=namespace, | ||||||||||
| name=name, | ||||||||||
| id=f"0x{id}", | ||||||||||
| has_flags=has_flags, | ||||||||||
| args=args, | ||||||||||
| qualtype=qualtype, | ||||||||||
| typespace=typespace, | ||||||||||
| type=type, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| combinators.append(combinator) | ||||||||||
|
|
||||||||||
| for c in combinators: | ||||||||||
| qualtype = c.qualtype | ||||||||||
|
|
||||||||||
| if qualtype.startswith("Vector"): | ||||||||||
| qualtype = qualtype.split("<")[1][:-1] | ||||||||||
|
|
||||||||||
| d = types_to_constructors if c.section == "types" else types_to_functions | ||||||||||
|
|
||||||||||
| if qualtype not in d: | ||||||||||
| d[qualtype] = [] | ||||||||||
|
|
||||||||||
| d[qualtype].append(c.qualname) | ||||||||||
|
|
||||||||||
| if c.section == "types": | ||||||||||
| key = c.namespace | ||||||||||
|
|
||||||||||
| if key not in namespaces_to_types: | ||||||||||
| namespaces_to_types[key] = [] | ||||||||||
|
|
||||||||||
| if c.type not in namespaces_to_types[key]: | ||||||||||
| namespaces_to_types[key].append(c.type) | ||||||||||
|
|
||||||||||
| for k, v in types_to_constructors.items(): | ||||||||||
| for i in v: | ||||||||||
| with contextlib.suppress(KeyError): | ||||||||||
| constructors_to_functions[i] = types_to_functions[k] | ||||||||||
|
|
||||||||||
| for qualtype, qualval in types_to_constructors.items(): | ||||||||||
| typespace, type = qualtype.split(".") if "." in qualtype else ("", qualtype) | ||||||||||
| dir_path = DESTINATION_PATH / "base" / typespace | ||||||||||
|
|
||||||||||
| module = type | ||||||||||
|
|
||||||||||
| if module == "Updates": | ||||||||||
| module = "UpdatesT" | ||||||||||
|
|
||||||||||
| dir_path.mkdir(parents=True, exist_ok=True) | ||||||||||
|
|
||||||||||
| constructors = sorted(qualval) | ||||||||||
| constr_count = len(constructors) | ||||||||||
| items = "\n ".join([f"{c}" for c in constructors]) | ||||||||||
|
|
||||||||||
| type_docs = docs["type"].get(qualtype, None) | ||||||||||
|
|
||||||||||
| type_docs = type_docs["desc"] if type_docs else "Telegram API base type." | ||||||||||
|
|
||||||||||
| docstring = type_docs | ||||||||||
|
|
||||||||||
| docstring += ( | ||||||||||
| f"\n\n Constructors:\n" | ||||||||||
| f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n" | ||||||||||
| f" .. currentmodule:: pyrogram.raw.types\n\n" | ||||||||||
| f" .. autosummary::\n" | ||||||||||
| f" :nosignatures:\n\n" | ||||||||||
| f" {items}" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| references, ref_count = get_references(qualtype, "types") | ||||||||||
|
|
||||||||||
| if references: | ||||||||||
| docstring += f"\n\n Functions:\n This object can be returned by {ref_count} function{'s' if ref_count > 1 else ''}.\n\n .. currentmodule:: pyrogram.raw.functions\n\n .. autosummary::\n :nosignatures:\n\n {references}" | ||||||||||
|
|
||||||||||
| with open(dir_path / f"{snake(module)}.py", "w") as f: | ||||||||||
| with open_utf8(dir_path / f"{snake(module)}.py", "w") as f: | ||||||||||
| f.write( | ||||||||||
| type_tmpl.format( | ||||||||||
| warning=WARNING, | ||||||||||
| docstring=docstring, | ||||||||||
| name=type, | ||||||||||
| qualname=qualtype, | ||||||||||
| types=", ".join([f'"raw.types.{c}"' for c in constructors]), | ||||||||||
| doc_name=snake(type).replace("_", "-"), | ||||||||||
| ), | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| for c in combinators: | ||||||||||
| sorted_args = sort_args(c.args) | ||||||||||
|
|
||||||||||
| arguments = (", *, " if c.args else "") + ( | ||||||||||
| ", ".join([f"{i[0]}: {get_type_hint(i[1])}" for i in sorted_args]) | ||||||||||
| if sorted_args | ||||||||||
| else "" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| fields = ( | ||||||||||
| "\n ".join( | ||||||||||
| [f"self.{i[0]} = {i[0]} # {i[1]}" for i in sorted_args], | ||||||||||
| ) | ||||||||||
| if sorted_args | ||||||||||
| else "pass" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| docstring = "" | ||||||||||
| docstring_args = [] | ||||||||||
|
|
||||||||||
| combinator_docs = ( | ||||||||||
| docs["method"] if c.section == "functions" else docs["constructor"] | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| for arg in sorted_args: | ||||||||||
| arg_name, arg_type = arg | ||||||||||
| is_optional = FLAGS_RE.match(arg_type) | ||||||||||
| arg_type = arg_type.split("?")[-1] | ||||||||||
|
|
||||||||||
| arg_docs = combinator_docs.get(c.qualname, None) | ||||||||||
|
|
||||||||||
| arg_docs = arg_docs["params"].get(arg_name, "N/A") if arg_docs else "N/A" | ||||||||||
|
|
||||||||||
| docstring_args.append( | ||||||||||
| f"{arg_name} ({get_docstring_arg_type(arg_type)}{', *optional*' if is_optional else ''}):\n {arg_docs}\n", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| if c.section == "types": | ||||||||||
| constructor_docs = docs["constructor"].get(c.qualname, None) | ||||||||||
|
|
||||||||||
| constructor_docs = ( | ||||||||||
| constructor_docs["desc"] | ||||||||||
| if constructor_docs | ||||||||||
| else "Telegram API type." | ||||||||||
| ) | ||||||||||
| docstring += constructor_docs + "\n" | ||||||||||
| docstring += ( | ||||||||||
| f"\n Constructor of :obj:`~pyrogram.raw.base.{c.qualtype}`." | ||||||||||
| ) | ||||||||||
| elif function_docs := docs["method"].get(c.qualname, None): | ||||||||||
| docstring += function_docs["desc"] + "\n" | ||||||||||
| else: | ||||||||||
| docstring += "Telegram API function." | ||||||||||
|
|
||||||||||
| docstring += f"\n\n Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n" | ||||||||||
| docstring += " Parameters:\n " + ( | ||||||||||
| "\n ".join(docstring_args) | ||||||||||
| if docstring_args | ||||||||||
| else "No parameters required.\n" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| if c.section == "functions": | ||||||||||
| docstring += "\n Returns:\n " + get_docstring_arg_type( | ||||||||||
| c.qualtype, | ||||||||||
| ) | ||||||||||
| else: | ||||||||||
| references, count = get_references(c.qualname, "constructors") | ||||||||||
|
|
||||||||||
| if references: | ||||||||||
| docstring += f"\n Functions:\n This object can be returned by {count} function{'s' if count > 1 else ''}.\n\n .. currentmodule:: pyrogram.raw.functions\n\n .. autosummary::\n :nosignatures:\n\n {references}" | ||||||||||
|
|
||||||||||
| write_types = read_types = "" if c.has_flags else "# No flags\n " | ||||||||||
|
|
||||||||||
| for arg_name, arg_type in c.args: | ||||||||||
| flag = FLAGS_RE_2.match(arg_type) | ||||||||||
|
|
||||||||||
| if re.match(r"flags\d?", arg_name) and arg_type == "#": | ||||||||||
| write_flags = [] | ||||||||||
|
|
||||||||||
| for i in c.args: | ||||||||||
| flag = FLAGS_RE_2.match(i[1]) | ||||||||||
|
|
||||||||||
| if flag: | ||||||||||
| if arg_name != f"flags{flag.group(1)}": | ||||||||||
| continue | ||||||||||
|
|
||||||||||
| if flag.group(3) == "true" or flag.group(3).startswith( | ||||||||||
| "Vector", | ||||||||||
| ): | ||||||||||
| write_flags.append( | ||||||||||
| f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0", | ||||||||||
| ) | ||||||||||
| else: | ||||||||||
| write_flags.append( | ||||||||||
| f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| write_flags = "\n ".join( | ||||||||||
| [ | ||||||||||
| f"{arg_name} = 0", | ||||||||||
| "\n ".join(write_flags), | ||||||||||
| f"b.write(Int({arg_name}))\n ", | ||||||||||
| ], | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| write_types += write_flags | ||||||||||
| read_types += f"\n {arg_name} = Int.read(b)\n " | ||||||||||
|
|
||||||||||
| continue | ||||||||||
|
|
||||||||||
| if flag: | ||||||||||
| number, index, flag_type = flag.groups() | ||||||||||
|
|
||||||||||
| if flag_type == "true": | ||||||||||
| read_types += "\n " | ||||||||||
| read_types += f"{arg_name} = True if flags{number} & (1 << {index}) else False" | ||||||||||
| elif flag_type in CORE_TYPES: | ||||||||||
| write_types += "\n " | ||||||||||
| write_types += f"if self.{arg_name} is not None:\n " | ||||||||||
| write_types += ( | ||||||||||
| f"b.write({flag_type.title()}(self.{arg_name}))\n " | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| read_types += "\n " | ||||||||||
| read_types += f"{arg_name} = {flag_type.title()}.read(b) if flags{number} & (1 << {index}) else None" | ||||||||||
| elif "vector" in flag_type.lower(): | ||||||||||
| sub_type = arg_type.split("<")[1][:-1] | ||||||||||
|
|
||||||||||
| write_types += "\n " | ||||||||||
| write_types += f"if self.{arg_name} is not None:\n " | ||||||||||
| write_types += f"b.write(Vector(self.{arg_name}{f', {sub_type.title()}' if sub_type in CORE_TYPES else ''}))\n " | ||||||||||
|
|
||||||||||
| read_types += "\n " | ||||||||||
| read_types += f"{arg_name} = TLObject.read(b{f', {sub_type.title()}' if sub_type in CORE_TYPES else ''}) if flags{number} & (1 << {index}) else []\n " | ||||||||||
| else: | ||||||||||
| write_types += "\n " | ||||||||||
| write_types += f"if self.{arg_name} is not None:\n " | ||||||||||
| write_types += f"b.write(self.{arg_name}.write())\n " | ||||||||||
|
|
||||||||||
| read_types += "\n " | ||||||||||
| read_types += f"{arg_name} = TLObject.read(b) if flags{number} & (1 << {index}) else None\n " | ||||||||||
| else: | ||||||||||
| write_types += "\n " | ||||||||||
| if arg_type in CORE_TYPES: | ||||||||||
| write_types += ( | ||||||||||
| f"b.write({arg_type.title()}(self.{arg_name}))\n " | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| read_types += "\n " | ||||||||||
| read_types += ( | ||||||||||
| f"{arg_name} = {arg_type.title()}.read(b)\n " | ||||||||||
| ) | ||||||||||
| elif "vector" in arg_type.lower(): | ||||||||||
| sub_type = arg_type.split("<")[1][:-1] | ||||||||||
|
|
||||||||||
| write_types += f"b.write(Vector(self.{arg_name}{f', {sub_type.title()}' if sub_type in CORE_TYPES else ''}))\n " | ||||||||||
|
|
||||||||||
| read_types += "\n " | ||||||||||
| read_types += f"{arg_name} = TLObject.read(b{f', {sub_type.title()}' if sub_type in CORE_TYPES else ''})\n " | ||||||||||
| else: | ||||||||||
| write_types += f"b.write(self.{arg_name}.write())\n " | ||||||||||
|
|
||||||||||
| read_types += "\n " | ||||||||||
| read_types += f"{arg_name} = TLObject.read(b)\n " | ||||||||||
|
|
||||||||||
| slots = ", ".join([f'"{i[0]}"' for i in sorted_args]) | ||||||||||
| return_arguments = ", ".join([f"{i[0]}={i[0]}" for i in sorted_args]) | ||||||||||
|
|
||||||||||
| base_class = ( | ||||||||||
| f"raw.base.{c.qualtype}" | ||||||||||
| if c.qualtype in types_to_constructors | ||||||||||
| else "TLObject" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| if c.section == "functions": | ||||||||||
| base_class = "TLObject" | ||||||||||
|
|
||||||||||
| compiled_combinator = combinator_tmpl.format( | ||||||||||
| warning=WARNING, | ||||||||||
| base=base_class, | ||||||||||
| name=c.name, | ||||||||||
| docstring=docstring, | ||||||||||
| slots=slots, | ||||||||||
| id=c.id, | ||||||||||
| qualname=f"{c.section}.{c.qualname}", | ||||||||||
| arguments=arguments, | ||||||||||
| fields=fields, | ||||||||||
| read_types=read_types, | ||||||||||
| write_types=write_types, | ||||||||||
| return_arguments=return_arguments, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| directory = "types" if c.section == "types" else c.section | ||||||||||
|
|
||||||||||
| dir_path = DESTINATION_PATH / directory / c.namespace | ||||||||||
|
|
||||||||||
| dir_path.mkdir(exist_ok=True, parents=True) | ||||||||||
|
|
||||||||||
| module = c.name | ||||||||||
|
|
||||||||||
| if module == "Updates": | ||||||||||
| module = "UpdatesT" | ||||||||||
|
|
||||||||||
| with open(dir_path / f"{snake(module)}.py", "w") as f: | ||||||||||
| with open_utf8(dir_path / f"{snake(module)}.py", "w") as f: | ||||||||||
| f.write(compiled_combinator) | ||||||||||
|
|
||||||||||
| d = ( | ||||||||||
| namespaces_to_constructors | ||||||||||
| if c.section == "types" | ||||||||||
| else namespaces_to_functions | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| if c.namespace not in d: | ||||||||||
| d[c.namespace] = [] | ||||||||||
|
|
||||||||||
| d[c.namespace].append(c.name) | ||||||||||
|
|
||||||||||
| for namespace, types in namespaces_to_types.items(): | ||||||||||
| with open(DESTINATION_PATH / "base" / namespace / "__init__.py", "w") as f: | ||||||||||
| with open_utf8( | ||||||||||
| DESTINATION_PATH / "base" / namespace / "__init__.py", "w" | ||||||||||
| ) as f: | ||||||||||
| f.write(f"{WARNING}\n\n") | ||||||||||
|
|
||||||||||
| all = [] | ||||||||||
|
|
||||||||||
| for t in types: | ||||||||||
| module = t | ||||||||||
|
|
||||||||||
| if module == "Updates": | ||||||||||
| module = "UpdatesT" | ||||||||||
|
|
||||||||||
| all.append(t) | ||||||||||
|
|
||||||||||
| f.write(f"from .{snake(module)} import {t}\n") | ||||||||||
|
|
||||||||||
| if not namespace: | ||||||||||
| f.write( | ||||||||||
| f"from . import {', '.join(filter(bool, namespaces_to_types))}", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| all.extend(filter(bool, namespaces_to_types)) | ||||||||||
|
|
||||||||||
| f.write("\n\n__all__ = [\n") | ||||||||||
| for it in all: | ||||||||||
| f.write(f' "{it}",\n') | ||||||||||
| f.write("]\n") | ||||||||||
|
|
||||||||||
| for namespace, types in namespaces_to_constructors.items(): | ||||||||||
| with open(DESTINATION_PATH / "types" / namespace / "__init__.py", "w") as f: | ||||||||||
| with open_utf8( | ||||||||||
| DESTINATION_PATH / "types" / namespace / "__init__.py", "w" | ||||||||||
| ) as f: | ||||||||||
| f.write(f"{WARNING}\n\n") | ||||||||||
|
|
||||||||||
| all = [] | ||||||||||
|
|
||||||||||
| for t in types: | ||||||||||
| module = t | ||||||||||
|
|
||||||||||
| if module == "Updates": | ||||||||||
| module = "UpdatesT" | ||||||||||
|
|
||||||||||
| all.append(t) | ||||||||||
|
|
||||||||||
| f.write(f"from .{snake(module)} import {t}\n") | ||||||||||
|
|
||||||||||
| if not namespace: | ||||||||||
| f.write( | ||||||||||
| f"from . import {', '.join(filter(bool, namespaces_to_constructors))}\n", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| all.extend(filter(bool, namespaces_to_constructors)) | ||||||||||
|
|
||||||||||
| f.write("\n\n__all__ = [\n") | ||||||||||
| for it in all: | ||||||||||
| f.write(f' "{it}",\n') | ||||||||||
| f.write("]\n") | ||||||||||
|
|
||||||||||
| for namespace, types in namespaces_to_functions.items(): | ||||||||||
| with open( | ||||||||||
| with open_utf8( | ||||||||||
| DESTINATION_PATH / "functions" / namespace / "__init__.py", | ||||||||||
| "w", | ||||||||||
| ) as f: | ||||||||||
| f.write(f"{WARNING}\n\n") | ||||||||||
|
|
||||||||||
| all = [] | ||||||||||
|
|
||||||||||
| for t in types: | ||||||||||
| module = t | ||||||||||
|
|
||||||||||
| if module == "Updates": | ||||||||||
| module = "UpdatesT" | ||||||||||
|
|
||||||||||
| all.append(t) | ||||||||||
|
|
||||||||||
| f.write(f"from .{snake(module)} import {t}\n") | ||||||||||
|
|
||||||||||
| if not namespace: | ||||||||||
| f.write( | ||||||||||
| f"from . import {', '.join(filter(bool, namespaces_to_functions))}", | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| all.extend(filter(bool, namespaces_to_functions)) | ||||||||||
|
|
||||||||||
| f.write("\n\n__all__ = [\n") | ||||||||||
| for it in all: | ||||||||||
| f.write(f' "{it}",\n') | ||||||||||
| f.write("]\n") | ||||||||||
|
|
||||||||||
| with open(DESTINATION_PATH / "all.py", "w", encoding="utf-8") as f: | ||||||||||
| with open_utf8(DESTINATION_PATH / "all.py", "w") as f: | ||||||||||
| f.write(WARNING + "\n\n") | ||||||||||
| f.write(f"layer = {layer}\n\n") | ||||||||||
| f.write("objects = {") | ||||||||||
|
|
||||||||||
| for c in combinators: | ||||||||||
| f.write(f'\n {c.id}: "pyrogram.raw.{c.section}.{c.qualname}",') | ||||||||||
|
|
||||||||||
| f.write('\n 0xbc799737: "pyrogram.raw.core.BoolFalse",') | ||||||||||
| f.write('\n 0x997275b5: "pyrogram.raw.core.BoolTrue",') | ||||||||||
| f.write('\n 0x1cb5c415: "pyrogram.raw.core.Vector",') | ||||||||||
| f.write('\n 0x73f1f8dc: "pyrogram.raw.core.MsgContainer",') | ||||||||||
| f.write('\n 0xae500895: "pyrogram.raw.core.FutureSalts",') | ||||||||||
| f.write('\n 0x0949d9dc: "pyrogram.raw.core.FutureSalt",') | ||||||||||
| f.write('\n 0x3072cfa1: "pyrogram.raw.core.GzipPacked",') | ||||||||||
| f.write('\n 0x5bb8e511: "pyrogram.raw.core.Message",') | ||||||||||
|
|
||||||||||
| f.write("\n}\n") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| if __name__ == "__main__": | ||||||||||
|
|
||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
f.read()method on a text file (opened without 'b' in the mode) already returns a string. The explicitstr()conversions here are redundant and can be removed for cleaner code.