Skip to content

Commit e6ceae6

Browse files
committed
1 parent df98160 commit e6ceae6

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

os/os.module.go

+10-14
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,18 @@ func putenv(self py.Object, args py.Tuple) (py.Object, error) {
136136

137137
// Unset (delete) the environment variable named key.
138138
func unsetenv(self py.Object, args py.Tuple) (py.Object, error) {
139-
if len(args) == 1 && objectIsString(args[0]) {
140-
_k, err := py.ReprAsString(args[0])
141-
if err != nil {
142-
return nil, py.ExceptionNewf(py.TypeError, "Unable to parse string") // this will never execute
143-
}
144-
key := strings.ReplaceAll(_k, "'", "") // required
145-
err = os.Unsetenv(key)
146-
if err != nil {
147-
return nil, py.ExceptionNewf(py.OSError, "Unable to unset enviroment variable")
148-
}
149-
return py.None, nil
150-
}
151-
if len(args) == 0 {
139+
if len(args) != 1 {
152140
return nil, py.ExceptionNewf(py.TypeError, "missing one required argument: 'key:str'")
153141
}
154-
return nil, py.ExceptionNewf(py.TypeError, "str expected, not "+args[0].Type().Name)
142+
k, ok := args[0].(py.String)
143+
if !ok {
144+
return nil, py.ExceptionNewf(py.TypeError, "str expected (pos 1), not "+args[0].Type().Name)
145+
}
146+
err := os.Unsetenv(string(k))
147+
if err != nil {
148+
return nil, py.ExceptionNewf(py.OSError, "Unable to unset enviroment variable")
149+
}
150+
return py.None, nil
155151
}
156152

157153
// os._exit() immediate program termination; unlike sys.exit(), which raises a SystemExit, this function will termninate the program immediately.

0 commit comments

Comments
 (0)