Skip to content

minor: add __all__ to strategy __init__#39

Merged
toumorokoshi merged 2 commits intotoumorokoshi:masterfrom
szepesisz:master
Sep 25, 2025
Merged

minor: add __all__ to strategy __init__#39
toumorokoshi merged 2 commits intotoumorokoshi:masterfrom
szepesisz:master

Conversation

@szepesisz
Copy link
Copy Markdown
Contributor

@szepesisz szepesisz commented Sep 24, 2025

Thank you for your work @toumorokoshi!

Just a little idea I had:
Instead of the recommended "magic-value-esque" way:

from deepmerge.merger import Merger

merger = Merger(
    type_strategies=[(list, 'override'), (dict, 'merge'), (set, 'union')],
    fallback_strategies=['override'],
    type_conflict_strategies=['override']
)

I would prefer explicitly referencing the merging functions:

from deepmerge.merger import Merger
from deepmerge.strategy import (
    ListStrategies,
    DictStrategies,
    SetStrategies,
    FallbackStrategies,
    TypeConflictStrategies
)

merger = Merger(
    type_strategies=[
        (list, ListStrategies.strategy_override), 
        (dict, DictStrategies.strategy_merge), 
        (set, SetStrategies.strategy_union)
    ],
    fallback_strategies=[
        FallbackStrategies.strategy_override
    ],
    type_conflict_strategies=[
        TypeConflictStrategies.strategy_override
    ]
)

This exact code does run currently, although the type checkers report errors:

"ListStrategies" is not exported from module "deepmerge.strategy"
     Import from "deepmerge.strategy.list" instead [reportPrivateImportUsage]

The suggested form would require a whole bunch of import lines.

Same applies to the merger.py source code:

"ListStrategies" is not exported from module "..strategy" [reportPrivateImportUsage]

Listing the classes in the __all__ variable solves this.

@toumorokoshi toumorokoshi merged commit db7c653 into toumorokoshi:master Sep 25, 2025
5 checks passed
@toumorokoshi
Copy link
Copy Markdown
Owner

Great, thank you! Yes, makes a lot of sense, and the explicit approach does seem better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants