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

AspectList: Overload __init__ to accept strings #4389

Merged
merged 1 commit into from
Jun 25, 2017

Conversation

adhikasp
Copy link
Member

Overload aspectlist so it could be instanced from a list of string
containing aspects name. The reason of this overloading is to make
it possible to instanced list of desired aspects found in coafile.

>>> aspectlist(['coalaCorrect', 'aspectsYEAH'])
[<aspectclass '...coalaCorrect'>, <aspectclass '...aspectsYEAH'>]

Replacement of #4379
Closes #4382

@@ -1,3 +1,4 @@
import coalib.bearlib.aspects
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace'

PycodestyleBear (W291), severity NORMAL, section autopep8.

@@ -1,3 +1,4 @@
import coalib.bearlib.aspects
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not comply to PEP8.

PEP8Bear, severity NORMAL, section autopep8.

The issue can be fixed by applying the following patch:

--- a/coalib/bearlib/aspects/collections.py
+++ b/coalib/bearlib/aspects/collections.py
@@ -1,4 +1,4 @@
-import coalib.bearlib.aspects 
+import coalib.bearlib.aspects
 from coalib.bearlib.aspects.meta import issubaspect, assert_aspect
 
 

@@ -1,3 +1,4 @@
import coalib.bearlib.aspects
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

SpaceConsistencyBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/coalib/bearlib/aspects/collections.py
+++ b/coalib/bearlib/aspects/collections.py
@@ -1,4 +1,4 @@
-import coalib.bearlib.aspects 
+import coalib.bearlib.aspects
 from coalib.bearlib.aspects.meta import issubaspect, assert_aspect
 
 

Copy link
Member

@userzimmermann userzimmermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adhikasp Good approach but doesn't handle mixed cases :/

instance, or string of partial/full qualified aspect name.
"""
if all(map((lambda x: isinstance(x, str)), seq)):
seq = map((lambda x: coalib.bearlib.aspects[x]), seq)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't cover mixed cases like aspectlist([Root.Spelling.coalaCorrect, 'aspectsYEAH'])

Better super().__init__(item if isaspect(item) else coalib.bearlib.aspects[item] for item in seq)

@@ -9,10 +9,15 @@
class aspectlistTest:

def test__init__(self):
with pytest.raises(aspectTypeError) as exc:
list_of_aspect = aspectlist(['CommitMessage.Shortlog',
'CommitMessage.Body'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test aspectclass/instance/string-only and mixed cases

>>> aspectlist([Root.Spelling.coalaCorrect, Root.Spelling.aspectsYEAH])
[<aspectclass '...coalaCorrect'>, <aspectclass '...aspectsYEAH'>]
>>> aspectlist(['coalaCorrect', 'aspectsYEAH'])
[<aspectclass '...coalaCorrect'>, <aspectclass '...aspectsYEAH'>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add mixed cases

Copy link
Member

@userzimmermann userzimmermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please add Relates to https://gitlab.com/coala/GSoC-2017/issues/299 to the commit message

@adhikasp adhikasp force-pushed the adhikasp/aspectlist-overload branch from 62093d6 to a530545 Compare June 22, 2017 19:33
@adhikasp
Copy link
Member Author

@userzimmermann updated

@adhikasp adhikasp force-pushed the adhikasp/aspectlist-overload branch 2 times, most recently from dd480b6 to 497adf7 Compare June 23, 2017 21:31
@adhikasp adhikasp force-pushed the adhikasp/aspectlist-overload branch from 497adf7 to b8a7d27 Compare June 24, 2017 19:06
aspectlist(['String'])
exc.match("'String' is not an aspectclass or "
'an instance of an aspectclass')
exc.match("no aspect named 'String'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception messages should begin with a capital letter: No aspect named ...

Please raise a bug to fix that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've raised #4402


>>> from .root import Root
>>> from .Spelling import Spelling
>>> aspectlist([Root.Spelling.coalaCorrect, Root.Spelling.aspectsYEAH])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4401 should be fixed first, otherwise lots of unnecessary changes occur.

@adhikasp adhikasp force-pushed the adhikasp/aspectlist-overload branch from b8a7d27 to c6cb0bb Compare June 25, 2017 13:21
@adhikasp adhikasp force-pushed the adhikasp/aspectlist-overload branch 2 times, most recently from 6204bf9 to 23220da Compare June 25, 2017 14:12
@jayvdb jayvdb changed the title aspectlist: Overload __init__ to accept strings AspectList: Overload __init__ to accept strings Jun 25, 2017
Copy link
Member

@jayvdb jayvdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit message needs updating to reflect fixed class name.

'CommitMessage.Body'])
mix_of_aspect = AspectList(['CommitMessage.Shortlog',
Metadata.CommitMessage.Body])
assert isinstance(list_of_aspect, AspectList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace assert with self.assert...(...) (This was mentioned to you in another PR just merged; fix all of your PRs)

Overload AspectList so it could be instanced from a list of string
containing aspects name. The reason of this overloading is to make
it possible to instanced list of desired aspects name found in
coafiles.

```python
>>> AspectList(['coalaCorrect', 'aspectsYEAH'])
[<aspectclass '...coalaCorrect'>, <aspectclass '...aspectsYEAH'>]
```

Replacement of coala#4379
Closes coala#4382
@adhikasp adhikasp force-pushed the adhikasp/aspectlist-overload branch from 928d39f to 852ba5e Compare June 25, 2017 16:45
@jayvdb jayvdb added process/approved The PR is approved and will be merged soon and removed process/pending review labels Jun 25, 2017
@jayvdb
Copy link
Member

jayvdb commented Jun 25, 2017

ack 852ba5e

@jayvdb
Copy link
Member

jayvdb commented Jun 25, 2017

@Tultor merge

@jayvdb
Copy link
Member

jayvdb commented Jun 25, 2017

@rultor merge

@rultor
Copy link
Contributor

rultor commented Jun 25, 2017

@rultor merge

@jayvdb OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 852ba5e into coala:master Jun 25, 2017
@rultor
Copy link
Contributor

rultor commented Jun 25, 2017

@rultor merge

@jayvdb Done! FYI, the full log is here (took me 2min)

@userzimmermann
Copy link
Member

@adhikasp @jayvdb This was merged a bit too early. It misses tests with aspect instances as mentioned in #4389 (comment) . But anyway... We can add that later ;)

@adhikasp adhikasp deleted the adhikasp/aspectlist-overload branch July 7, 2017 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/aspects process/approved The PR is approved and will be merged soon size/S type/feature
Development

Successfully merging this pull request may close these issues.

5 participants