[MRG+1] Allowed passing objects of Mapping class or its subclass to the CaselessDict initializer #2646
Conversation
…essDict initializer
The feature make sense. I wonder if we should go further and just check for |
Generic |
ok, makes sense! |
seq = MyMutableMapping(red=1, black=3) | ||
d = CaselessDict(seq) | ||
self.assertEqual(d['red'], 1) | ||
self.assertEqual(d['black'], 3) |
kmike
Mar 14, 2017
Member
Could you please split it into several separate methods? Original test_init
implementation was not a good example, it should have been two methods in a first place.
Could you please split it into several separate methods? Original test_init
implementation was not a good example, it should have been two methods in a first place.
woxcab
Mar 15, 2017
•
Author
Contributor
@kmike, into which semantic methods to split this method? I.e. what is the criterion for the splitting?
@kmike, into which semantic methods to split this method? I.e. what is the criterion for the splitting?
kmike
Mar 15, 2017
Member
by input to the CaselessDict constructor: dict, sequence, Mapping, MutableMapping
by input to the CaselessDict constructor: dict, sequence, Mapping, MutableMapping
woxcab
Mar 15, 2017
Author
Contributor
Completed.
Completed.
Codecov Report
@@ Coverage Diff @@
## master #2646 +/- ##
==========================================
+ Coverage 84.25% 84.26% +0.01%
==========================================
Files 162 162
Lines 9106 9106
Branches 1350 1350
==========================================
+ Hits 7672 7673 +1
Misses 1174 1174
+ Partials 260 259 -1
Continue to review full report at Codecov.
|
CaselessDict can process sequence of general Mapping/MutableMapping class or subclass of Mapping.
Documentations both for Python 2 and Python 3 declare that all instances of
Mapping
class haveitems()
method, so it's safely to generalize check fromisinstance(seq, dict)
.Real usage example:
requests
package returns responses which headers are instances ofrequests.structures.CaseInsensitiveDict
that is subclass ofMutableMapping
and this patch allows to pass these headers directly toscrapy.Response
initializer.