Added new error message and test for dict[str, Any] generation#22
Merged
Added new error message and test for dict[str, Any] generation#22
Conversation
|
✅ Code coverage on 🎉 No files have reduced coverage 🎉
|
| File | Details |
|---|---|
src/assertical/__init__.py |
✅ 100% → 100% |
src/assertical/asserts/__init__.py |
✅ 100% → 100% |
src/assertical/asserts/generator.py |
✅ 100% → 100% |
src/assertical/asserts/pandas.py |
✅ 88% → 88% |
src/assertical/asserts/time.py |
✅ 95% → 95% |
src/assertical/asserts/type.py |
✅ 92% → 92% |
src/assertical/fake/__init__.py |
✅ 100% → 100% |
src/assertical/fake/asyncio.py |
✅ 100% → 100% |
src/assertical/fake/generator.py |
✅ 94% → 94% |
src/assertical/fake/http.py |
✅ 71% → 71% |
src/assertical/fixtures/__init__.py |
✅ 100% → 100% |
src/assertical/fixtures/environment.py |
✅ 100% → 100% |
src/assertical/fixtures/fastapi.py |
✅ 97% → 97% |
src/assertical/fixtures/generator.py |
✅ 100% → 100% |
src/assertical/snapshot.py |
✅ 100% → 100% |
TOTAL |
✅ 91% → 91% |
joshvote
approved these changes
May 7, 2026
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.
v0.3.3 added native dict generation, which is great, but silently breaks when the dict value type is unresolvable by assertical (e.g. Any, Path, object). Instead of a clear error, generation crashes deep in the stack:
Exception: Type None does not inherit from one of dict_keys([...])
This is because enumerate_class_properties sets second_type_to_generate = None when the value type can't be resolved, but generate_class_instance then passes None to generate_member, which calls generate_class_instance(None, ...) causing the crash.
This was already handled cleanly by keys:
if member.type_to_generate is None:
if not (optional_is_none and member.is_optional):
raise Exception(f"...cannot be generated")
Now added the error message to values to make it a little easier to trace.
The reason why I think this is useful is from a cryptic issue I found after this upgrade in another repo. When generating a dict[str, Any] prior to assertical v0.3.3, the assertical_extensions fixture registered register_value_generator(dict, lambda _: {}), which intercepted any dict field and returned {} before assertical inspected the type arguments. This masked the fact that Any is not a type assertical can generate. Now these are no longer intercepted and fail with the error described above. This new message would have made things easier!