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

Fix ConfigDict's handling of unicode keys #13

Merged
merged 1 commit into from Dec 12, 2016
Merged

Conversation

timj
Copy link
Member

@timj timj commented Dec 12, 2016

Make ConfigDict.__setitem__ call _autocast before checking the key type, just like Dict does. Add a unicode key in the unit test for each so that this is tested (and I confirmed the fix by commenting out the call to _autocast in both dict classes, and two tests failed.

This solves a problem that pybind11 returns unicode strings from C++ methods that return std::string; the problem was showing up in afw's testCameraGeom.py.

Make `ConfigDict.__setitem__` call `_autocast`
before checking the key type, just like `Dict` does.
Add a unicode key in the unit test for each
so that this is tested (and I confirmed the fix
by commenting out the call to `_autocast` in
both dict classes, and two tests failed.

This solves a problem that pybind11 returns unicode strings
from C++ methods that return std::string;
the problem was showing up in afw's `testCameraGeom.py`.
@timj timj self-assigned this Dec 12, 2016
@@ -48,6 +48,7 @@ def __setitem__(self, k, x, at=None, label="setitem", setHistory=True):
raise FieldValidationError(self._field, self._config, msg)

# validate keytype
k = _autocast(k, self._field.keytype)
Copy link
Member Author

Choose a reason for hiding this comment

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

@r-owen it's probably the case that we should be using _autocast more consistently in pex_config. This works because a future str is an instance of unicode, although at present, you end up with the unicode-ness being stripped so this is going to fail (and pex_config will fail in general) if we pass in unicode strings that can't be converted to native Python 2 str. There are advantages to dropping Python 2.

@r-owen r-owen merged commit 6c561ee into master Dec 12, 2016
@ktlim ktlim deleted the tickets/DM-8626 branch August 25, 2018 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants