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

Allow usage of is not in GDScript #1319

Closed
Xascoria opened this issue Aug 6, 2020 · 10 comments · Fixed by godotengine/godot#87939
Closed

Allow usage of is not in GDScript #1319

Xascoria opened this issue Aug 6, 2020 · 10 comments · Fixed by godotengine/godot#87939
Milestone

Comments

@Xascoria
Copy link

Xascoria commented Aug 6, 2020

Describe the project you are working on:
This issue works for all projects that use the keywords "in" and "is"

Describe the problem or limitation you are having in your project:
When trying to use the opposite of "in" and "is", most people, especially the people who have used Python before would use "a not in b" and "a is not b" instead of "not a in b" and "not a is b". In Python, both the former and latter example works, but in GDScript only the latter is valid syntaxes.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Just allow usage of "a not in b" and "a is not b", which not only are in Python but also make sense grammatically

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
a is not b #equivalent to not a is b
a not in b #equivalent to not a in b

If this enhancement will not be used often, can it be worked around with a few lines of script?:
The keywords themselves should be used quite oftenly, but yes its easy to have a work around.

Is there a reason why this should be core and not an add-on in the asset library?:
It's a simple quality of life improvement that is pretty straightforward to implement and helps with the workload a lot.

@VedatGunel
Copy link

Previous discussion: godotengine/godot#3677

@TheDuriel
Copy link

"in" does not exist to my knowledge, unless this was newly added in 4.0. It also is a bit extreme to add, given that if not thing.has(thing): is already pretty grammatically correct.

And I don't see why we need a whole addition to the language just to have the occasional line be a little bit more correct in English.

@Meriipu
Copy link

Meriipu commented Aug 7, 2020

I do not want a is not b and I dislike that part of python, it makes boolean expressions more confusing by trying to hide/muddy the fact that they are boolean
The most intuitive parsing of it is a is (not b) which rarely makes sense unless a and b are bools.

Trying to shoehorn natural english into expressions like this is a huge mistake in my opinion

I would be less opposed to an isnt-operator, like a isnt b but that would be incredibly obscure and probably not worth it.

@Xascoria
Copy link
Author

Xascoria commented Aug 7, 2020

"in" does not exist to my knowledge, unless this was newly added in 4.0. It also is a bit extreme to add, given that if not thing.has(thing): is already pretty grammatically correct.

And I don't see why we need a whole addition to the language just to have the occasional line be a little bit more correct in English.

It does, I'm currently using 3.2.2 Stable

@Calinou Calinou changed the title Allow usages of "is not" and "not in" in GDScript Allow usage of is not and not in in GDScript Aug 7, 2020
@strank
Copy link

strank commented Aug 27, 2020

Note that is in gdscript is not equivalent to is in python. The former is a type check, the latter is an identity check.
I would suggest splitting this into two proposals:

  • allow is not: this has the boolean ambiguity mentioned by @Meriipu but is is probably very rare in gdscript anyway with as automatically returning null. Note that for both python and gdscript semantics a is (not b) is almost certainly a bug. And I personally think allowing the more natural meaning proposed here would be a good thing, but I won't shed a tear if it doesn't happen.

  • allow not in: currently a syntax error, so no ambiguity. Should be less controversial. I write this all the time out of habit, and I think it would be a great addition. I'd also be prepared to look into making it happen.

@NorPhi
Copy link

NorPhi commented May 20, 2021

I like pythons is not and not in. They are like all those other neat little python tricks that don't work in GDscript and turn really annoying for anyone familiar with python. In general GDscript puts way too much emphasis on "being similar python" in the docs and everywhere else I read about it.

Having said that, pythons a is not b is equivalent to not (a is b) which also works in GDscript and is less ambiguous than an operator that looks like a combination of two different operators. Same for a not in b and not (a in b) although having the negation not in front of in makes it less confusing than is not. So how about allowing not is instead?

@YuriSizov
Copy link
Contributor

In general GDscript puts way too much emphasis on "being similar python" in the docs and everywhere else I read about it.

We actually amended the docs not so long ago to make sure people stop with this misconception, but high level similarity still makes some community participant to make comparisons. 🙃

@dalexeev
Copy link
Member

not in is already supported in GDScript.

I'm not sure about is not:

  • Formally, this is a parser ambiguity (unlike not in) since not comes after is.
    • Is "not is" acceptable even though it's grammatically incorrect and inconsistent with Python?
  • On the other hand, this is not so important, because there is no type negation operation.
  • It seems to me that is not is much more rare than not in. See also GDScript: Rework type check godot#73489:

Since right side now needs to be compile time known type to support previously available functionality, where a type was intended to be variable, add is_instance_of utility function to GDScript.

is_instance_of(a, TYPE_INT)
is_instance_of(a, RefCounted)
is_instance_of(a, A)

@Shadowblitz16
Copy link

Shadowblitz16 commented Jul 20, 2023

I support this suggestion
I just found out this isn't possible I needed it to do...

@export var options : Array[PackedScene]:
	set(v):
		for value in v:
			if value != null:
				var instance := value.instantiate()
				if instance is not Control:
					instance.queue_free()
					return
		options = v

due to the fact that godot doesn't support typed packed scenes yet.
sadly this gives me an error.

The only way I can seem to do this is if I do this...

				var instance := value.instantiate()
                                var node := instance as Control
				if !node:
					instance.queue_free()
					return

which looks ugly

Production edit: added gdscript syntax highlighting to code.

@TheDuriel
Copy link

Use PackedScene.get_state() to query the saved state for the root nodes type.

@Calinou Calinou changed the title Allow usage of is not and not in in GDScript Allow usage of is not in GDScript Dec 1, 2023
@AThousandShips AThousandShips added this to the 4.3 milestone Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.