Skip to content

Commit de4b483

Browse files
committed
Fix type assertion and error check
1 parent 202e82a commit de4b483

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

stdlib/builtin/builtin.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,11 +1202,15 @@ func builtin_input(self py.Object, args py.Tuple) (py.Object, error) {
12021202
if py.InputHook != nil {
12031203
promptStr := ""
12041204
if prompt != py.None {
1205-
promptStr = string(prompt.(py.String))
1205+
s, ok := prompt.(py.String)
1206+
if !ok {
1207+
return nil, py.ExceptionNewf(py.TypeError, "input() prompt must be a string")
1208+
}
1209+
promptStr = string(s)
12061210
}
12071211
line, err := py.InputHook(promptStr)
12081212
if err != nil {
1209-
if err == io.EOF {
1213+
if errors.Is(err, io.EOF) {
12101214
return nil, py.ExceptionNewf(py.EOFError, "EOF when reading a line")
12111215
}
12121216
return nil, err
@@ -1242,7 +1246,7 @@ func builtin_input(self py.Object, args py.Tuple) (py.Object, error) {
12421246
reader := bufio.NewReader(file.File)
12431247
line, err := reader.ReadString('\n')
12441248
if err != nil {
1245-
if err.Error() == "EOF" {
1249+
if errors.Is(err, io.EOF) {
12461250
return nil, py.ExceptionNewf(py.EOFError, "EOF when reading a line")
12471251
}
12481252
return nil, err

0 commit comments

Comments
 (0)