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

Groups of arguments binded with chained Callable.bind calls are appended in reversed call order #62891

Closed
kleonc opened this issue Jul 10, 2022 · 6 comments

Comments

@kleonc
Copy link
Member

kleonc commented Jul 10, 2022

Godot version

4.0.alpha11

System information

N/A

Issue description

Currently callable.bind(a1, a2).bind(b1, b2) is equivalent to callable.bind(b1, b2, a1, a2). I think it should be equivalent to callable.bind(a1, a2, b1, b2).

Steps to reproduce

Run this script:

@tool
extends EditorScript

func _run():
	f.bind(1, 2, 3).call(0)
	f.bind(1, 2).bind(3).call(0)
	f.bind(1).bind(2, 3).call(0)
	f.bind(1).bind(2).bind(3).call(0)
	
func f(a, b, c, d) -> void:
	prints(a, b, c, d)

Output:

0 1 2 3
0 3 1 2
0 2 3 1
0 3 2 1

Expected output:

0 1 2 3
0 1 2 3
0 1 2 3
0 1 2 3

Minimal reproduction project

No response

@kleonc kleonc added this to the 4.0 milestone Jul 10, 2022
@cdemirer
Copy link
Contributor

Technically, this is documented behavior.

But I agree that it's not intuitive (especially when following Python terminology).

@vnen
Copy link
Member

vnen commented Jul 13, 2022

I'm not sure why it's like this. It seems to be used in the engine like this internally for connecting signals. In any case, need to be discussed with core team too.

@vnen
Copy link
Member

vnen commented Feb 20, 2023

So, this is not really a bug, it's just the way bind() works. That is, it always bind the last arguments. Taking that into account it is really expected behavior. A Callable for a function with 2 parameters is the same as a Callable for a function with 4 parameters that has 2 bound arguments, so it shouldn't reorder the already bound ones.

@AThousandShips
Copy link
Member

AThousandShips commented Apr 17, 2023

Closed by #76158 clarifying the order, if you want to change the behaviour please open a proposal for this as it is intended behaviour and would break compatibility

@YuriSizov
Copy link
Contributor

Yeah, I agree.

@AntonBogun
Copy link

AntonBogun commented Apr 28, 2023

While this is documented behaviour, it doesn't seem to be "right" behaviour. I want my bind to act in the "first argument bound comes first" way, but it seems there isn't any way to extend Callable to add an "alt_bind()" or something like that.
I suppose this isn't that big of a deal but I would still greatly prefer not having to think backwards about my arguments. I will try to inverse this by creating a singleton and seeing how that goes, but it would be preferable to have a built-in alternative bind that works as one would expect.
If there is any other solution to this I'm unaware of, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants