Repository navigation
fix(python): accept out_type in DecodeIds and DecodePieces - #1336
Merged
Merged
Conversation
DecodeIds and DecodePieces default return_type to str and forward it to Decode, so passing the documented legacy alias out_type always raised "Cannot specify both out_type and return_type". Default return_type to None instead; Decode already falls back to str.
Collaborator
|
Thanks for the fix! Note that out_type is deprecated and we plan to remove it in a future release, so please migrate to return_type. That said, as long as it's still supported as an alias, DecodeIds/DecodePieces should behave consistently with decode, so I'll merge this. A DeprecationWarning for out_type will be added in a follow-up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the change
DecodeIdsandDecodePieces(anddecode_ids/decode_pieces) defaultreturn_typetostrand pass it toDecodetogether with**kwargs. Soreturn_typeis neverNonethere, and anyout_typefrom the caller trips the "both specified" check:out_typeworked on these methods before the pybind11 migration, the README says it is still supported as an alias, the.pyistubs list it on both methods, andsp.decode(ids, out_type=bytes)works.The fix defaults
return_typetoNonein both wrappers.Decodealready falls back tostr, so calls without either argument still returnstr, and passing both still raises.Testing Information
Extended
test_legacy_out_type_compatwithDecodeIds(ids, out_type=bytes)anddecode_pieces(pieces, out_type=bytes). It fails with theValueErrorabove before the change and passes after.Ran
pytest test/inpython/(Windows, Python 3.12). Every other test gives the same result with and without this change (test_trainandtest_train_iteratorfail on my machine only because my checkout path contains spaces).tools/gen_stubs.py --checkpasses, so the stub is unchanged.