@@ -71,6 +71,7 @@ import { WithPyDsl } from './stmt/with';
7171// import { TypeTemplatePyDsl } from './type/template';
7272// import { TypeTuplePyDsl } from './type/tuple';
7373import { LazyPyDsl } from './utils/lazy' ;
74+ import { safeKeywordName } from './utils/name' ;
7475
7576const pyDsl = {
7677 /** Creates an array literal expression (e.g. `[1, 2, 3]`). */
@@ -147,12 +148,12 @@ const pyDsl = {
147148 /** Creates an import statement. */
148149 import : ( ...args : ConstructorParameters < typeof ImportPyDsl > ) => new ImportPyDsl ( ...args ) ,
149150
150- /** Creates a keyword argument expression (e.g. `name=value`). */
151- kwarg : ( ...args : ConstructorParameters < typeof KwargPyDsl > ) => new KwargPyDsl ( ...args ) ,
152-
153151 /** Creates an initialization block or statement. */
154152 // init: (...args: ConstructorParameters<typeof InitTsDsl>) => new InitTsDsl(...args),
155153
154+ /** Creates a keyword argument expression (e.g. `name=value`). */
155+ kwarg : ( ...args : ConstructorParameters < typeof KwargPyDsl > ) => new KwargPyDsl ( ...args ) ,
156+
156157 /** Creates a lazy, context-aware node with deferred evaluation. */
157158 lazy : < T extends py . Node > ( ...args : ConstructorParameters < typeof LazyPyDsl < T > > ) =>
158159 new LazyPyDsl < T > ( ...args ) ,
@@ -166,8 +167,12 @@ const pyDsl = {
166167 /** Creates an enum member declaration. */
167168 // member: (...args: ConstructorParameters<typeof EnumMemberTsDsl>) => new EnumMemberTsDsl(...args),
168169
169- /** Creates a method declaration inside a class or object. */
170- // method: (...args: ConstructorParameters<typeof MethodTsDsl>) => new MethodTsDsl(...args),
170+ /** Creates a class method declaration. */
171+ method : ( ( name : NodeName , fn ?: ( f : FuncPyDsl ) => void ) =>
172+ new FuncPyDsl ( name , fn , { nameSanitizer : safeKeywordName } ) ) as {
173+ ( name : NodeName ) : FuncPyDsl ;
174+ ( name : NodeName , fn : ( f : FuncPyDsl ) => void ) : FuncPyDsl ;
175+ } ,
171176
172177 /** Creates a negation expression (`-x`). */
173178 // neg: (...args: ConstructorParameters<typeof PrefixTsDsl>) => new PrefixTsDsl(...args).neg(),
0 commit comments