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

print() of empty array using format string does not work #101401

Open
DarkiStar opened this issue Jan 10, 2025 · 5 comments
Open

print() of empty array using format string does not work #101401

DarkiStar opened this issue Jan 10, 2025 · 5 comments

Comments

@DarkiStar
Copy link
Contributor

DarkiStar commented Jan 10, 2025

Tested versions

Godot Engine v4.4.dev7.official.46c8f8c5c

System information

Godot v4.4.dev7 - Windows 10 (build 19045)

Issue description

the print of an empty array with a format string does not work like expected.

the print of an empty dictionary with a format string works but has 2 spaces between the brackets.


output test1: %s
Expected output: []
Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...

output test2: %s
Expected output: []
Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...

output test3: %s
Expected output: []
Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...

output test4: {  }
Expected output: {}

output test5: 0
Expected output: 0

output test6: []
Expected output: []


Steps to reproduce

extends Control


func _ready() -> void:
	var test1 : Array
	print('output test1: %s' % test1)
	print('Expected output: []')
	print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')
	
	print()
	
	var test2 : Array = []
	print('output test2: %s' % test2)
	print('Expected output: []')
	print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')

	print()
	
	var test3 : Array [int] = []
	print('output test3: %s' % test3)
	print('Expected output: []')
	print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')

	print()
	
	var test4 : Dictionary
	print('output test4: %s' % test4) 
	print('Expected output: {}')

	print()

	var test5 : int
	print('output test5: %s' % test5)
	print('Expected output: 0')

	print()

	var test6 : Array
	prints('output test6:', test6)
	print('Expected output: []')

Minimal reproduction project (MRP)

see steps to reproduce

@AThousandShips
Copy link
Member

I'd say this is to be expected, you need an array of one element and providing one with zero, it should be:

var test1 : Array
print('output test1: %s' % [test1])
print('Expected output: []')
print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')
	
print()
	
var test2 : Array = []
print('output test2: %s' % [test2])
print('Expected output: []')
print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')

print()
	
var test3 : Array [int] = []
print('output test3: %s' % [test3])
print('Expected output: []')
print('Debugger Message: ... _ready(): String formatting error: not enough arguments for format string. ...')

@DarkiStar
Copy link
Contributor Author

But why does it work with a dictionary?

@AThousandShips
Copy link
Member

Because % doesn't support Dictionary formatting like String.format does AFAIK, it just treats it the same way as "test: %s" % 1 or any other non-Array case

@DarkiStar
Copy link
Contributor Author

Because % doesn't support Dictionary formatting like String.format does AFAIK, it just treats it the same way as "test: %s" % 1 or any other non-Array case

But Dictionary worked with % (see test4 in my example).

@AThousandShips
Copy link
Member

Yes as I said, it just treats Dictionary as any other value, it doesn't support formatting like so:

print("User {id} is {name}.".format({"id": 42, "name": "Godot"}))

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

No branches or pull requests

2 participants