@@ -627,8 +627,14 @@ def to_rst(cls):
627
627
'"signature"' )
628
628
629
629
630
- class Conventions (object ):
631
- pep257 = set (ErrorRegistry .get_error_codes ())
630
+ class AttrDict (dict ):
631
+ def __getattr__ (self , item ):
632
+ return self [item ]
633
+
634
+
635
+ conventions = AttrDict ({
636
+ 'pep257' : set (ErrorRegistry .get_error_codes ()),
637
+ })
632
638
633
639
634
640
def get_option_parser ():
@@ -652,7 +658,8 @@ def get_option_parser():
652
658
'codes). for example: --ignore=D101,D202' )
653
659
option ('--convention' , metavar = '<name>' , default = '' ,
654
660
help = 'choose the basic list of checked errors by specifying an '
655
- 'existing convention. for example: --convention=pep257' )
661
+ 'existing convention. Possible conventions: {0}'
662
+ .format (', ' .join (conventions )))
656
663
option ('--add-select' , metavar = '<codes>' , default = '' ,
657
664
help = 'amend the list of errors to check for by specifying more '
658
665
'error codes to check.' )
@@ -717,7 +724,7 @@ def check(filenames, select=None, ignore=None):
717
724
checked_codes = (select or
718
725
set (ErrorRegistry .get_error_codes ()) - set (ignore ))
719
726
else :
720
- checked_codes = Conventions .pep257
727
+ checked_codes = conventions .pep257
721
728
722
729
for filename in filenames :
723
730
log .info ('Checking file %s.' , filename )
@@ -812,9 +819,9 @@ def get_checked_error_codes(options):
812
819
elif options .select :
813
820
checked_codes = set (options .select .split (',' ))
814
821
elif options .convention :
815
- checked_codes = getattr (Conventions , options .convention )
822
+ checked_codes = getattr (conventions , options .convention )
816
823
else :
817
- checked_codes = Conventions .pep257
824
+ checked_codes = conventions .pep257
818
825
checked_codes -= set (options .add_ignore .split (',' ))
819
826
checked_codes |= set (options .add_select .split (',' ))
820
827
return checked_codes - set ('' )
@@ -827,7 +834,9 @@ def validate_options(options):
827
834
log .error ('Cannot pass both {0} and {1}. They are '
828
835
'mutually exclusive.' .format (opt1 , opt2 ))
829
836
return False
830
- if options .convention and not hasattr (Conventions , options .convention ):
837
+ if options .convention and options .convention not in conventions :
838
+ log .error ("Illegal convention '{0}'. Possible conventions: {1}"
839
+ .format (options .convention , ', ' .join (conventions .keys ())))
831
840
return False
832
841
return True
833
842
0 commit comments