@@ -64,22 +64,22 @@ func getCwd(self py.Object, args py.Tuple) (py.Object, error) {
6464
6565// change current working directory
6666func 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) " )
6969 }
7070 if objectIsString (args [0 ]) {
7171 dir , err := py .ReprAsString (args [0 ])
7272 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
7474 }
7575 dir = strings .ReplaceAll (dir , "'" , "" )
7676 err = os .Chdir (dir )
7777 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 ())
7979 }
8080 return py .None , nil
8181 }
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 )
8383}
8484
8585// get a enviroment variable by key
@@ -89,25 +89,27 @@ func getenv(self py.Object, args py.Tuple) (py.Object, error) {
8989 var default_ py.Object // return when not found
9090 var err error // error obj
9191
92- if len (args ) > 2 {
93- return nil , py .ExceptionNewf (py .KeyError , "1 argument required, \" key\" " )
94- }
9592 if len (args ) == 1 {
9693 if objectIsString (args [0 ]) {
9794 key = args [0 ]
9895 } 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 )
10097 }
10198 default_ = py .None
10299 } 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+ }
103105 if objectIsString (args [1 ]) {
104106 key = args [0 ]
105107 default_ = args [1 ]
106108 } 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 )
108110 }
109111 } 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' " )
111113 }
112114 var res py.Object // hold the result value
113115 res , err = getEnvVariables ().M__getitem__ (key )
@@ -142,7 +144,7 @@ func putenv(self py.Object, args py.Tuple) (py.Object, error) {
142144 }
143145 return py .None , nil
144146 }
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' " )
146148}
147149
148150// Unset (delete) the environment variable named key.
@@ -161,7 +163,10 @@ func unsetenv(self py.Object, args py.Tuple) (py.Object, error) {
161163 return py .None , nil
162164 }
163165 }
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 )
165170}
166171
167172// 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
187192// os.system(command string) this function runs a shell command and directs the output to standard output.
188193func system (self py.Object , args py.Tuple ) (py.Object , error ) {
189194 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' " )
191196 }
192197 var cargs []string
193198 _carg , err := py .ReprAsString (args [0 ])
0 commit comments