Skip to content

Add typing for root and core/ python files #105818

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from SCons.Builder import ListEmitter
# folder when doing `import editor.template_builder`)


def _helper_module(name, path):
def _helper_module(name, path) -> None:
spec = spec_from_file_location(name, path)
module = module_from_spec(spec)
spec.loader.exec_module(module)
Expand Down
9 changes: 6 additions & 3 deletions core/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
from misc.utility.scons_hints import *

import os
from typing import TYPE_CHECKING

import core_builders

import methods

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"

Import("env")

env.core_sources = []
Expand Down Expand Up @@ -156,10 +162,8 @@ if env["builtin_zstd"]:

env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources)


env.core_sources += thirdparty_obj


# Godot source files
env.add_source_files(env.core_sources, "*.cpp")

Expand Down Expand Up @@ -222,7 +226,6 @@ SConscript("string/SCsub")
SConscript("config/SCsub")
SConscript("error/SCsub")


# Build it all as a library
lib = env.add_library("core", env.core_sources)
env.Prepend(LIBS=[lib])
Expand Down
6 changes: 6 additions & 0 deletions core/config/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env_config = env.Clone()
Expand Down
13 changes: 8 additions & 5 deletions core/core_builders.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Functions used to generate source files during build time"""

from collections import OrderedDict
from io import TextIOWrapper
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from io import TextIOWrapper

import methods

Expand Down Expand Up @@ -71,7 +74,7 @@ def encryption_key_builder(target, source, env):
)


def make_certs_header(target, source, env):
def make_certs_header(target, source, env) -> None:
buffer = methods.get_buffer(str(source[0]))
decomp_size = len(buffer)
buffer = methods.compress_buffer(buffer)
Expand All @@ -92,7 +95,7 @@ def make_certs_header(target, source, env):
""")


def make_authors_header(target, source, env):
def make_authors_header(target, source, env) -> None:
SECTIONS = {
"Project Founders": "AUTHORS_FOUNDERS",
"Lead Developer": "AUTHORS_LEAD_DEVELOPERS",
Expand Down Expand Up @@ -123,7 +126,7 @@ def close_section():
close_section()


def make_donors_header(target, source, env):
def make_donors_header(target, source, env) -> None:
SECTIONS = {
"Patrons": "DONORS_PATRONS",
"Platinum sponsors": "DONORS_SPONSORS_PLATINUM",
Expand Down Expand Up @@ -163,7 +166,7 @@ def make_license_header(target, source, env):
src_license = str(source[1])

class LicenseReader:
def __init__(self, license_file: TextIOWrapper):
def __init__(self, license_file: "TextIOWrapper"):
self._license_file = license_file
self.line_num = 0
self.current = self.next_line()
Expand Down
6 changes: 6 additions & 0 deletions core/crypto/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env_crypto = env.Clone()
Expand Down
6 changes: 6 additions & 0 deletions core/debugger/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env.add_source_files(env.core_sources, "*.cpp")
6 changes: 6 additions & 0 deletions core/error/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env_error = env.Clone()
Expand Down
6 changes: 6 additions & 0 deletions core/extension/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

import make_interface_dumper
Expand Down
2 changes: 1 addition & 1 deletion core/extension/make_interface_dumper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import methods


def run(target, source, env):
def run(target, source, env) -> None:
buffer = methods.get_buffer(str(source[0]))
decomp_size = len(buffer)
buffer = methods.compress_buffer(buffer)
Expand Down
10 changes: 7 additions & 3 deletions core/extension/make_wrappers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import PositiveInt
proto_mod = """
#define MODBIND$VER($RETTYPE m_name$ARG) \\
virtual $RETVAL _##m_name($FUNCARGS) $CONST; \\
Expand All @@ -7,7 +11,7 @@
"""


def generate_mod_version(argcount, const=False, returns=False):
def generate_mod_version(argcount: "PositiveInt", const: bool = False, returns: bool = False) -> str:
s = proto_mod
sproto = str(argcount)
if returns:
Expand Down Expand Up @@ -64,7 +68,7 @@ def generate_mod_version(argcount, const=False, returns=False):
"""


def generate_ex_version(argcount, const=False, returns=False):
def generate_ex_version(argcount: "PositiveInt", const: bool = False, returns: bool = False) -> str:
s = proto_ex
sproto = str(argcount)
if returns:
Expand Down Expand Up @@ -116,7 +120,7 @@ def generate_ex_version(argcount, const=False, returns=False):
return s


def run(target, source, env):
def run(target, source, env) -> None:
max_versions = 12

txt = "#pragma once"
Expand Down
6 changes: 6 additions & 0 deletions core/input/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

import input_builders
Expand Down
5 changes: 3 additions & 2 deletions core/input/input_builders.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Functions used to generate source files during build time"""

from collections import OrderedDict
from typing import Any

import methods


def make_default_controller_mappings(target, source, env):
def make_default_controller_mappings(target, source, env) -> None:
with methods.generated_wrapper(str(target[0])) as file:
file.write("""\
#include "core/input/default_controller_mappings.h"
Expand All @@ -15,7 +16,7 @@ def make_default_controller_mappings(target, source, env):
""")

# ensure mappings have a consistent order
platform_mappings = OrderedDict()
platform_mappings: OrderedDict[Any, Any] = OrderedDict()
for src_path in map(str, source):
with open(src_path, "r", encoding="utf-8") as f:
# read mapping file and skip header
Expand Down
6 changes: 6 additions & 0 deletions core/io/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env.add_source_files(env.core_sources, "*.cpp")
6 changes: 6 additions & 0 deletions core/math/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env_math = env.Clone()
Expand Down
6 changes: 6 additions & 0 deletions core/object/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

import make_virtuals
Expand Down
10 changes: 8 additions & 2 deletions core/object/make_virtuals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import PositiveInt
script_call = """ScriptInstance *_script_instance = ((Object *)(this))->get_script_instance();\\
if (_script_instance) {\\
Callable::CallError ce;\\
Expand Down Expand Up @@ -88,7 +92,9 @@
"""


def generate_version(argcount, const=False, returns=False, required=False, compat=False):
def generate_version(
argcount: "PositiveInt", const: bool = False, returns: bool = False, required: bool = False, compat: bool = False
) -> str:
s = proto
if compat:
s = s.replace("$SCRIPTCALL", "")
Expand Down Expand Up @@ -211,7 +217,7 @@ def generate_version(argcount, const=False, returns=False, required=False, compa
return s


def run(target, source, env):
def run(target, source, env) -> None:
max_versions = 12

txt = """/* THIS FILE IS GENERATED DO NOT EDIT */
Expand Down
6 changes: 6 additions & 0 deletions core/os/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env.add_source_files(env.core_sources, "*.cpp")
6 changes: 6 additions & 0 deletions core/string/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env_string = env.Clone()
Expand Down
6 changes: 6 additions & 0 deletions core/templates/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env_templates = env.Clone()
Expand Down
6 changes: 6 additions & 0 deletions core/variant/SCsub
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from godot_typing import GodotSConsEnvironment

env: "GodotSConsEnvironment"
Import("env")

env_variant = env.Clone()
Expand Down
Loading