Skip to content

Commit 4a4f9cf

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

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

astroid/brain/brain_dataclasses.py

Lines changed: 17 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,15 @@ 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(node: nodes.Module) -> bool:
507+
return node.qname() == "dataclasses"
508+
509+
510+
def _resolve_private_replace_to_public(node: nodes.Module) -> None:
511+
if "_replace" in node.locals:
512+
node.locals["replace"] = node.locals["_replace"]
513+
514+
506515
def _get_field_default(field_call: nodes.Call) -> _FieldDefaultReturn:
507516
"""Return a the default value of a field call, and the corresponding keyword
508517
argument name.
@@ -608,6 +617,13 @@ def _infer_instance_from_annotation(
608617

609618

610619
def register(manager: AstroidManager) -> None:
620+
if PY313_PLUS:
621+
manager.register_transform(
622+
nodes.Module,
623+
_resolve_private_replace_to_public,
624+
_looks_like_dataclasses,
625+
)
626+
611627
manager.register_transform(
612628
nodes.ClassDef, dataclass_transform, is_decorated_with_dataclass
613629
)

0 commit comments

Comments
 (0)