77 from configparser import RawConfigParser |
77 from configparser import RawConfigParser |
78 from io import TextIOWrapper |
78 from io import TextIOWrapper |
79 except ImportError: |
79 except ImportError: |
80 from ConfigParser import RawConfigParser # __IGNORE_WARNING__ |
80 from ConfigParser import RawConfigParser # __IGNORE_WARNING__ |
81 |
81 |
82 __version__ = '2.1.0-eric' |
82 __version__ = '2.2.0-eric' |
83 |
83 |
84 DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox' |
84 DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox' |
85 DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503' |
85 DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503' |
86 try: |
86 try: |
87 if sys.platform == 'win32': |
87 if sys.platform == 'win32': |
924 |
924 |
925 Okay: import os |
925 Okay: import os |
926 Okay: # this is a comment\nimport os |
926 Okay: # this is a comment\nimport os |
927 Okay: '''this is a module docstring'''\nimport os |
927 Okay: '''this is a module docstring'''\nimport os |
928 Okay: r'''this is a module docstring'''\nimport os |
928 Okay: r'''this is a module docstring'''\nimport os |
929 Okay: try:\n import x\nexcept:\n pass\nelse:\n pass\nimport y |
929 Okay: |
930 Okay: try:\n import x\nexcept:\n pass\nfinally:\n pass\nimport y |
930 try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y |
|
931 Okay: |
|
932 try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y |
|
933 |
931 E402: a=1\nimport os |
934 E402: a=1\nimport os |
932 E402: 'One string'\n"Two string"\nimport os |
935 E402: 'One string'\n"Two string"\nimport os |
933 E402: a=1\nfrom sys import x |
936 E402: a=1\nfrom sys import x |
934 |
937 |
935 Okay: if x:\n import os |
938 Okay: if x:\n import os |
1192 if match and not noqa: |
1195 if match and not noqa: |
1193 inst = match.group(1) |
1196 inst = match.group(1) |
1194 if inst and isidentifier(inst) and inst not in SINGLETONS: |
1197 if inst and isidentifier(inst) and inst not in SINGLETONS: |
1195 return # Allow comparison for types which are not obvious |
1198 return # Allow comparison for types which are not obvious |
1196 yield match.start(), "E721 do not compare types, use 'isinstance()'" |
1199 yield match.start(), "E721 do not compare types, use 'isinstance()'" |
|
1200 |
|
1201 |
|
1202 def bare_except(logical_line, noqa): |
|
1203 r"""When catching exceptions, mention specific exceptions whenever possible. |
|
1204 |
|
1205 Okay: except Exception: |
|
1206 Okay: except BaseException: |
|
1207 E722: except: |
|
1208 """ |
|
1209 if noqa: |
|
1210 return |
|
1211 |
|
1212 regex = re.compile(r"except\s*:") |
|
1213 match = regex.match(logical_line) |
|
1214 if match: |
|
1215 yield match.start(), "E722 do not use bare except'" |
1197 |
1216 |
1198 |
1217 |
1199 def ambiguous_identifier(logical_line, tokens): |
1218 def ambiguous_identifier(logical_line, tokens): |
1200 r"""Never use the characters 'l', 'O', or 'I' as variable names. |
1219 r"""Never use the characters 'l', 'O', or 'I' as variable names. |
1201 |
1220 |