@@ -11,7 +11,7 @@ extern crate web_sys;
11
11
use crate :: js_to_py;
12
12
use js_sys:: Array ;
13
13
use rustpython_vm:: obj:: { objstr, objtype} ;
14
- use rustpython_vm:: pyobject:: { PyFuncArgs , PyObjectRef , PyResult } ;
14
+ use rustpython_vm:: pyobject:: { IdProtocol , PyFuncArgs , PyObjectRef , PyResult , TypeProtocol } ;
15
15
use rustpython_vm:: VirtualMachine ;
16
16
use wasm_bindgen:: { JsCast , JsValue } ;
17
17
use web_sys:: { console, window, HtmlTextAreaElement } ;
@@ -33,7 +33,9 @@ pub fn print_to_html(text: &str, selector: &str) -> Result<(), JsValue> {
33
33
34
34
pub fn format_print_args ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> Result < String , PyObjectRef > {
35
35
// Handle 'sep' kwarg:
36
- let sep_arg = args. get_optional_kwarg ( "sep" ) ;
36
+ let sep_arg = args
37
+ . get_optional_kwarg ( "sep" )
38
+ . filter ( |obj| !obj. is ( & vm. get_none ( ) ) ) ;
37
39
if let Some ( ref obj) = sep_arg {
38
40
if !objtype:: isinstance ( obj, & vm. ctx . str_type ( ) ) {
39
41
return Err ( vm. new_type_error ( format ! (
@@ -45,7 +47,9 @@ pub fn format_print_args(vm: &mut VirtualMachine, args: PyFuncArgs) -> Result<St
45
47
let sep_str = sep_arg. as_ref ( ) . map ( |obj| objstr:: get_value_as_ref ( obj) ) ;
46
48
47
49
// Handle 'end' kwarg:
48
- let end_arg = args. get_optional_kwarg ( "end" ) ;
50
+ let end_arg = args
51
+ . get_optional_kwarg ( "end" )
52
+ . filter ( |obj| !obj. is ( & vm. get_none ( ) ) ) ;
49
53
if let Some ( ref obj) = end_arg {
50
54
if !objtype:: isinstance ( obj, & vm. ctx . str_type ( ) ) {
51
55
return Err ( vm. new_type_error ( format ! (
@@ -63,10 +67,17 @@ pub fn format_print_args(vm: &mut VirtualMachine, args: PyFuncArgs) -> Result<St
63
67
for a in args. args {
64
68
if first {
65
69
first = false ;
70
+ } else if let Some ( ref sep_str) = sep_str {
71
+ output. push_str ( sep_str) ;
66
72
} else {
67
- output. push_str ( " " ) ;
73
+ output. push ( ' ' ) ;
68
74
}
69
75
output. push_str ( & vm. to_pystr ( & a) ?) ;
76
+ }
77
+
78
+ if let Some ( end_str) = end_str {
79
+ output. push_str ( end_str. as_ref ( ) )
80
+ } else {
70
81
output. push ( '\n' ) ;
71
82
}
72
83
Ok ( output)
0 commit comments