@@ -268,6 +268,106 @@ After:
268268
269269**async is a NAME here, not a keyword ** (because you can do `async = 42 `.)
270270
271+ Typed arguments
272+ ---------------
273+
274+ Python 3.3 or earlier
275+
276+ Baron: https://github.com/PyCQA/baron/pull/140
277+ RedBaron: Done
278+
279+ .. image :: ./grammar_diff/typed_args.png
280+
281+ Action:
282+
283+ ::
284+
285+ # parameters
286+ # this is mixed with the removal of def a((b, c)): style
287+ # which will probably need to continue supporting
288+
289+ CHANGE parameters: '(' [varargslist] ')'
290+ ^
291+ TO parameters: '(' [typedargslist] ')'
292+ ^
293+
294+ ::
295+
296+ # CHANGE
297+ varargslist:
298+ (
299+ (fpdef ['=' test] ',')*
300+ (
301+ '*' NAME [',' '**' NAME]
302+ |
303+ '**' NAME
304+ )
305+ |
306+ fpdef ['=' test]
307+ (',' fpdef ['=' test])*
308+ [',']
309+ )
310+
311+ fpdef: NAME | '(' fplist ')'
312+ fplist: fpdef (',' fpdef)* [',']
313+
314+ # TO
315+ typedargslist:
316+ (
317+ tfpdef ['=' test]
318+ (',' tfpdef ['=' test])*
319+ [
320+ ','
321+ [
322+ '*' [tfpdef]
323+ (',' tfpdef ['=' test])*
324+ [',' ['**' tfpdef [',']]]
325+ |
326+ '**' tfpdef [',']
327+ ]
328+ ]
329+ |
330+ '*' [tfpdef]
331+ (',' tfpdef ['=' test])*
332+ [',' ['**' tfpdef [',']]]
333+ |
334+ '**' tfpdef [',']
335+ )
336+
337+ # after some analysis, this is just a refactoring of the previous form with
338+ # fpdef being changed to vfpdef
339+ varargslist:
340+ (
341+ vfpdef ['=' test]
342+ (',' vfpdef ['=' test])*
343+ [
344+ ','
345+ [
346+ '*' [vfpdef]
347+ (',' vfpdef ['=' test])*
348+ [',' ['**' vfpdef [',']]]
349+ |
350+ '**' vfpdef [',']
351+ ]
352+ ]
353+ |
354+ '*' [vfpdef]
355+ (',' vfpdef ['=' test])*
356+ [',' ['**' vfpdef [',']]]
357+ |
358+ '**' vfpdef [',']
359+ )
360+
361+ tfpdef: NAME [':' test]
362+
363+ vfpdef: NAME
364+
365+
366+
367+
368+
369+
370+
271371TODO
272372====
273373
@@ -455,142 +555,6 @@ After:
455555 ('=' (yield_expr|testlist_star_expr))*)
456556 annassign: ':' test ['=' test]
457557
458- Refactoring in typedargslist ?
459- ------------------------------
460-
461- I think this is for asynchronous generator and comprehension:
462-
463- * https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep525
464- * https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep530
465-
466- Before:
467-
468- ::
469-
470- typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [','
471- ['*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef]]
472- | '*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
473- varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [','
474- ['*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef]]
475- | '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
476-
477- After:
478-
479- ::
480-
481- typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [','
482- ['*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
483- | '**' tfpdef [',']]]
484- | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
485- | '**' tfpdef [','])
486- varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [','
487- ['*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
488- | '**' vfpdef [',']]]
489- | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
490- | '**' vfpdef [',']
491- )
492-
493-
494- Typed arguments
495- ---------------
496-
497- Python 3.3 or earlier
498-
499- Baron: https://github.com/PyCQA/baron/pull/140
500- RedBaron: WIP
501-
502- .. image :: ./grammar_diff/typed_args.png
503-
504- Action:
505-
506- ::
507-
508- # parameters
509- # this is mixed with the removal of def a((b, c)): style
510- # which will probably need to continue supporting
511-
512- CHANGE parameters: '(' [varargslist] ')'
513- ^
514- TO parameters: '(' [typedargslist] ')'
515- ^
516-
517- ::
518-
519- # CHANGE
520- varargslist:
521- (
522- (fpdef ['=' test] ',')*
523- (
524- '*' NAME [',' '**' NAME]
525- |
526- '**' NAME
527- )
528- |
529- fpdef ['=' test]
530- (',' fpdef ['=' test])*
531- [',']
532- )
533-
534- fpdef: NAME | '(' fplist ')'
535- fplist: fpdef (',' fpdef)* [',']
536-
537- # TO
538- typedargslist:
539- (
540- tfpdef ['=' test]
541- (',' tfpdef ['=' test])*
542- [
543- ','
544- [
545- '*' [tfpdef]
546- (',' tfpdef ['=' test])*
547- [',' ['**' tfpdef [',']]]
548- |
549- '**' tfpdef [',']
550- ]
551- ]
552- |
553- '*' [tfpdef]
554- (',' tfpdef ['=' test])*
555- [',' ['**' tfpdef [',']]]
556- |
557- '**' tfpdef [',']
558- )
559-
560- # after some analysis, this is just a refactoring of the previous form with
561- # fpdef being changed to vfpdef
562- varargslist:
563- (
564- vfpdef ['=' test]
565- (',' vfpdef ['=' test])*
566- [
567- ','
568- [
569- '*' [vfpdef]
570- (',' vfpdef ['=' test])*
571- [',' ['**' vfpdef [',']]]
572- |
573- '**' vfpdef [',']
574- ]
575- ]
576- |
577- '*' [vfpdef]
578- (',' vfpdef ['=' test])*
579- [',' ['**' vfpdef [',']]]
580- |
581- '**' vfpdef [',']
582- )
583-
584- tfpdef: NAME [':' test]
585-
586- vfpdef: NAME
587-
588-
589-
590-
591-
592-
593-
594558
595559
596560
0 commit comments