Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(atdpy): remove outdated comments on lists with default values #346

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions atdpy/src/lib/Codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ let inst_var_declaration
match get_python_default unwrapped_e an with
| None -> ""
| Some x ->
(* This constructs ensures that a fresh default value is
evaluated for each class instanciation. It's important for
(* This construct ensures that a fresh default value is
evaluated for each class instantiation. It's important for
default lists since Python lists are mutable. *)
sprintf " = field(default_factory=lambda: %s)" x
in
Expand Down
23 changes: 1 addition & 22 deletions doc/atdpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,7 @@ expression e.g.
~answer <python default="42">: int;
}

Default values are always honored when reading JSON data from
Python. However, the implementation of ``dataclass`` via the
``@dataclass`` decorator prevents the use of mutable values for
defaults. This causes class constructors to not have default fields
that are mutable such as ``[]``. For example:

.. code-block:: ocaml

type bar = {
~items: int list;
}

will translate to a class constructor that requires one argument of
type list. For example, ``Bar([1, 2, 3])`` would be legal but
``Bar()`` would be illegal. Reading from the JSON object ``{}`` would
however succeed. Therefore, the following two Python expressions would
be valid and equivalent:

.. code-block:: python

Bar([])
Bar.from_json_string('{}')
Default values are always honored when reading JSON data from Python.


Field and constructor renaming
Expand Down