[MRG] Item multi inheritance fix #353
Conversation
@@ -33,6 +33,9 @@ def __new__(mcs, class_name, bases, attrs): | |||
cls = type.__new__(mcs, class_name, bases, new_attrs) | |||
cls.fields = cls.fields.copy() | |||
cls.fields.update(fields) | |||
for base in bases: | |||
fields = base.fields.copy() | |||
cls.fields.update(fields) |
dangra
Jul 22, 2013
Member
dict.update()
already does a shallow copy of base.fields
, no need to copy()
it.
and bases can be non-Item too, think on mixins not extending scrapy.item.Item
class.
dict.update()
already does a shallow copy of base.fields
, no need to copy()
it.
and bases can be non-Item too, think on mixins not extending scrapy.item.Item
class.
nramirezuy
Jul 22, 2013
Author
Contributor
If I remove the copies the tests fails, I'm not sure why.
If I remove the copies the tests fails, I'm not sure why.
keys = Field() | ||
values = Field() | ||
|
||
class FinalItem(BaseItem, NameItem): |
dangra
Dec 16, 2013
Member
This lacks a test for a field that exists in base classes and it is redefined in FinalItem.
This lacks a test for a field that exists in base classes and it is redefined in FinalItem.
|
||
i = FinalItem(keys=3, name='Manolo') | ||
self.assertEqual(i['keys'], 3) | ||
self.assertEqual(i['name'], 'Manolo') |
dangra
Dec 16, 2013
Member
it misses values
field test
it misses values
field test
@@ -33,6 +33,10 @@ def __new__(mcs, class_name, bases, attrs): | |||
cls = type.__new__(mcs, class_name, bases, new_attrs) | |||
cls.fields = cls.fields.copy() | |||
cls.fields.update(fields) | |||
for base in bases: | |||
if issubclass(base, DictItem): |
dangra
Dec 16, 2013
Member
missing a unit test case for mixed base classes that are not DictItem subclasses.
missing a unit test case for mixed base classes that are not DictItem subclasses.
@dangra Tests added and a behavior fix. Do you want to add the @arijitchakraborty SEP from #487 to the sep folder? |
for base in bases: | ||
if issubclass(base, DictItem): | ||
fields = base.fields.copy() | ||
fields.update(fields) |
dangra
Jul 30, 2014
Member
How is this supposed to work? it updates fields
with fields
and opaques the declaration of fields
in line 26
How is this supposed to work? it updates fields
with fields
and opaques the declaration of fields
in line 26
What is missing in this PR? Can it be merged? |
@chekunkov anything to comment on its implementation? From my past comments I still don't get a test case for defining and/or overriding fields of its parents. |
@@ -24,18 +24,20 @@ class Field(dict): | |||
class ItemMeta(ABCMeta): | |||
|
|||
def __new__(mcs, class_name, bases, attrs): | |||
_class = super(ItemMeta, mcs).__new__(mcs, 'x_' + class_name, tuple(base._class for base in bases if hasattr(base, '_class')), attrs) |
kmike
Apr 21, 2015
Member
hey @nramirezuy - could you please split it into multiple lines?
e.g. tuple(base._class for base in bases if hasattr(base, '_class'))
is a good candidate for a local variable.
hey @nramirezuy - could you please split it into multiple lines?
e.g. tuple(base._class for base in bases if hasattr(base, '_class'))
is a good candidate for a local variable.
nramirezuy
Apr 21, 2015
Author
Contributor
done 😄
done
0010e3a
to
49a2cc9
class D(B, C): pass | ||
|
||
self.assertEqual(D(save='X')['save'], 'X') | ||
self.assertEqual(D.fields, {'save': {'default': 'C'}}) |
dangra
Apr 21, 2015
Member
I think it lacks another testcase where class D overrides a field defined in class A or B.
I think it lacks another testcase where class D overrides a field defined in class A or B.
nramirezuy
Apr 21, 2015
Author
Contributor
Done for D and E
Done for D and E
49a2cc9
to
7871acd
You have my +1 to merge as long as tests passes in Travis-CI for python2 and python3 |
[MRG] Item multi inheritance fix
Changes Unknown when pulling 7871acd on nramirezuy:item-multi_inherit into ** on scrapy:master**. |
No description provided.