@@ -64,22 +64,22 @@ func getCwd(self py.Object, args py.Tuple) (py.Object, error) {
64
64
65
65
// change current working directory
66
66
func chdir (self py.Object , args py.Tuple ) (py.Object , error ) {
67
- if len (args ) == 0 || len ( args ) > 1 {
68
- return nil , py .ExceptionNewf (py .TypeError , "One argument required " )
67
+ if len (args ) == 0 {
68
+ return nil , py .ExceptionNewf (py .TypeError , "Missing required argument 'path' (pos 1) " )
69
69
}
70
70
if objectIsString (args [0 ]) {
71
71
dir , err := py .ReprAsString (args [0 ])
72
72
if err != nil {
73
- return nil , py .ExceptionNewf (py .TypeError , "Failed to parse string" )
73
+ return nil , py .ExceptionNewf (py .TypeError , "Failed to parse string" ) // never going to run
74
74
}
75
75
dir = strings .ReplaceAll (dir , "'" , "" )
76
76
err = os .Chdir (dir )
77
77
if err != nil {
78
- return nil , py .ExceptionNewf (py .OSError , "Couldn't change cwd; " + err .Error ())
78
+ return nil , py .ExceptionNewf (py .NotADirectoryError , "Couldn't change cwd; " + err .Error ())
79
79
}
80
80
return py .None , nil
81
81
}
82
- return nil , py .ExceptionNewf (py .TypeError , "Expected string argument at position 0" )
82
+ return nil , py .ExceptionNewf (py .TypeError , "str expected, not " + args [ 0 ]. Type (). Name )
83
83
}
84
84
85
85
// get a enviroment variable by key
@@ -89,25 +89,27 @@ func getenv(self py.Object, args py.Tuple) (py.Object, error) {
89
89
var default_ py.Object // return when not found
90
90
var err error // error obj
91
91
92
- if len (args ) > 2 {
93
- return nil , py .ExceptionNewf (py .KeyError , "1 argument required, \" key\" " )
94
- }
95
92
if len (args ) == 1 {
96
93
if objectIsString (args [0 ]) {
97
94
key = args [0 ]
98
95
} else {
99
- return nil , py .ExceptionNewf (py .TypeError , "Expected argument of type string" )
96
+ return nil , py .ExceptionNewf (py .TypeError , "str expected (pos 1), not " + args [ 0 ]. Type (). Name )
100
97
}
101
98
default_ = py .None
102
99
} else if len (args ) == 2 {
100
+ if objectIsString (args [0 ]) {
101
+ key = args [0 ]
102
+ } else {
103
+ return nil , py .ExceptionNewf (py .TypeError , "str expected (pos 1), not " + args [0 ].Type ().Name )
104
+ }
103
105
if objectIsString (args [1 ]) {
104
106
key = args [0 ]
105
107
default_ = args [1 ]
106
108
} else {
107
- return nil , py .ExceptionNewf (py .TypeError , "Expected argument of type string" )
109
+ return nil , py .ExceptionNewf (py .TypeError , "str expected (pos 2), not" + args [ 1 ]. Type (). Name )
108
110
}
109
111
} else {
110
- return nil , py .ExceptionNewf (py .TypeError , "Expected argument of type string " )
112
+ return nil , py .ExceptionNewf (py .TypeError , "missing one required argument: 'name:str' " )
111
113
}
112
114
var res py.Object // hold the result value
113
115
res , err = getEnvVariables ().M__getitem__ (key )
@@ -142,7 +144,7 @@ func putenv(self py.Object, args py.Tuple) (py.Object, error) {
142
144
}
143
145
return py .None , nil
144
146
}
145
- return nil , py .ExceptionNewf (py .TypeError , "Expected 2 arguments of type string " )
147
+ return nil , py .ExceptionNewf (py .TypeError , "missing required arguments: 'key:str' and 'value:str' " )
146
148
}
147
149
148
150
// Unset (delete) the environment variable named key.
@@ -161,7 +163,10 @@ func unsetenv(self py.Object, args py.Tuple) (py.Object, error) {
161
163
return py .None , nil
162
164
}
163
165
}
164
- return nil , py .ExceptionNewf (py .TypeError , "Expected 1 argument of type string" )
166
+ if len (args ) == 0 {
167
+ return nil , py .ExceptionNewf (py .TypeError , "missing one required argument: 'key:str'" )
168
+ }
169
+ return nil , py .ExceptionNewf (py .TypeError , "str expected, not " + args [0 ].Type ().Name )
165
170
}
166
171
167
172
// os._exit() immediate program termination; unlike sys.exit(), which raises a SystemExit, this function will termninate the program immediately.
@@ -187,7 +192,7 @@ func _exit(self py.Object, args py.Tuple) (py.Object, error) { // can never retu
187
192
// os.system(command string) this function runs a shell command and directs the output to standard output.
188
193
func system (self py.Object , args py.Tuple ) (py.Object , error ) {
189
194
if len (args ) == 0 && ! (objectIsString (args [0 ])) {
190
- return nil , py .ExceptionNewf (py .TypeError , "Expected 1 or more arguments all of type string " )
195
+ return nil , py .ExceptionNewf (py .TypeError , "missing one required argument: 'command:str' " )
191
196
}
192
197
var cargs []string
193
198
_carg , err := py .ReprAsString (args [0 ])
0 commit comments