@@ -381,7 +381,8 @@ class Error(object):
381
381
382
382
# should be overridden by inheriting classes
383
383
code = None
384
- _message = None
384
+ short_desc = None
385
+ context = None
385
386
386
387
# Options that define how errors are printed:
387
388
explain = False
@@ -401,7 +402,10 @@ def set_context(self, definition, explanation):
401
402
402
403
@property
403
404
def message (self ):
404
- return '%s: %s' % (self .code , self ._message ) % self .parameters
405
+ ret = '%s: %s' % (self .code , self .short_desc )
406
+ if self .context is not None :
407
+ ret += ' (' + self .context % self .parameters + ')'
408
+ return ret
405
409
406
410
@property
407
411
def lines (self ):
@@ -446,18 +450,19 @@ class ErrorRegistry(object):
446
450
groups = []
447
451
448
452
class ErrorGroup (object ):
449
- errors = []
450
453
451
454
def __init__ (self , prefix , name ):
452
455
self .prefix = prefix
453
456
self .name = name
457
+ self .errors = []
454
458
455
- def create_error (self , error_code , error_message ):
459
+ def create_error (self , error_code , error_desc , error_context = None ):
456
460
# TODO: check prefix
457
461
458
462
class _Error (Error ):
459
463
code = error_code
460
- _message = error_message
464
+ short_desc = error_desc
465
+ context = error_context
461
466
462
467
self .errors .append (_Error )
463
468
return _Error
@@ -470,13 +475,26 @@ def create_group(cls, prefix, name):
470
475
471
476
@classmethod
472
477
def get_error_codes (cls ):
473
- # TODO: implement
474
- pass
478
+ for group in cls .groups :
479
+ for error in group .errors :
480
+ yield error
475
481
476
482
@classmethod
477
483
def to_rst (cls ):
478
- # TODO: implement
479
- pass
484
+ sep_line = '+' + 6 * '-' + '+' + '-' * 71 + '+\n '
485
+ blank_line = '|' + 78 * ' ' + '|\n '
486
+ table = ''
487
+ for group in cls .groups :
488
+ table += sep_line
489
+ table += blank_line
490
+ table += '|' + ('**%s**' % group .name ).center (78 ) + '|\n '
491
+ table += blank_line
492
+ for error in group .errors :
493
+ table += sep_line
494
+ table += ('|' + error .code .center (6 ) + '| ' +
495
+ error .short_desc .ljust (70 ) + '|\n ' )
496
+ table += sep_line
497
+ return table
480
498
481
499
482
500
D1xx = ErrorRegistry .create_group ('D1' , 'Missing Docstrings' )
@@ -487,17 +505,17 @@ def to_rst(cls):
487
505
488
506
D2xx = ErrorRegistry .create_group ('D2' , 'Whitespace Issues' )
489
507
D200 = D2xx .create_error ('D200' , 'One-line docstring should fit on one line '
490
- 'with quotes, found %s' )
508
+ 'with quotes' , ' found %s' )
491
509
D201 = D2xx .create_error ('D201' , 'No blank lines allowed before function '
492
- 'docstring, found %s' )
510
+ 'docstring' , ' found %s' )
493
511
D202 = D2xx .create_error ('D202' , 'No blank lines allowed after function '
494
- 'docstring, found %s' )
512
+ 'docstring' , ' found %s' )
495
513
D203 = D2xx .create_error ('D203' , '1 blank line required before class '
496
- 'docstring, found %s' )
514
+ 'docstring' , ' found %s' )
497
515
D204 = D2xx .create_error ('D204' , '1 blank line required after class '
498
- 'docstring, found %s' )
516
+ 'docstring' , ' found %s' )
499
517
D205 = D2xx .create_error ('D205' , '1 blank line required between summary line '
500
- 'and description, found %s' )
518
+ 'and description' , ' found %s' )
501
519
D206 = D2xx .create_error ('D206' , 'Docstring should be indented with spaces, '
502
520
'not tabs' )
503
521
D207 = D2xx .create_error ('D207' , 'Docstring is under-indented' )
@@ -508,15 +526,16 @@ def to_rst(cls):
508
526
'docstring text' )
509
527
510
528
D3xx = ErrorRegistry .create_group ('D3' , 'Quotes Issues' )
511
- D300 = D3xx .create_error ('D300' , 'Use """triple double quotes""", found '
512
- ' %s-quotes' )
529
+ D300 = D3xx .create_error ('D300' , 'Use """triple double quotes"""' ,
530
+ 'found %s-quotes' )
513
531
D301 = D3xx .create_error ('D301' , 'Use r""" if any backslashes in a docstring' )
514
532
D302 = D3xx .create_error ('D302' , 'Use u""" for Unicode docstrings' )
515
533
516
534
D4xx = ErrorRegistry .create_group ('D4' , 'Docstring Content Issues' )
517
- D400 = D4xx .create_error ('D400' , 'First line should end with a period, not %r' )
518
- D401 = D4xx .create_error ('D401' , 'First line should be in imperative mood: '
519
- '%r, not %r' )
535
+ D400 = D4xx .create_error ('D400' , 'First line should end with a period' ,
536
+ 'not %r' )
537
+ D401 = D4xx .create_error ('D401' , 'First line should be in imperative mood' ,
538
+ '%r, not %r' )
520
539
D402 = D4xx .create_error ('D402' , 'First line should not be the function\' s '
521
540
'"signature"' )
522
541
0 commit comments