Repository navigation
tests/cpydiff: Add str return type and subclass preservation differences. - #18955
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18955 +/- ##
=======================================
Coverage 98.47% 98.47%
=======================================
Files 176 176
Lines 22845 22845
=======================================
Hits 22497 22497
Misses 348 348 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
Thanks for the contribution. I think these tests belong better in the |
Contributor
Author
|
Good point, thanks @dpgeorge! I've updated the tests to use |
jseop-lim
force-pushed
the
cpydiff-str
branch
2 times, most recently
from
April 17, 2026 00:44
afb977d to
58b9d3e
Compare
Document two str()-related CPython compatibility differences in tests/cpydiff/: - core_class_strrettype.py: __str__/__repr__ returning a non-string type does not raise TypeError. MicroPython silently converts and prints the value. Relates to micropython#18941. - core_class_subclassret.py: str() does not preserve str subclass type from __str__/__repr__ return value. MicroPython always returns a plain str instance. Relates to micropython#18942. Signed-off-by: Jeongseop Lim <[email protected]>
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.
Summary
Document two
str()-related CPython compatibility differences intests/cpydiff/:types_str_strrettype.py:__str__/__repr__returning a non-string type does not raiseTypeError. MicroPython silently converts and prints the value.Relates to
repr()does not raise TypeError when__repr__returns a non-string #18941.types_str_subclassret.py:str()does not preservestrsubclass type from__str__/__repr__return value. MicroPython always returns a plainstrinstance.Relates to
repr()does not preservestrsubclass type returned by__repr__#18942.Testing
Verified that each test produces different output between CPython and MicroPython:
types_str_strrettype.py: CPython raisesTypeError, MicroPython printsTrue.types_str_subclassret.py: CPython prints<class '__main__.MyStr'>, MicroPython prints<class 'str'>.Tested on unix port, Linux.
Generative AI
I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.