Raise the intended error when a space type has no deserializer - #345
Open
DenisDrobyshev wants to merge 2 commits into
Open
DenisDrobyshev wants to merge 2 commits into
DenisDrobyshev wants to merge 2 commits into
Conversation
type_value_dispatch built its table as defaultdict(func). defaultdict calls
its factory with no arguments, so an unregistered type called the fallback
without space_dict and the caller saw
TypeError: deserialize_space() missing 1 required positional argument
instead of the NotImplementedError the fallback is written to raise. The
factory now returns the fallback rather than being it.
serialize_space already reported unsupported types correctly, and only that
direction was covered by a test.
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.
Description
deserialize_spacereports an unregistered space type with the wrong error:type_value_dispatchbuilds its table asdefaultdict(func).defaultdictcalls its factory with no arguments, so
func— the fallback, which takesspace_dict— was invoked without it. TheNotImplementedErrorit is writtento raise never got the chance:
The factory now returns the fallback rather than being it, and the message
names the type that has no deserializer.
The two directions disagreed until now:
serialize_spaceis asingledispatchand reports unsupported spaces correctly, which is what
test_space_serialize_deserialize_unsupportedcovers. Nothing exercised thedeserializing direction, so this went unnoticed.
Tests
tests/test_serialization.pygainstest_space_deserialize_unsupported,parametrised over
Graph,SequenceandOneOf— three Gymnasium spaces withno deserializer registered. All three fail on
mainwith theTypeErroraboveand pass here; the file goes from 19 to 22 passing.
pre-commit runis clean on both files.tests/test_namespace.pyfails 9 caseshere both with and without this change — they reach the remote storage, and the
baseline is the same.
Type of change
Checklist
pre-commitchecks withpre-commit run --all-files