Open michal-klimek opened 2 years ago
@Lukasa , @sigmavirus24
LookupDict
object inherits dict
object , so it's basically a dictionary. However, when setting a key to a value like codes["my_code"] = 700
from @michal-klimek example, that key is inaccessible because __getitem__
and get
methods have been overridden only to access the object's attributes.
To resolve this issue, we can override the __setitem__
to write key-value pairs to object's attributes or __dict__
.
Do you agree with this solution?
LookupDict
absolutely includes all of the dict methods. In particular, it allows the use of__setitem__
and other things from the dict class. It specifically does only one thing, which is override__getitem__
to allow returningNone
.So it's not ok to replace the dict with
object
in this case, even though the requests codebase doesn't use that functionality.Thanks for reporting this issue though, and I hope you keep reading through the codebase!
Originally posted by @Lukasa in https://github.com/psf/requests/issues/3848#issuecomment-277197592
This is unfortunately a false statement. Take a look on the following checks:
If
LookupDict
pretends to quack like a duck it should do so. Or it should not derive from thedict
if it works even worse: