Skip to content

py/objdict: Make OrderedDict.fromkeys return an OrderedDict. - #19645

Open
pablogventura wants to merge 1 commit into
micropython:masterfrom
pablogventura:py-ordereddict-fromkeys
Open

py/objdict: Make OrderedDict.fromkeys return an OrderedDict.#19645
pablogventura wants to merge 1 commit into
micropython:masterfrom
pablogventura:py-ordereddict-fromkeys

Conversation

@pablogventura

@pablogventura pablogventura commented Aug 23, 2026

Copy link
Copy Markdown

Summary

Fixes #12011. dict_fromkeys is a classmethod shared by dict and OrderedDict; it always allocated a plain dict. When called as OrderedDict.fromkeys, set base.type and map.is_ordered on the result (same as mp_obj_dict_make_new).

Testing

  • tests/basics/ordereddict_fromkeys.py (type, insertion order, default value, dict.fromkeys regression)
  • tests/run-tests.py basics/ordereddict_fromkeys.py basics/dict_fromkeys.py basics/dict_fromkeys2.py on unix port

Code size

Unix standard port, size text section (clean rebuild):

Version bytes vs master
master 796206 -
this commit 796206 0

Only handles OrderedDict itself (not subclasses), consistent with existing OrderedDict support in MicroPython.

Generative AI

I did not use generative AI tools when creating this PR.

Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.58%. Comparing base (1c3c201) to head (69d93e4).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19645   +/-   ##
=======================================
  Coverage   98.58%   98.58%           
=======================================
  Files         182      182           
  Lines       23322    23325    +3     
  Branches        5        5           
=======================================
+ Hits        22993    22996    +3     
  Misses        328      328           
  Partials        1        1           
Flag Coverage Δ
unix-coverage-32bit 98.59% <100.00%> (+<0.01%) ⬆️
unix-coverage-64bit 98.52% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@github-actions

Copy link
Copy Markdown

Code size report:

Reference:  extmod: Add USB Network (NCM) driver implementation. [1c3c201]
Comparison: py/objdict: Make OrderedDict.fromkeys return an OrderedDict. [merge of 69d93e4]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:   +16 +0.002% standard
      stm32:   +24 +0.006% PYBV10
      esp32:   +20 +0.001% ESP32_GENERIC
     mimxrt:   +16 +0.004% TEENSY40
        rp2:   +24 +0.002% RPI_PICO_W
       samd:   +24 +0.009% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:   +24 +0.005% VIRT_RV32

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OrderedDict.fromkeys returns an (unordered) dict

2 participants