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
Aspects: Add more robust setting checks #4582
Conversation
1988cc9
to
42cfd09
Compare
coalib/settings/Setting.py
Outdated
""" | ||
try: | ||
return Language[name] | ||
except AttributeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line of your patch is correct, but will need to change if #4643 is merged, as that fixes a fairly fundamental exception problem.
coalib/settings/Setting.py
Outdated
@@ -44,6 +45,21 @@ def glob_list(obj, *args, **kwargs): | |||
return obj.__glob_list__(*args, **kwargs) | |||
|
|||
|
|||
def language_obj(name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not keen on this name. This name needs to be used in Bear.run()
override arg lists, and becomes part of our documentation. Can it simply be language
? And be used as def run(.... , language: language):
; while that looks like it might be wrong, it should work and do the right thing.
The other alternative is that the run
argument validator should work correctly with def run(.... , language: Language):
, which would require improvements to the argument validator so that dict subclass, like Language
, are checked using the value to key-index the dict, and thus KeyError
would be the expected exception of incorrect values instead of ValueError
.
Also, in order to properly solve #4463 , this PR should include a test which is a Bear using language: language
.
42cfd09
to
24dc08b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor improvements needed
return False | ||
|
||
if not len(aspects_language): | ||
logging.warning('Language setting is not found in section `{}`. ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Language setting ..
-> Setting 'language' ..
logging.getLogger()) as cm: | ||
self.assertTrue(check_aspect_config( | ||
self.section, acquire_settings)) | ||
self.assertRegex(cm.output[0], 'Language setting is not found in ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start the string on a new line. (also below..)
tests/settings/SettingTest.py
Outdated
from coalib.settings.Setting import ( | ||
Setting, path, path_list, url, typed_dict, typed_list, typed_ordered_dict, | ||
glob, glob_list) | ||
glob, glob_list, language) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on a new line, as it isnt a glob.
24dc08b
to
3e53e03
Compare
3e53e03
to
a0adcba
Compare
a0adcba
to
2179535
Compare
return sections | ||
|
||
|
||
def check_aspect_config(section, acquire_settings): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isnt a check_..
, as it does UI and it modifies the section
4e6e597
to
e4455e0
Compare
Add new commit to fix #4681 |
return True | ||
|
||
|
||
def validate_and_inject_language(sections): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be just _set_section_language
. validation is assumed. doesnt need to be part of public API
coalib/settings/Section.py
Outdated
@@ -46,24 +46,18 @@ def append_to_sections(sections, | |||
|
|||
def extract_aspects_from_section(section): | |||
""" | |||
Extracts aspects and their related settings from a section and create an | |||
AspectList from it. | |||
Extracts aspects settings from a section into an AspectList. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Singular 'Extract', not plural
e4455e0
to
67ef72b
Compare
ack 67ef72b 5f90a8b 25893e2 c8f1405 fc75951 82ec615 9979e16 |
``aspect`` passed to ``Result`` should be instance of aspectbase.
Move everything related to validating a correct aspect section into its own function.
Dynamically create `aspects` attribute only when aspects is detected is prone to many edge case bugs. Fixes coala#4681
67ef72b
to
a697b09
Compare
@rultor merge |
Closes #4580 #4463