@@ -116,25 +116,22 @@ func getpid(self py.Object, args py.Tuple) (py.Object, error) {
116116
117117// putenv sets the value of an environment variable named by the key.
118118func putenv (self py.Object , args py.Tuple ) (py.Object , error ) {
119- if len (args ) == 2 && objectIsString (args [0 ]) && objectIsString (args [1 ]) {
120- _k , err := py .ReprAsString (args [0 ])
121- if err != nil {
122- return nil , py .ExceptionNewf (py .TypeError , "Unable to parse string" ) // this will never execute
123- }
124- key := strings .ReplaceAll (_k , "'" , "" ) // required
125- _v , err := py .ReprAsString (args [1 ])
126- if err != nil {
127- return nil , py .ExceptionNewf (py .TypeError , "Unable to parse string" ) // this will never execute
128- }
129- value := _v [1 : len (_v )- 1 ]
130-
131- err = os .Setenv (key , value )
132- if err != nil {
133- return nil , py .ExceptionNewf (py .OSError , "Unable to set enviroment variable" )
134- }
135- return py .None , nil
119+ if len (args ) != 2 {
120+ //... return error ...
121+ }
122+ k , ok := args [0 ].(py.String )
123+ if ! ok {
124+ //... return error ...
136125 }
137- return nil , py .ExceptionNewf (py .TypeError , "missing required arguments: 'key:str' and 'value:str'" )
126+ v , ok := args [1 ].(py.String )
127+ if ! ok {
128+ //... return error ...
129+ }
130+ err := os .Setenv (string (k ), string (v ))
131+ if err != nil {
132+ return ...
133+ }
134+ return py .None , nil
138135}
139136
140137// Unset (delete) the environment variable named key.
0 commit comments