Skip to content
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

GDScript: Add warning if non-@tool class extends @tool class #78178

Merged

Conversation

dalexeev
Copy link
Member

@dalexeev dalexeev commented Jun 13, 2023

@akien-mga
Copy link
Member

I support the idea in principle.

One question we might want to ponder is whether there might be a valid use case for extending @tool scripts with a non-@tool script, to disable the tool-specific behavior in that script. E.g. for a script that has both in-game and in-editor logic, where the in-editor logic is only meant for debugging in a specific scene, but inherited scenes with their own extending scripts should not run it.

I guess this use case, if it exists, could be achieved the other way around by making the base script non @tool and extending it via a @tool script only where wanted.

@ajreckof
Copy link
Member

Effectively I can see cases where the base script is a tool script and the extended should not. For example the base script can have some exported value that has a setter that needs to run but the current script has a lot of things happening on process which you don't want to run in the editor because of performance reasons.
The workaround proposed by akien does not work because as of now if a script is marked as @tool even if the base class is not marked as tool it will be considered as such.
This is still a fix for the issue but it feels more like a bandaid then a proper fix. I think a proper fix should aim to make it possible to have abas script that run in the editor while the script extending it is not i @tool mode

@dalexeev
Copy link
Member Author

The problem is that we can't make @tool work only for some of the methods and not for others. Especially if the child class overrides the methods of the base class. We cannot guarantee that the methods will never be called. Therefore, the script can either be entirely in @tool mode or not.

If you propose the ability to disable @tool for an inherited class (the base class's @tool code is not executed), then I think that some explicit annotation (@notool or @disable_tool) is needed, not just the absence of @tool. Because the current issue is that users may forget to add @tool or assume that it inherits automatically.

Or we can replace the error with a warning and shift the responsibility to users, but we need to come up with code so that the warning can be ignored.

@Flavelius
Copy link
Contributor

Flavelius commented Jul 1, 2023

@notool or @disable_tool definitely makes more sense, because the base class explicitly expresses the intent to be a tool, and this explicit requirement shouln't be implicitly violated by inheritors. It's the same reason that not all base class methods are virtual by default. In godot's special case though with explicit annotations users/inheritors can alteast make it their responsibility to deal with broken behaviour.

@adamscott
Copy link
Member

As discussed in the GDScript team meeting, instead of adding @disable_tool or @notool, we decided to go ahead with @tool(false) as annotations can take arguments. Technically, the first argument of tool would default to true if none is supplied.

@dalexeev dalexeev force-pushed the gds-add-non-tool-extends-tool-error branch 2 times, most recently from 7e0d773 to 2326f0d Compare September 27, 2023 13:43
@dalexeev dalexeev changed the title GDScript: Add error if non-@tool class extends @tool class GDScript: Add warning if non-@tool class extends @tool class Sep 27, 2023
@dalexeev dalexeev force-pushed the gds-add-non-tool-extends-tool-error branch from 2326f0d to a107a11 Compare September 27, 2023 13:49
@dalexeev
Copy link
Member Author

we decided to go ahead with @tool(false) as annotations can take arguments. Technically, the first argument of tool would default to true if none is supplied.

Autocompletion inserts empty parentheses when there are optional arguments. We could have added an exception, but I remembered that we already have an annotation for ignoring warnings, which is most likely the first thing the user will use by clicking the "Ignore" button in the warning bar. I don't think we need any other way than @warning_ignore.

@dalexeev dalexeev force-pushed the gds-add-non-tool-extends-tool-error branch from a107a11 to 862699b Compare September 27, 2023 14:05
@dalexeev dalexeev requested a review from a team as a code owner September 27, 2023 14:05
@adamscott adamscott modified the milestones: 4.x, 4.3 Oct 3, 2023
Copy link
Contributor

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation for the warning looks fine but I have a feel this PR is abandoned a bit?

@dalexeev dalexeev force-pushed the gds-add-non-tool-extends-tool-error branch from 862699b to 3f52871 Compare July 4, 2024 07:37
Copy link
Contributor

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally relate to the issues the warning would address (it used to be extremely painful figuring them out on my own), but it's worth questioning if this should be in 4.3 right now, in feature freeze.

@akien-mga akien-mga modified the milestones: 4.3, 4.4 Jul 4, 2024
@akien-mga akien-mga requested a review from a team August 27, 2024 21:40
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@akien-mga akien-mga merged commit 4e051ff into godotengine:master Aug 28, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

@dalexeev dalexeev deleted the gds-add-non-tool-extends-tool-error branch August 28, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants