Setget is used to validate a property when it is called from outside the class. It is not called locally because if you are editing the class it is assumed that you are the owner or have full access to it. But when the property is modified from outside (an instance of the class or another referenced script or an export) the set function is called if it is defined for that property. Some examples:
class TestSetGet:
var prop = 0 setget set_prop
func set_prop(p):
prop = p + 1000
func _ready() -> void:
var test = TestSetGet.new()
test.prop = 5
print (test.prop) #print 1005
https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html#setters-getters
extends Node2D #This is a class with no name
var number = 0 setget set_number
func set_number(num):
if num > 5:
num = 5
number = num
func _ready() -> void:
number = 15 #access local, not trigger the setter and getter
print(number) #print 15
self.number = 15 #access outside whit self
print(number) #print 5
pass