Require outer script reference in Mock._init to remove class name dependency - #11
Open
ChrisCrossCrash wants to merge 1 commit into
Open
Require outer script reference in Mock._init to remove class name dependency#11ChrisCrossCrash wants to merge 1 commit into
ChrisCrossCrash wants to merge 1 commit into
Conversation
Mock.install() and Mock.uninstall() previously referenced the C3Http identifier directly, which breaks when class_name C3Http is commented out to avoid global scope pollution (a common addon pattern). Mock now accepts the outer GDScript reference in _init and stores it, so install/uninstall use _outer._impl instead. Commenting out class_name C3Http in the addon file requires no further changes to the file. Call sites update from Mock.new() to Mock.new(C3Http). Docs and tests updated to match.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Mock.install()andMock.uninstall()previously referenced theC3Httpidentifier directly. This breaks whenclass_name C3Httpis commented out to avoid global scope pollution — a common pattern for addon authors who want to prevent the class from appearing in every project that includes the addon.Mocknow accepts the outerGDScriptreference in_initand stores it, soinstall/uninstalluse_outer._implinstead ofC3Http._impl. With this change, commenting outclass_name C3Httpin the addon file requires no further changes to the file.Breaking change:
Mock.new()→Mock.new(C3Http). All internal call sites are updated.Usage
When
class_name C3Httpis active (the default):When
class_name C3Httpis commented out, load the script into a local constant and pass it through:install()anduninstall()remain argument-free — the reference is captured once at construction.Test plan
godot --headless --path . -s addons/gut/gut_cmdln.gd -gdir=res://tests -ginclude_subdirs -gexit)class_name C3Httpand using thepreloadpattern produces no GDScript errors