WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a883719

Browse files
generatedunixname647790274085263facebook-github-bot
authored andcommitted
[codemod][py3.12] Convert dataclasses mutable default values to use default_factory
Summary: As of [Python 3.11](https://docs.python.org/3.11/whatsnew/3.11.html#dataclasses), dataclasses now only allow defaults that are hashable. Using mutable (non-hashable) default values under Python 3.11+ will cause a runtime error: ``` ValueError: mutable default <class 'problematic.ClassName'> for field <field> is not allowed: use default_factory ``` This codemod attempts to automatically convert mutable defaults to use `default_factory` NOTE: The change is not semantically equivalent to before the change. Before, all dataclass instances with a mutable default value were sharing the same instance. This change results each dataclass instance using a new instance of the mutable value. It is likely that the before state was a latent bug, but it's still a behavior change! Reviewed By: itamaro Differential Revision: D72541748 fbshipit-source-id: 32a57309ed267f52813d54bb647e4ca5f9c67c58
1 parent 42f1c6f commit a883719

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mmf/models/mmf_transformer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class Config(BaseTransformer.Config):
5454
freeze_image_encoder: bool = False
5555
tie_weight_to_encoder: Optional[str] = None
5656
finetune_lr_multiplier: float = 1
57-
backend: BaseTransformerBackendConfig = MMFTransformerBackendConfig(
58-
type="huggingface"
57+
backend: BaseTransformerBackendConfig = field(
58+
default_factory=lambda: MMFTransformerBackendConfig(type="huggingface")
5959
)
6060
modalities: List[BaseTransformerModalityConfig] = field(
6161
default_factory=lambda: [

0 commit comments

Comments
 (0)