Add __bool__ for MetaType#102
Merged
jhonabreul merged 3 commits intoQuantConnect:masterfrom May 2, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds an implementation for bool on the MetaType so that truthiness for types is evaluated using nb_bool rather than len.
- Added nb_bool implementation in MetaType.cs that always returns 1.
- Updated native type offsets (TypeOffset.cs and ITypeOffsets.cs) to include nb_bool.
- Introduced embed_tests to verify that types are truthy in Python.
Reviewed Changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/runtime/Types/MetaType.cs | Added nb_bool method that returns 1 for truthiness. |
| src/runtime/Properties/AssemblyInfo.cs | Updated assembly version to 2.0.44. |
| src/runtime/Native/TypeOffset.cs | Added nb_bool offset property. |
| src/runtime/Native/ITypeOffsets.cs | Added nb_bool property in the interface. |
| src/embed_tests/ClassManagerTests.cs | Added tests to verify that types are always truthy. |
Files not reviewed (2)
- src/perf_tests/Python.PerformanceTests.csproj: Language not supported
- src/runtime/Python.Runtime.csproj: Language not supported
Martin-Molinero
approved these changes
May 1, 2025
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.
Add
__bool__for MetaType.This is required so that truthiness for Type is checked using this slot instead of
__len__