Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling warnings about members not existing by default #102

Merged
merged 1 commit into from
Jan 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions prospector/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,21 @@ def _get_profile(self, path, config):
profile_name = 'default'
extra_profiles = []

if config.doc_warnings is not None and config.doc_warnings:
cmdline_implicit.append('doc_warnings')
if config.test_warnings is not None and config.test_warnings:
cmdline_implicit.append('test_warnings')
if config.no_style_warnings is not None and config.no_style_warnings:
cmdline_implicit.append('no_pep8')
if config.full_pep8 is not None and config.full_pep8:
cmdline_implicit.append('full_pep8')

# Use the strictness profile only if no profile has been given
if config.strictness is not None and config.strictness:
cmdline_implicit.append('strictness_%s' % config.strictness)
strictness = config.strictness
if config.doc_warnings is not None and config.doc_warnings:
cmdline_implicit.append('doc_warnings')
if config.test_warnings is not None and config.test_warnings:
cmdline_implicit.append('test_warnings')
if config.no_style_warnings is not None and config.no_style_warnings:
cmdline_implicit.append('no_pep8')
if config.full_pep8 is not None and config.full_pep8:
cmdline_implicit.append('full_pep8')
if config.member_warnings is not None and config.member_warnings:
cmdline_implicit.append('member_warnings')

# Use the strictness profile only if no profile has been given
if config.strictness is not None and config.strictness:
cmdline_implicit.append('strictness_%s' % config.strictness)
strictness = config.strictness

# the profile path is
# * anything provided as an argument
Expand Down
7 changes: 7 additions & 0 deletions prospector/config/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def build_manager():
manager.add(soc.BooleanSetting('doc_warnings', default=None))
manager.add(soc.BooleanSetting('test_warnings', default=None))
manager.add(soc.BooleanSetting('no_style_warnings', default=None))
manager.add(soc.BooleanSetting('member_warnings', default=None))
manager.add(soc.BooleanSetting('full_pep8', default=None))
manager.add(soc.IntegerSetting('max_line_length', default=None))

Expand Down Expand Up @@ -137,6 +138,12 @@ def build_command_line_source(prog=None, description='Performs static analysis o
'help': 'Don\'t create any warnings about style. This disables the'
' PEP8 tool and similar checks for formatting.',
},
'member_warnings': {
'flags': ['-m', '--member-warnings'],
'help': 'Attempt to warn when code tries to access an attribute of a '
'class or member of a module which does not exist. This is disabled '
'by default as it tends to be quite inaccurate.'
},
'full_pep8': {
'flags': ['-F', '--full-pep8'],
'help': 'Enables every PEP8 warning, so that all PEP8 style'
Expand Down
20 changes: 17 additions & 3 deletions prospector/profiles/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, name, profile_dict, inherit_order):
self.ignore_patterns = profile_dict.get('ignore-patterns', []) + profile_dict.get('ignore', [])

self.output_format = profile_dict.get('output-format')
self.member_warnings = profile_dict.get('member-warnings')
self.autodetect = profile_dict.get('autodetect')
self.uses = [uses for uses in _ensure_list(profile_dict.get('uses', [])) if uses in ('django', 'celery')]
self.max_line_length = profile_dict.get('max-line-length')
Expand Down Expand Up @@ -63,7 +64,8 @@ def as_dict(self):
'output-format': self.output_format,
'autodetect': self.autodetect,
'uses': self.uses,
'max-line-length': self.max_line_length
'max-line-length': self.max_line_length,
'member-warnings': self.member_warnings,
}
for tool in TOOLS.keys():
out[tool] = getattr(self, tool)
Expand Down Expand Up @@ -146,7 +148,8 @@ def _merge_profile_dict(priority, base):
out = dict(base.items())

for key, value in priority.items():
if key in ('strictness', 'doc-warnings', 'test-warnings', 'output-format', 'autodetect', 'max-line-length'):
if key in ('strictness', 'doc-warnings', 'test-warnings', 'member-warnings',
'output-format', 'autodetect', 'max-line-length',):
# some keys are simple values which are overwritten
out[key] = value
elif key in ('ignore', 'ignore-patterns', 'ignore-paths', 'uses'):
Expand Down Expand Up @@ -193,6 +196,13 @@ def _determine_test_warnings(profile_dict):
return (None if test_warnings else 'no_test_warnings'), True


def _determine_member_warnings(profile_dict):
member_warnings = profile_dict.get('member-warnings')
if member_warnings is None:
return None, False
return ('member_warnings' if member_warnings else 'no_member_warnings'), True


def _determine_implicit_inherits(profile_dict, already_inherits, shorthands_found):
# Note: the ordering is very important here - the earlier items
# in the list have precedence over the later items. The point of
Expand All @@ -202,7 +212,8 @@ def _determine_implicit_inherits(profile_dict, already_inherits, shorthands_foun
('pep8', _determine_pep8(profile_dict)),
('docs', _determine_doc_warnings(profile_dict)),
('tests', _determine_test_warnings(profile_dict)),
('strictness', _determine_strictness(profile_dict, already_inherits))
('strictness', _determine_strictness(profile_dict, already_inherits)),
('members', _determine_member_warnings(profile_dict)),
]
inherits = []

Expand Down Expand Up @@ -236,6 +247,9 @@ def _load_and_merge(name_or_path, profile_path, allow_shorthand=True, forced_inh
if 'docs' not in shorthands_found:
data, inherit_list = _append_profiles('no_doc_warnings', profile_path, data, inherit_list)

if 'members' not in shorthands_found:
data, inherit_list = _append_profiles('no_member_warnings', profile_path, data, inherit_list)

if 'tests' not in shorthands_found:
data, inherit_list = _append_profiles('no_test_warnings', profile_path, data, inherit_list)

Expand Down
1 change: 1 addition & 0 deletions prospector/profiles/profiles/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ strictness: medium
doc-warnings: false
test-warnings: false
autodetect: true
member-warnings: false
6 changes: 6 additions & 0 deletions prospector/profiles/profiles/member_warnings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
allow-shorthand: false

pylint:
enable:
- no-member
- no-name-in-module
6 changes: 6 additions & 0 deletions prospector/profiles/profiles/no_member_warnings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
allow-shorthand: false

pylint:
disable:
- no-member
- no-name-in-module