@@ -136,22 +136,18 @@ func putenv(self py.Object, args py.Tuple) (py.Object, error) {
136
136
137
137
// Unset (delete) the environment variable named key.
138
138
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 {
152
140
return nil , py .ExceptionNewf (py .TypeError , "missing one required argument: 'key:str'" )
153
141
}
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
155
151
}
156
152
157
153
// os._exit() immediate program termination; unlike sys.exit(), which raises a SystemExit, this function will termninate the program immediately.
0 commit comments