@@ -5,10 +5,11 @@ export interface PyPrinterOptions {
55 indentSize ?: number ;
66}
77
8+ const DEFAULT_INDENT_SIZE = 4 ;
89const PARAMS_MULTILINE_THRESHOLD = 3 ;
910
1011export function createPrinter ( options ?: PyPrinterOptions ) {
11- const indentSize = options ?. indentSize ?? 4 ;
12+ const indentSize = options ?. indentSize ?? DEFAULT_INDENT_SIZE ;
1213
1314 let indentLevel = 0 ;
1415
@@ -52,12 +53,12 @@ export function createPrinter(options?: PyPrinterOptions) {
5253 switch ( node . kind ) {
5354 case PyNodeKind . Assignment : {
5455 const target = printNode ( node . target ) ;
55- if ( node . annotation ) {
56- const annotation = printNode ( node . annotation ) ;
56+ if ( node . type ) {
57+ const type = printNode ( node . type ) ;
5758 if ( node . value ) {
58- parts . push ( printLine ( `${ target } : ${ annotation } = ${ printNode ( node . value ) } ` ) ) ;
59+ parts . push ( printLine ( `${ target } : ${ type } = ${ printNode ( node . value ) } ` ) ) ;
5960 } else {
60- parts . push ( printLine ( `${ target } : ${ annotation } ` ) ) ;
61+ parts . push ( printLine ( `${ target } : ${ type } ` ) ) ;
6162 }
6263 } else {
6364 parts . push ( printLine ( `${ target } = ${ printNode ( node . value ! ) } ` ) ) ;
@@ -182,7 +183,7 @@ export function createPrinter(options?: PyPrinterOptions) {
182183 const defPrefix = modifiers ? `${ modifiers } def` : 'def' ;
183184 const formatParameter = ( parameter : ( typeof node . parameters ) [ number ] ) : string => {
184185 const children : Array < string > = [ parameter . name ] ;
185- if ( parameter . annotation ) children . push ( `: ${ printNode ( parameter . annotation ) } ` ) ;
186+ if ( parameter . type ) children . push ( `: ${ printNode ( parameter . type ) } ` ) ;
186187 if ( parameter . defaultValue ) children . push ( ` = ${ printNode ( parameter . defaultValue ) } ` ) ;
187188 return children . join ( '' ) ;
188189 } ;
@@ -272,7 +273,7 @@ export function createPrinter(options?: PyPrinterOptions) {
272273 case PyNodeKind . LambdaExpression : {
273274 const parameters = node . parameters . map ( ( parameter ) => {
274275 const children : Array < string > = [ parameter . name ] ;
275- if ( parameter . annotation ) children . push ( `: ${ printNode ( parameter . annotation ) } ` ) ;
276+ if ( parameter . type ) children . push ( `: ${ printNode ( parameter . type ) } ` ) ;
276277 if ( parameter . defaultValue ) children . push ( ` = ${ printNode ( parameter . defaultValue ) } ` ) ;
277278 return children . join ( '' ) ;
278279 } ) ;
0 commit comments