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