diff --git a/.clang-format b/.clang-format index 1df6c35bf..87731d9eb 100644 --- a/.clang-format +++ b/.clang-format @@ -1,80 +1,105 @@ # Commented out parameters are those with the same value as base LLVM style. # We can uncomment them if we want to change their value, or enforce the -# chosen value in case the base style changes (last sync: Clang 14.0). ---- -### General config, applies to all languages ### -BasedOnStyle: LLVM +# chosen value in case the base style changes (last sync: Clang 17.0.6). +BasedOnStyle: LLVM AccessModifierOffset: -4 AlignAfterOpenBracket: DontAlign # AlignArrayOfStructures: None -# AlignConsecutiveMacros: None -# AlignConsecutiveAssignments: None -# AlignConsecutiveBitFields: None -# AlignConsecutiveDeclarations: None +# AlignConsecutiveAssignments: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# PadOperators: true +# AlignConsecutiveBitFields: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# PadOperators: false +# AlignConsecutiveDeclarations: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# PadOperators: false +# AlignConsecutiveMacros: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCompound: false +# PadOperators: false +# AlignConsecutiveShortCaseStatements: +# Enabled: false +# AcrossEmptyLines: false +# AcrossComments: false +# AlignCaseColons: false # AlignEscapedNewlines: Right -AlignOperands: DontAlign -AlignTrailingComments: false +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 # AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false -# AllowShortEnumsOnASingleLine: true # AllowShortBlocksOnASingleLine: Never # AllowShortCaseLabelsOnASingleLine: false -# AllowShortFunctionsOnASingleLine: All -# AllowShortLambdasOnASingleLine: All +# AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Inline # AllowShortIfStatementsOnASingleLine: Never +# AllowShortLambdasOnASingleLine: All # AllowShortLoopsOnASingleLine: false # AlwaysBreakAfterDefinitionReturnType: None # AlwaysBreakAfterReturnType: None # AlwaysBreakBeforeMultilineStrings: false # AlwaysBreakTemplateDeclarations: MultiLine -# AttributeMacros: -# - __capability +AttributeMacros: + - _ALWAYS_INLINE_ + - _FORCE_INLINE_ + - _NO_INLINE_ # BinPackArguments: true # BinPackParameters: true +# BitFieldColonSpacing: Both # BraceWrapping: -# AfterCaseLabel: false -# AfterClass: false +# AfterCaseLabel: false +# AfterClass: false # AfterControlStatement: Never -# AfterEnum: false -# AfterFunction: false -# AfterNamespace: false +# AfterEnum: false +# AfterFunction: false +# AfterNamespace: false # AfterObjCDeclaration: false -# AfterStruct: false -# AfterUnion: false +# AfterStruct: false +# AfterUnion: false # AfterExternBlock: false -# BeforeCatch: false -# BeforeElse: false +# BeforeCatch: false +# BeforeElse: false # BeforeLambdaBody: false -# BeforeWhile: false -# IndentBraces: false +# BeforeWhile: false +# IndentBraces: false # SplitEmptyFunction: true # SplitEmptyRecord: true # SplitEmptyNamespace: true +# BreakAfterAttributes: Never +# BreakAfterJavaFieldAnnotations: false +# BreakArrays: true # BreakBeforeBinaryOperators: None -# BreakBeforeConceptDeclarations: true # BreakBeforeBraces: Attach -# BreakBeforeInheritanceComma: false -# BreakInheritanceList: BeforeColon +# BreakBeforeConceptDeclarations: Always +# BreakBeforeInlineASMColon: OnlyMultiline # BreakBeforeTernaryOperators: true -# BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: AfterColon +# BreakInheritanceList: BeforeColon # BreakStringLiterals: true -ColumnLimit: 0 -# CommentPragmas: '^ IWYU pragma:' -# QualifierAlignment: Leave +ColumnLimit: 0 +# CommentPragmas: "^ IWYU pragma:" # CompactNamespaces: false ConstructorInitializerIndentWidth: 8 ContinuationIndentWidth: 8 Cpp11BracedListStyle: false -# DeriveLineEnding: true # DerivePointerAlignment: false -# DisableFormat: false +# DisableFormat: false # EmptyLineAfterAccessModifier: Never # EmptyLineBeforeAccessModifier: LogicalBlock # ExperimentalAutoDetectBinPacking: false -# PackConstructorInitializers: BinPack -ConstructorInitializerAllOnOneLineOrOnePerLine: true -# AllowAllConstructorInitializersOnNextLine: true # FixNamespaceComments: true # ForEachMacros: # - foreach @@ -82,34 +107,61 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true # - BOOST_FOREACH # IfMacros: # - KJ_IF_MAYBE -# IncludeBlocks: Preserve +# IncludeBlocks: Preserve IncludeCategories: - - Regex: '".*"' - Priority: 1 - - Regex: '^<.*\.h>' - Priority: 2 - - Regex: '^<.*' - Priority: 3 -# IncludeIsMainRegex: '(Test)?$' -# IncludeIsMainSourceRegex: '' + - Regex: ^".*"$ + Priority: 1 + - Regex: ^<.*\.h>$ + Priority: 2 + - Regex: ^<.*>$ + Priority: 3 +# IncludeIsMainRegex: (Test)?$ +# IncludeIsMainSourceRegex: "" # IndentAccessModifiers: false -IndentCaseLabels: true # IndentCaseBlocks: false +IndentCaseLabels: true +# IndentExternBlock: AfterExternBlock # IndentGotoLabels: true # IndentPPDirectives: None -# IndentExternBlock: AfterExternBlock -# IndentRequires: false -IndentWidth: 4 +# IndentRequiresClause: true +IndentWidth: 4 # IndentWrappedFunctionNames: false +InsertBraces: true +# InsertNewlineAtEOF: false # InsertTrailingCommas: None +# IntegerLiteralSeparator: +# Binary: 0 +# BinaryMinDigits: 0 +# Decimal: 0 +# DecimalMinDigits: 0 +# Hex: 0 +# HexMinDigits: 0 +JavaImportGroups: + - org.godotengine + - android + - androidx + - com.android + - com.google + - java + - javax # JavaScriptQuotes: Leave # JavaScriptWrapImports: true +# KeepEmptyLinesAtEOF: false KeepEmptyLinesAtTheStartOfBlocks: false # LambdaBodyIndentation: Signature -# MacroBlockBegin: '' -# MacroBlockEnd: '' +# Language: Cpp +# LineEnding: DeriveLF +# MacroBlockBegin: "" +# MacroBlockEnd: "" # MaxEmptyLinesToKeep: 1 # NamespaceIndentation: None +# ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +# ObjCBreakBeforeNestedBlockParam: true +# ObjCSpaceAfterProperty: false +# ObjCSpaceBeforeProtocolList: true +# PPIndentWidth: -1 +PackConstructorInitializers: NextLine # PenaltyBreakAssignment: 2 # PenaltyBreakBeforeFirstCallParameter: 19 # PenaltyBreakComment: 300 @@ -118,82 +170,71 @@ KeepEmptyLinesAtTheStartOfBlocks: false # PenaltyBreakString: 1000 # PenaltyBreakTemplateDeclaration: 10 # PenaltyExcessCharacter: 1000000 -# PenaltyReturnTypeOnItsOwnLine: 60 # PenaltyIndentedWhitespace: 0 +# PenaltyReturnTypeOnItsOwnLine: 60 # PointerAlignment: Right -# PPIndentWidth: -1 +# QualifierAlignment: Leave # ReferenceAlignment: Pointer -# ReflowComments: true +# ReflowComments: true # RemoveBracesLLVM: false +# RemoveParentheses: Leave +RemoveSemicolon: true +# RequiresClausePosition: OwnLine +# RequiresExpressionIndentation: OuterScope # SeparateDefinitionBlocks: Leave # ShortNamespaceLines: 1 -# SortIncludes: CaseSensitive +# SortIncludes: CaseSensitive # SortJavaStaticImport: Before -# SortUsingDeclarations: true +# SortUsingDeclarations: LexicographicNumeric # SpaceAfterCStyleCast: false # SpaceAfterLogicalNot: false # SpaceAfterTemplateKeyword: true +# SpaceAroundPointerQualifiers: Default # SpaceBeforeAssignmentOperators: true # SpaceBeforeCaseColon: false # SpaceBeforeCpp11BracedList: false # SpaceBeforeCtorInitializerColon: true # SpaceBeforeInheritanceColon: true +# SpaceBeforeJsonColon: false # SpaceBeforeParens: ControlStatements # SpaceBeforeParensOptions: # AfterControlStatements: true # AfterForeachMacros: true -# AfterFunctionDefinitionName: false # AfterFunctionDeclarationName: false -# AfterIfMacros: true +# AfterFunctionDefinitionName: false +# AfterIfMacros: true # AfterOverloadedOperator: false +# AfterRequiresInClause: false +# AfterRequiresInExpression: false # BeforeNonEmptyParentheses: false -# SpaceAroundPointerQualifiers: Default # SpaceBeforeRangeBasedForLoopColon: true +# SpaceBeforeSquareBrackets: false # SpaceInEmptyBlock: false -# SpaceInEmptyParentheses: false # SpacesBeforeTrailingComments: 1 -# SpacesInAngles: Never -# SpacesInConditionalStatement: false +# SpacesInAngles: Never # SpacesInContainerLiterals: true -# SpacesInCStyleCastParentheses: false -## Godot TODO: We'll want to use a min of 1, but we need to see how to fix -## our comment capitalization at the same time. SpacesInLineCommentPrefix: - Minimum: 0 - Maximum: -1 -# SpacesInParentheses: false + Minimum: 0 # We want a minimum of 1 for comments, but allow 0 for disabled code. + Maximum: -1 +# SpacesInParens: Never +# SpacesInParensOptions: +# InConditionalStatements: false +# InCStyleCasts: false +# InEmptyParentheses: false +# Other: false # SpacesInSquareBrackets: false -# SpaceBeforeSquareBrackets: false -# BitFieldColonSpacing: Both +Standard: c++20 # StatementAttributeLikeMacros: # - Q_EMIT # StatementMacros: # - Q_UNUSED # - QT_REQUIRE_VERSION -TabWidth: 4 -# UseCRLF: false -UseTab: Always +TabWidth: 4 +UseTab: Always +# VerilogBreakBetweenInstancePorts: true # WhitespaceSensitiveMacros: -# - STRINGIZE -# - PP_STRINGIZE # - BOOST_PP_STRINGIZE -# - NS_SWIFT_NAME # - CF_SWIFT_NAME ---- -### C++ specific config ### -Language: Cpp -Standard: c++17 ---- -### ObjC specific config ### -Language: ObjC -# ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 4 -# ObjCBreakBeforeNestedBlockParam: true -# ObjCSpaceAfterProperty: false -# ObjCSpaceBeforeProtocolList: true ---- -### Java specific config ### -Language: Java -# BreakAfterJavaFieldAnnotations: false -JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax'] -... +# - NS_SWIFT_NAME +# - PP_STRINGIZE +# - STRINGIZE diff --git a/.editorconfig b/.editorconfig index f14ac7f14..0da03e8a7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,11 +6,12 @@ end_of_line = lf indent_size = 4 indent_style = tab insert_final_newline = true +max_line_length = 120 trim_trailing_whitespace = true [{*.py,SConstruct}] indent_style = space -[*.{yml,yaml}] +[{*.{yml,yaml},.clang-format}] indent_size = 2 indent_style = space diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7354ba41f..e370058f4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,32 +9,36 @@ exclude: | repos: - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v17.0.6 + rev: v20.1.0 hooks: - id: clang-format - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.4 + rev: v0.11.4 hooks: - id: ruff args: [--fix] + files: (\.py|SConstruct)$ + types_or: [text] - id: ruff-format + files: (\.py|SConstruct)$ + types_or: [text] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.971 + rev: v1.14.1 # Latest version that supports Python 3.8 hooks: - id: mypy files: \.py$ types_or: [text] - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell additional_dependencies: [tomli] - repo: https://github.com/BlankSpruce/gersemi - rev: 0.18.2 + rev: 0.19.2 hooks: - id: gersemi args: ["-i", "--no-warn-about-unknown-commands", "-l", "120"] diff --git a/SConstruct b/SConstruct index 8acea2624..64d335b5d 100644 --- a/SConstruct +++ b/SConstruct @@ -3,7 +3,7 @@ import os EnsureSConsVersion(4, 0) - +EnsurePythonVersion(3, 8) try: Import("env") diff --git a/binding_generator.py b/binding_generator.py index 8dabe578a..134789ea2 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -356,7 +356,7 @@ def generate_builtin_bindings(api, output_dir, build_config): add_header("variant_size.hpp", variant_size_source) variant_size_source.append("#pragma once") - variant_size_source.append(f'#define GODOT_CPP_VARIANT_SIZE {builtin_sizes["Variant"]}') + variant_size_source.append(f"#define GODOT_CPP_VARIANT_SIZE {builtin_sizes['Variant']}") variant_size_file.write("\n".join(variant_size_source)) @@ -601,19 +601,19 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl if "constructors" in builtin_api: for constructor in builtin_api["constructors"]: - result.append(f'\t\tGDExtensionPtrConstructor constructor_{constructor["index"]};') + result.append(f"\t\tGDExtensionPtrConstructor constructor_{constructor['index']};") if builtin_api["has_destructor"]: result.append("\t\tGDExtensionPtrDestructor destructor;") if "methods" in builtin_api: for method in builtin_api["methods"]: - result.append(f'\t\tGDExtensionPtrBuiltInMethod method_{method["name"]};') + result.append(f"\t\tGDExtensionPtrBuiltInMethod method_{method['name']};") if "members" in builtin_api: for member in builtin_api["members"]: - result.append(f'\t\tGDExtensionPtrSetter member_{member["name"]}_setter;') - result.append(f'\t\tGDExtensionPtrGetter member_{member["name"]}_getter;') + result.append(f"\t\tGDExtensionPtrSetter member_{member['name']}_setter;") + result.append(f"\t\tGDExtensionPtrGetter member_{member['name']}_getter;") if "indexing_return_type" in builtin_api: result.append("\t\tGDExtensionPtrIndexedSetter indexed_setter;") @@ -628,10 +628,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl for operator in builtin_api["operators"]: if "right_type" in operator: result.append( - f'\t\tGDExtensionPtrOperatorEvaluator operator_{get_operator_id_name(operator["name"])}_{operator["right_type"]};' + f"\t\tGDExtensionPtrOperatorEvaluator operator_{get_operator_id_name(operator['name'])}_{operator['right_type']};" ) else: - result.append(f'\t\tGDExtensionPtrOperatorEvaluator operator_{get_operator_id_name(operator["name"])};') + result.append(f"\t\tGDExtensionPtrOperatorEvaluator operator_{get_operator_id_name(operator['name'])};") result.append("\t} _method_bindings;") @@ -693,12 +693,12 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl if class_name == "Vector3" and constant["name"].startswith("AXIS"): if axis_constants_count == 0: result.append("\tenum Axis {") - result.append(f'\t\t{constant["name"]} = {constant["value"]},') + result.append(f"\t\t{constant['name']} = {constant['value']},") axis_constants_count += 1 if axis_constants_count == 3: result.append("\t};") else: - result.append(f'\tstatic const {correct_type(constant["type"])} {constant["name"]};') + result.append(f"\tstatic const {correct_type(constant['type'])} {constant['name']};") if builtin_api["has_destructor"]: result.append(f"\t~{class_name}();") @@ -718,13 +718,13 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl method_signature += "static " if "return_type" in method: - method_signature += f'{correct_type(method["return_type"])}' + method_signature += f"{correct_type(method['return_type'])}" if not method_signature.endswith("*"): method_signature += " " else: method_signature += "void " - method_signature += f'{method["name"]}(' + method_signature += f"{method['name']}(" method_arguments = [] if "arguments" in method: @@ -759,21 +759,21 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl if "members" in builtin_api: for member in builtin_api["members"]: - if f'get_{member["name"]}' not in method_list: - result.append(f'\t{correct_type(member["type"])} get_{member["name"]}() const;') - if f'set_{member["name"]}' not in method_list: - result.append(f'\tvoid set_{member["name"]}({type_for_parameter(member["type"])}value);') + if f"get_{member['name']}" not in method_list: + result.append(f"\t{correct_type(member['type'])} get_{member['name']}() const;") + if f"set_{member['name']}" not in method_list: + result.append(f"\tvoid set_{member['name']}({type_for_parameter(member['type'])}value);") if "operators" in builtin_api: for operator in builtin_api["operators"]: if is_valid_cpp_operator(operator["name"]): if "right_type" in operator: result.append( - f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const;' + f"\t{correct_type(operator['return_type'])} operator{get_operator_cpp_name(operator['name'])}({type_for_parameter(operator['right_type'])}p_other) const;" ) else: result.append( - f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}() const;' + f"\t{correct_type(operator['return_type'])} operator{get_operator_cpp_name(operator['name'])}() const;" ) # Copy assignment. @@ -1041,7 +1041,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl if "constructors" in builtin_api: for constructor in builtin_api["constructors"]: result.append( - f'\t_method_bindings.constructor_{constructor["index"]} = internal::gdextension_interface_variant_get_ptr_constructor({enum_type_name}, {constructor["index"]});' + f"\t_method_bindings.constructor_{constructor['index']} = internal::gdextension_interface_variant_get_ptr_constructor({enum_type_name}, {constructor['index']});" ) if builtin_api["has_destructor"]: @@ -1065,17 +1065,17 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl # TODO: Add error check for hash mismatch. result.append(f'\t_gde_name = StringName("{method["name"]}");') result.append( - f'\t_method_bindings.method_{method["name"]} = internal::gdextension_interface_variant_get_ptr_builtin_method({enum_type_name}, _gde_name._native_ptr(), {method["hash"]});' + f"\t_method_bindings.method_{method['name']} = internal::gdextension_interface_variant_get_ptr_builtin_method({enum_type_name}, _gde_name._native_ptr(), {method['hash']});" ) if "members" in builtin_api: for member in builtin_api["members"]: result.append(f'\t_gde_name = StringName("{member["name"]}");') result.append( - f'\t_method_bindings.member_{member["name"]}_setter = internal::gdextension_interface_variant_get_ptr_setter({enum_type_name}, _gde_name._native_ptr());' + f"\t_method_bindings.member_{member['name']}_setter = internal::gdextension_interface_variant_get_ptr_setter({enum_type_name}, _gde_name._native_ptr());" ) result.append( - f'\t_method_bindings.member_{member["name"]}_getter = internal::gdextension_interface_variant_get_ptr_getter({enum_type_name}, _gde_name._native_ptr());' + f"\t_method_bindings.member_{member['name']}_getter = internal::gdextension_interface_variant_get_ptr_getter({enum_type_name}, _gde_name._native_ptr());" ) if "indexing_return_type" in builtin_api: @@ -1107,11 +1107,11 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl f"GDEXTENSION_VARIANT_TYPE_{camel_to_snake(operator['right_type']).upper()}" ) result.append( - f'\t_method_bindings.operator_{get_operator_id_name(operator["name"])}_{operator["right_type"]} = internal::gdextension_interface_variant_get_ptr_operator_evaluator(GDEXTENSION_VARIANT_OP_{get_operator_id_name(operator["name"]).upper()}, {enum_type_name}, {right_type_variant_type});' + f"\t_method_bindings.operator_{get_operator_id_name(operator['name'])}_{operator['right_type']} = internal::gdextension_interface_variant_get_ptr_operator_evaluator(GDEXTENSION_VARIANT_OP_{get_operator_id_name(operator['name']).upper()}, {enum_type_name}, {right_type_variant_type});" ) else: result.append( - f'\t_method_bindings.operator_{get_operator_id_name(operator["name"])} = internal::gdextension_interface_variant_get_ptr_operator_evaluator(GDEXTENSION_VARIANT_OP_{get_operator_id_name(operator["name"]).upper()}, {enum_type_name}, GDEXTENSION_VARIANT_TYPE_NIL);' + f"\t_method_bindings.operator_{get_operator_id_name(operator['name'])} = internal::gdextension_interface_variant_get_ptr_operator_evaluator(GDEXTENSION_VARIANT_OP_{get_operator_id_name(operator['name']).upper()}, {enum_type_name}, GDEXTENSION_VARIANT_TYPE_NIL);" ) result.append("}") @@ -1136,7 +1136,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl result.append(method_signature) method_call = ( - f'\tinternal::_call_builtin_constructor(_method_bindings.constructor_{constructor["index"]}, &opaque' + f"\tinternal::_call_builtin_constructor(_method_bindings.constructor_{constructor['index']}, &opaque" ) if "arguments" in constructor: if len(constructor["arguments"]) == 1 and constructor["arguments"][0]["type"] == class_name: @@ -1204,7 +1204,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl method_call += f"return internal::_call_builtin_method_ptr_ret_obj<{return_type}>(" else: method_call += "internal::_call_builtin_method_ptr_no_ret(" - method_call += f'_method_bindings.method_{method["name"]}, ' + method_call += f"_method_bindings.method_{method['name']}, " if "is_static" in method and method["is_static"]: method_call += "nullptr" else: @@ -1233,19 +1233,19 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl if "members" in builtin_api: for member in builtin_api["members"]: - if f'get_{member["name"]}' not in method_list: - result.append(f'{correct_type(member["type"])} {class_name}::get_{member["name"]}() const {{') + if f"get_{member['name']}" not in method_list: + result.append(f"{correct_type(member['type'])} {class_name}::get_{member['name']}() const {{") result.append( - f'\treturn internal::_call_builtin_ptr_getter<{correct_type(member["type"])}>(_method_bindings.member_{member["name"]}_getter, (GDExtensionConstTypePtr)&opaque);' + f"\treturn internal::_call_builtin_ptr_getter<{correct_type(member['type'])}>(_method_bindings.member_{member['name']}_getter, (GDExtensionConstTypePtr)&opaque);" ) result.append("}") - if f'set_{member["name"]}' not in method_list: - result.append(f'void {class_name}::set_{member["name"]}({type_for_parameter(member["type"])}value) {{') + if f"set_{member['name']}" not in method_list: + result.append(f"void {class_name}::set_{member['name']}({type_for_parameter(member['type'])}value) {{") (encode, arg_name) = get_encoded_arg("value", member["type"], None) result += encode result.append( - f'\t_method_bindings.member_{member["name"]}_setter((GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr){arg_name});' + f"\t_method_bindings.member_{member['name']}_setter((GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr){arg_name});" ) result.append("}") @@ -1256,20 +1256,20 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl if is_valid_cpp_operator(operator["name"]): if "right_type" in operator: result.append( - f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const {{' + f"{correct_type(operator['return_type'])} {class_name}::operator{get_operator_cpp_name(operator['name'])}({type_for_parameter(operator['right_type'])}p_other) const {{" ) (encode, arg_name) = get_encoded_arg("other", operator["right_type"], None) result += encode result.append( - f'\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator["return_type"]))}>(_method_bindings.operator_{get_operator_id_name(operator["name"])}_{operator["right_type"]}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr){arg_name});' + f"\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator['return_type']))}>(_method_bindings.operator_{get_operator_id_name(operator['name'])}_{operator['right_type']}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr){arg_name});" ) result.append("}") else: result.append( - f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}() const {{' + f"{correct_type(operator['return_type'])} {class_name}::operator{get_operator_cpp_name(operator['name'])}() const {{" ) result.append( - f'\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator["return_type"]))}>(_method_bindings.operator_{get_operator_id_name(operator["name"])}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr) nullptr);' + f"\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator['return_type']))}>(_method_bindings.operator_{get_operator_id_name(operator['name'])}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr) nullptr);" ) result.append("}") result.append("") @@ -1638,12 +1638,12 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us if "enums" in class_api: for enum_api in class_api["enums"]: if enum_api["is_bitfield"]: - result.append(f'\tenum {enum_api["name"]} : uint64_t {{') + result.append(f"\tenum {enum_api['name']} : uint64_t {{") else: - result.append(f'\tenum {enum_api["name"]} {{') + result.append(f"\tenum {enum_api['name']} {{") for value in enum_api["values"]: - result.append(f'\t\t{value["name"]} = {value["value"]},') + result.append(f"\t\t{value['name']} = {value['value']},") result.append("\t};") result.append("") @@ -1651,7 +1651,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us for value in class_api["constants"]: if "type" not in value: value["type"] = "int" - result.append(f'\tstatic const {value["type"]} {value["name"]} = {value["value"]};') + result.append(f"\tstatic const {value['type']} {value['name']} = {value['value']};") result.append("") if is_singleton: @@ -1774,9 +1774,9 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us if "enums" in class_api and class_name != "Object": for enum_api in class_api["enums"]: if enum_api["is_bitfield"]: - result.append(f'VARIANT_BITFIELD_CAST({class_name}::{enum_api["name"]});') + result.append(f"VARIANT_BITFIELD_CAST({class_name}::{enum_api['name']});") else: - result.append(f'VARIANT_ENUM_CAST({class_name}::{enum_api["name"]});') + result.append(f"VARIANT_ENUM_CAST({class_name}::{enum_api['name']});") result.append("") if class_name == "ClassDBSingleton": @@ -1785,12 +1785,12 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us if "enums" in class_api: for enum_api in class_api["enums"]: if enum_api["is_bitfield"]: - result.append(f'\tenum {enum_api["name"]} : uint64_t {{ \\') + result.append(f"\tenum {enum_api['name']} : uint64_t {{ \\") else: - result.append(f'\tenum {enum_api["name"]} {{ \\') + result.append(f"\tenum {enum_api['name']} {{ \\") for value in enum_api["values"]: - result.append(f'\t\t{value["name"]} = {value["value"]}, \\') + result.append(f"\t\t{value['name']} = {value['value']}, \\") result.append("\t}; \\") result.append("\t \\") @@ -1821,7 +1821,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us else: method_signature += "void " - method_signature += f'{method["name"]}(' + method_signature += f"{method['name']}(" method_arguments = [] if "arguments" in method: @@ -1840,7 +1840,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us method_body += "return " if "alias_for" in class_api and return_type.startswith(class_api["alias_for"] + "::"): method_body += f"({return_type})" - method_body += f'ClassDBSingleton::get_singleton()->{method["name"]}(' + method_body += f"ClassDBSingleton::get_singleton()->{method['name']}(" method_body += ", ".join(map(lambda x: escape_argument(x["name"]), method_arguments)) if vararg: method_body += ", p_args..." @@ -1856,9 +1856,9 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us if "enums" in class_api: for enum_api in class_api["enums"]: if enum_api["is_bitfield"]: - result.append(f'\tVARIANT_BITFIELD_CAST({class_api["alias_for"]}::{enum_api["name"]}); \\') + result.append(f"\tVARIANT_BITFIELD_CAST({class_api['alias_for']}::{enum_api['name']}); \\") else: - result.append(f'\tVARIANT_ENUM_CAST({class_api["alias_for"]}::{enum_api["name"]}); \\') + result.append(f"\tVARIANT_ENUM_CAST({class_api['alias_for']}::{enum_api['name']}); \\") result.append("\t") result.append("") @@ -1955,7 +1955,7 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us if has_return: result.append( - f'\tCHECK_METHOD_BIND_RET(_gde_method_bind, ({get_default_value_for_type(method["return_value"]["type"])}));' + f"\tCHECK_METHOD_BIND_RET(_gde_method_bind, ({get_default_value_for_type(method['return_value']['type'])}));" ) else: result.append("\tCHECK_METHOD_BIND(_gde_method_bind);") @@ -2037,7 +2037,7 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us method_signature += " {" if "return_value" in method and correct_type(method["return_value"]["type"]) != "void": result.append(method_signature) - result.append(f'\treturn {get_default_value_for_type(method["return_value"]["type"])};') + result.append(f"\treturn {get_default_value_for_type(method['return_value']['type'])};") result.append("}") else: method_signature += "}" @@ -2073,7 +2073,7 @@ def generate_global_constants(api, output_dir): if len(api["global_constants"]) > 0: for constant in api["global_constants"]: - header.append(f'const int64_t {escape_identifier(constant["name"])} = {constant["value"]};') + header.append(f"const int64_t {escape_identifier(constant['name'])} = {constant['value']};") header.append("") @@ -2082,12 +2082,12 @@ def generate_global_constants(api, output_dir): continue if enum_def["is_bitfield"]: - header.append(f'enum {enum_def["name"]} : uint64_t {{') + header.append(f"enum {enum_def['name']} : uint64_t {{") else: - header.append(f'enum {enum_def["name"]} {{') + header.append(f"enum {enum_def['name']} {{") for value in enum_def["values"]: - header.append(f'\t{value["name"]} = {value["value"]},') + header.append(f"\t{value['name']} = {value['value']},") header.append("};") header.append("") @@ -2115,8 +2115,8 @@ def generate_version_header(api, output_dir): header.append(f"#define GODOT_VERSION_MAJOR {api['header']['version_major']}") header.append(f"#define GODOT_VERSION_MINOR {api['header']['version_minor']}") header.append(f"#define GODOT_VERSION_PATCH {api['header']['version_patch']}") - header.append(f"#define GODOT_VERSION_STATUS \"{api['header']['version_status']}\"") - header.append(f"#define GODOT_VERSION_BUILD \"{api['header']['version_build']}\"") + header.append(f'#define GODOT_VERSION_STATUS "{api["header"]["version_status"]}"') + header.append(f'#define GODOT_VERSION_BUILD "{api["header"]["version_build"]}"') header.append("") @@ -2148,9 +2148,9 @@ def generate_global_constant_binds(api, output_dir): continue if enum_def["is_bitfield"]: - header.append(f'VARIANT_BITFIELD_CAST({enum_def["name"]});') + header.append(f"VARIANT_BITFIELD_CAST({enum_def['name']});") else: - header.append(f'VARIANT_ENUM_CAST({enum_def["name"]});') + header.append(f"VARIANT_ENUM_CAST({enum_def['name']});") # Variant::Type is not a global enum, but only one line, it is worth to place in this file instead of creating new file. header.append("VARIANT_ENUM_CAST(godot::Variant::Type);") @@ -2249,7 +2249,7 @@ def generate_utility_functions(api, output_dir): has_return = "return_type" in function and function["return_type"] != "void" if has_return: source.append( - f'\tCHECK_METHOD_BIND_RET(_gde_function, ({get_default_value_for_type(function["return_type"])}));' + f"\tCHECK_METHOD_BIND_RET(_gde_function, ({get_default_value_for_type(function['return_type'])}));" ) else: source.append("\tCHECK_METHOD_BIND(_gde_function);") @@ -2261,7 +2261,7 @@ def generate_utility_functions(api, output_dir): if function["return_type"] == "Object": function_call += "internal::_call_utility_ret_obj(_gde_function" else: - function_call += f'internal::_call_utility_ret<{get_gdextension_type(correct_type(function["return_type"]))}>(_gde_function' + function_call += f"internal::_call_utility_ret<{get_gdextension_type(correct_type(function['return_type']))}>(_gde_function" else: function_call += "internal::_call_utility_no_ret(_gde_function" @@ -2279,7 +2279,7 @@ def generate_utility_functions(api, output_dir): function_call += ", ".join(arguments) else: if has_return: - source.append(f'\t{get_gdextension_type(correct_type(function["return_type"]))} ret;') + source.append(f"\t{get_gdextension_type(correct_type(function['return_type']))} ret;") else: source.append("\tVariant ret;") function_call += "_gde_function(&ret, reinterpret_cast(p_args), p_arg_count" @@ -2473,7 +2473,7 @@ def make_varargs_template( if len(class_befor_signature) > 0: function_signature += class_befor_signature + "::" - function_signature += f'{escape_identifier(function_data["name"])}' + function_signature += f"{escape_identifier(function_data['name'])}" method_arguments = [] if "arguments" in function_data: @@ -2498,7 +2498,7 @@ def make_varargs_template( if argument["type"] == "Variant": args_array += escape_argument(argument["name"]) else: - args_array += f'Variant({escape_argument(argument["name"])})' + args_array += f"Variant({escape_argument(argument['name'])})" args_array += ", " args_array += "Variant(p_args)... }};" @@ -2514,7 +2514,7 @@ def make_varargs_template( if return_type != "void": call_line += "return " - call_line += f'{escape_identifier(function_data["name"])}_internal(call_args.data(), variant_args.size());' + call_line += f"{escape_identifier(function_data['name'])}_internal(call_args.data(), variant_args.size());" result.append(call_line) else: base = "(GDExtensionTypePtr)&opaque" @@ -2524,7 +2524,7 @@ def make_varargs_template( ret = "nullptr" if return_type != "void": ret = "&ret" - result.append(f'\t{correct_type(function_data["return_type"])} ret;') + result.append(f"\t{correct_type(function_data['return_type'])} ret;") function_name = function_data["name"] result.append( diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 2b4a9035e..15d0a492b 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -192,7 +192,9 @@ private: friend class ::godot::Wrapped; \ \ protected: \ - virtual bool _is_extension_class() const override { return true; } \ + virtual bool _is_extension_class() const override { \ + return true; \ + } \ \ static const ::godot::StringName *_get_extension_class_name() { \ const ::godot::StringName &string_name = get_class_static(); \ @@ -204,35 +206,35 @@ protected: } \ \ static void (::godot::Wrapped::*_get_notification())(int) { \ - return (void(::godot::Wrapped::*)(int)) & m_class::_notification; \ + return (void (::godot::Wrapped::*)(int)) & m_class::_notification; \ } \ \ static bool (::godot::Wrapped::*_get_set())(const ::godot::StringName &p_name, const ::godot::Variant &p_property) { \ - return (bool(::godot::Wrapped::*)(const ::godot::StringName &p_name, const ::godot::Variant &p_property)) & m_class::_set; \ + return (bool (::godot::Wrapped::*)(const ::godot::StringName &p_name, const ::godot::Variant &p_property)) & m_class::_set; \ } \ \ static bool (::godot::Wrapped::*_get_get())(const ::godot::StringName &p_name, ::godot::Variant &r_ret) const { \ - return (bool(::godot::Wrapped::*)(const ::godot::StringName &p_name, ::godot::Variant &r_ret) const) & m_class::_get; \ + return (bool (::godot::Wrapped::*)(const ::godot::StringName &p_name, ::godot::Variant &r_ret) const) & m_class::_get; \ } \ \ static void (::godot::Wrapped::*_get_get_property_list())(::godot::List<::godot::PropertyInfo> * p_list) const { \ - return (void(::godot::Wrapped::*)(::godot::List<::godot::PropertyInfo> * p_list) const) & m_class::_get_property_list; \ + return (void (::godot::Wrapped::*)(::godot::List<::godot::PropertyInfo> * p_list) const) & m_class::_get_property_list; \ } \ \ static bool (::godot::Wrapped::*_get_property_can_revert())(const ::godot::StringName &p_name) const { \ - return (bool(::godot::Wrapped::*)(const ::godot::StringName &p_name) const) & m_class::_property_can_revert; \ + return (bool (::godot::Wrapped::*)(const ::godot::StringName &p_name) const) & m_class::_property_can_revert; \ } \ \ static bool (::godot::Wrapped::*_get_property_get_revert())(const ::godot::StringName &p_name, ::godot::Variant &) const { \ - return (bool(::godot::Wrapped::*)(const ::godot::StringName &p_name, ::godot::Variant &) const) & m_class::_property_get_revert; \ + return (bool (::godot::Wrapped::*)(const ::godot::StringName &p_name, ::godot::Variant &) const) & m_class::_property_get_revert; \ } \ \ static void (::godot::Wrapped::*_get_validate_property())(::godot::PropertyInfo & p_property) const { \ - return (void(::godot::Wrapped::*)(::godot::PropertyInfo & p_property) const) & m_class::_validate_property; \ + return (void (::godot::Wrapped::*)(::godot::PropertyInfo & p_property) const) & m_class::_validate_property; \ } \ \ static ::godot::String (::godot::Wrapped::*_get_to_string())() const { \ - return (::godot::String(::godot::Wrapped::*)() const) & m_class::_to_string; \ + return (::godot::String (::godot::Wrapped::*)() const) & m_class::_to_string; \ } \ \ template \ diff --git a/include/godot_cpp/core/method_bind.hpp b/include/godot_cpp/core/method_bind.hpp index 07d51be6e..ef5ab018d 100644 --- a/include/godot_cpp/core/method_bind.hpp +++ b/include/godot_cpp/core/method_bind.hpp @@ -149,8 +149,7 @@ class MethodBind { template class MethodBindVarArgBase : public MethodBind { protected: - R(T::*method) - (const Variant **, GDExtensionInt, GDExtensionCallError &); + R (T::*method)(const Variant **, GDExtensionInt, GDExtensionCallError &); std::vector arguments; public: @@ -434,8 +433,7 @@ template template #endif // TYPED_METHOD_BIND class MethodBindTR : public MethodBind { - R(MB_T::*method) - (P...); + R (MB_T::*method)(P...); protected: // GCC raises warnings in the case P = {} as the comparison is always false... @@ -517,8 +515,7 @@ template template #endif // TYPED_METHOD_BIND class MethodBindTRC : public MethodBind { - R(MB_T::*method) - (P...) const; + R (MB_T::*method)(P...) const; protected: // GCC raises warnings in the case P = {} as the comparison is always false... @@ -663,8 +660,7 @@ MethodBind *create_static_method_bind(void (*p_method)(P...)) { template class MethodBindTRS : public MethodBind { - R(*function) - (P...); + R (*function)(P...); protected: // GCC raises warnings in the case P = {} as the comparison is always false... diff --git a/include/godot_cpp/variant/callable_method_pointer.hpp b/include/godot_cpp/variant/callable_method_pointer.hpp index e9aea09bc..876d1d806 100644 --- a/include/godot_cpp/variant/callable_method_pointer.hpp +++ b/include/godot_cpp/variant/callable_method_pointer.hpp @@ -104,8 +104,7 @@ template class CallableCustomMethodPointerRet : public CallableCustomMethodPointerBase { struct Data { T *instance; - R(T::*method) - (P...); + R (T::*method)(P...); } data; static_assert(sizeof(Data) % 4 == 0); @@ -146,8 +145,7 @@ template class CallableCustomMethodPointerRetC : public CallableCustomMethodPointerBase { struct Data { T *instance; - R(T::*method) - (P...) const; + R (T::*method)(P...) const; } data; static_assert(sizeof(Data) % 4 == 0); @@ -227,8 +225,7 @@ Callable create_custom_callable_static_function_pointer(void (*p_method)(P...)) template class CallableCustomStaticMethodPointerRet : public CallableCustomMethodPointerBase { struct Data { - R(*method) - (P...); + R (*method)(P...); } data; static_assert(sizeof(Data) % 4 == 0); diff --git a/include/godot_cpp/variant/char_string.hpp b/include/godot_cpp/variant/char_string.hpp index b7b795b52..908dc3432 100644 --- a/include/godot_cpp/variant/char_string.hpp +++ b/include/godot_cpp/variant/char_string.hpp @@ -113,7 +113,7 @@ class CharStringT { CharStringT &operator+=(T p_char); int64_t length() const { return size() ? size() - 1 : 0; } const T *get_data() const; - operator const T *() const { return get_data(); }; + operator const T *() const { return get_data(); } protected: void copy_from(const T *p_cstr); diff --git a/include/godot_cpp/variant/variant.hpp b/include/godot_cpp/variant/variant.hpp index 6a0264a3a..b1bb7b633 100644 --- a/include/godot_cpp/variant/variant.hpp +++ b/include/godot_cpp/variant/variant.hpp @@ -145,7 +145,7 @@ class Variant { static GDExtensionTypeFromVariantConstructorFunc to_type_constructor[VARIANT_MAX]; public: - _FORCE_INLINE_ GDExtensionVariantPtr _native_ptr() const { return const_cast(&opaque); } + _FORCE_INLINE_ GDExtensionVariantPtr _native_ptr() const { return const_cast(&opaque); } Variant(); Variant(std::nullptr_t n) : Variant() {} diff --git a/pyproject.toml b/pyproject.toml index 0e9c4b444..0a51b3b3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,16 +5,16 @@ ignore_missing_imports = true namespace_packages = true no_implicit_optional = true pretty = true -scripts_are_modules = true show_column_numbers = true warn_redundant_casts = true warn_return_any = true warn_unreachable = true +python_version = "3.8" [tool.ruff] -extend-include = ["SConstruct"] +extend-include = ["*SConstruct"] line-length = 120 -target-version = "py37" +target-version = "py38" [tool.ruff.lint] extend-select = [ @@ -27,32 +27,32 @@ extend-select = [ ] [tool.codespell] -enable-colors = "" -write-changes = "" -check-hidden = "" +enable-colors = true +write-changes = true +check-hidden = true quiet-level = 3 -builtin = "clear,rare,en-GB_to_en-US" -ignore-words-list = """\ - breaked, - cancelled, - checkin, - curvelinear, - doubleclick, - expct, - findn, - gird, - hel, - inout, - labelin, - lod, - mis, - nd, - numer, - ot, - outin, - requestor, - te, - textin, - thirdparty, - vai -""" +builtin = ["clear", "rare", "en-GB_to_en-US"] +ignore-words-list = [ + "breaked", + "cancelled", + "checkin", + "curvelinear", + "doubleclick", + "expct", + "findn", + "gird", + "hel", + "inout", + "labelin", + "lod", + "mis", + "nd", + "numer", + "ot", + "outin", + "requestor", + "te", + "textin", + "thirdparty", + "vai", +] diff --git a/test/src/example.cpp b/test/src/example.cpp index f51c1c175..97915a0fd 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -161,7 +161,7 @@ bool Example::_property_can_revert(const StringName &p_name) const { } else { return false; } -}; +} bool Example::_property_get_revert(const StringName &p_name, Variant &r_property) const { if (p_name == StringName("property_from_list")) { @@ -170,7 +170,7 @@ bool Example::_property_get_revert(const StringName &p_name, Variant &r_property } else { return false; } -}; +} void Example::_validate_property(PropertyInfo &p_property) const { String name = p_property.name; diff --git a/test/src/example.h b/test/src/example.h index b40fcab16..22e9382bd 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -58,7 +58,7 @@ class ExampleMin : public Control { GDCLASS(ExampleMin, Control); protected: - static void _bind_methods(){}; + static void _bind_methods() {} }; class Example : public Control {