Skip to content

tests/cpydiff: Add str return type and subclass preservation differences. - #18955

Merged
dpgeorge merged 1 commit into
micropython:masterfrom
jseop-lim:cpydiff-str
May 14, 2026
Merged

dpgeorge merged 1 commit into
micropython:masterfrom
jseop-lim:cpydiff-str

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Summary

Document two str()-related CPython compatibility differences in tests/cpydiff/:

  1. types_str_strrettype.py: __str__/__repr__ returning a non-string type does not raise TypeError. MicroPython silently converts and prints the value.
    Relates to repr() does not raise TypeError when __repr__ returns a non-string #18941.

  2. types_str_subclassret.py: str() does not preserve str subclass type from __str__/__repr__ return value. MicroPython always returns a plain str instance.
    Relates to repr() does not preserve str subclass type returned by __repr__ #18942.

Testing

Verified that each test produces different output between CPython and MicroPython:

  • types_str_strrettype.py: CPython raises TypeError, MicroPython prints True.
  • 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.

@codecov

codecov Bot commented Mar 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (6574d98) to head (3ef656a).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Mar 21, 2026
@dpgeorge

Copy link
Copy Markdown
Member

Thanks for the contribution.

I think these tests belong better in the categories: Core,Classes, and their files be named with a prefix core_class_.

@jseop-lim

Copy link
Copy Markdown
Contributor Author

Good point, thanks @dpgeorge!

I've updated the tests to use categories: Core,Classes and renamed the files with the core_class_ prefix.

@jseop-lim
jseop-lim force-pushed the cpydiff-str branch 2 times, most recently from afb977d to 58b9d3e Compare April 17, 2026 00:44

@dpgeorge dpgeorge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating.

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]>
@dpgeorge
dpgeorge merged commit 3ef656a into micropython:master May 14, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Relates to tests/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants