Skip to content

Commit 5a2fffb

Browse files
[PY313] Preserve inference of dataclasses.replace()
1 parent 66c87bb commit 5a2fffb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

astroid/brain/brain_dataclasses.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from astroid import bases, context, nodes
2121
from astroid.builder import parse
22-
from astroid.const import PY310_PLUS
22+
from astroid.const import PY310_PLUS, PY313_PLUS
2323
from astroid.exceptions import AstroidSyntaxError, InferenceError, UseInferenceDefault
2424
from astroid.inference_tip import inference_tip
2525
from astroid.manager import AstroidManager
@@ -503,6 +503,14 @@ def _looks_like_dataclass_field_call(
503503
return inferred.name == FIELD_NAME and inferred.root().name in DATACLASS_MODULES
504504

505505

506+
def _looks_like_dataclasses(mod: nodes.Module):
507+
return mod.qname() == "dataclasses"
508+
509+
510+
def _resolve_private_replace_to_public(node):
511+
node.locals["replace"] = node.locals["_replace"]
512+
513+
506514
def _get_field_default(field_call: nodes.Call) -> _FieldDefaultReturn:
507515
"""Return a the default value of a field call, and the corresponding keyword
508516
argument name.
@@ -608,6 +616,13 @@ def _infer_instance_from_annotation(
608616

609617

610618
def register(manager: AstroidManager) -> None:
619+
if PY313_PLUS:
620+
manager.register_transform(
621+
nodes.Module,
622+
_resolve_private_replace_to_public,
623+
_looks_like_dataclasses,
624+
)
625+
611626
manager.register_transform(
612627
nodes.ClassDef, dataclass_transform, is_decorated_with_dataclass
613628
)

0 commit comments

Comments
 (0)