From a4747b54c0b95d4be00e1e8752e54c8ca5d8dc68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 1 Oct 2019 21:19:08 +0200 Subject: [PATCH] Dataclass --- README.md | 6 ++++-- index.html | 6 ++++-- parse.js | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 27cb41e..e64d102 100644 --- a/README.md +++ b/README.md @@ -1037,14 +1037,16 @@ class : : = : list/dict/set = field(default_factory=list/dict/set) ``` -* **Objects can be made sortable with `'order=True'` or immutable and hashable with `'frozen=True'`.** +* **Objects can be made sortable with `'order=True'` and/or immutable and hashable with `'frozen=True'`.** * **Function field() is needed because `': list = []'` would make a list that is shared among all instances.** * **Default_factory can be any [callable](#callable).** #### Inline: ```python from dataclasses import make_dataclass - = make_dataclass('', ) + = make_dataclass('', ) + = make_dataclass('', ) + = ('', [, ]) ``` ### Slots diff --git a/index.html b/index.html index 5242c05..df73983 100644 --- a/index.html +++ b/index.html @@ -990,12 +990,14 @@ Z = dataclasses.make_dataclass('Z', [ -
  • Objects can be made sortable with 'order=True' or immutable and hashable with 'frozen=True'.
  • +
  • Objects can be made sortable with 'order=True' and/or immutable and hashable with 'frozen=True'.
  • Function field() is needed because '<attr_name>: list = []' would make a list that is shared among all instances.
  • Default_factory can be any callable.
  • Inline:

    from dataclasses import make_dataclass
    -<class> = make_dataclass('<class_name>', <list_of_attribute_names>)
    +<class> = make_dataclass('<class_name>', <coll_of_attribute_names>) +<class> = make_dataclass('<class_name>', <coll_of_tuples>) +<tuple> = ('<attr_name>', <type> [, <default_val>])

    Slots

    Mechanism that restricts objects to attributes listed in 'slots' and significantly reduces their memory footprint.

    class MyClassWithSlots:
         __slots__ = ['a']
    diff --git a/parse.js b/parse.js
    index 667ac23..ccd257f 100755
    --- a/parse.js
    +++ b/parse.js
    @@ -223,7 +223,9 @@ const TYPE =
     
     const DATACLASS = 
       'from dataclasses import make_dataclass\n' +
    -  '<class> = make_dataclass(\'<class_name>\', <list_of_attribute_names>)';
    +  '<class> = make_dataclass(\'<class_name>\', <coll_of_attribute_names>)\n' +
    +  '<class> = make_dataclass(\'<class_name>\', <coll_of_tuples>)\n' +
    +  '<tuple> = (\'<attr_name>\', <type> [, <default_val>])';
     
     
     function main() {
    @@ -328,7 +330,7 @@ function fixHighlights() {
       $(`code:contains(ValueError: malformed node)`).html(EVAL);
       $(`code:contains(@lru_cache(maxsize=None))`).html(LRU_CACHE);
       $(`code:contains(, , )`).html(TYPE);
    -  $(`code:contains()`).html(DATACLASS);
    +  $(`code:contains(make_dataclass(\'\')`).html(DATACLASS);
     }
     
     function preventPageBreaks() {