question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Backport python 3.7 dataclass

See original GitHub issue

A new dataclass decorator was recently accepted into python 3.7 (https://www.python.org/dev/peps/pep-0557/).

The implementation seems similar to coconut’s implementation of the data type (subclassing the namedtuple) but they differ in terms of their syntax. I was just wondering whether coconut would keep the current syntax (for backward compatibility) or would it be changing to the new syntax (to avoid feature duplication). I just asked this question because I’m curious.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Hong-Xiangcommented, Feb 28, 2019

For older versions of Python, we can get same functionality of dataclasses via attrs, as this says, it support PyPi, Python 2.7, 3.4+.

It supports

import attr

@attr.s(auto_attribs=True)
class vector20:
    x: int
    y: int

@attr.s(auto_attribs=True)
class vector21:
    x: int
    y: int


print(vector20(0, 1) == vector20(0, 1)) # return True
print(vector20(0, 1) == vector21(0, 1)) # return False

and lots of other features.

I’m wondering if it is allowed to add this package as dependency of coconut?

If it is allowed, I’m wondering how to learn about the compiling process of data. I’ve found data_handle in L1202 of compiler/compiler.py, and it seems that for basic data support, only block after L1331 elif saw_defaults: should be modified, but there I’m confused of matching simple, docstring, e.t.c in stmts. How to learn this block of code? I can’t add break point to compiler, and adding print statement seems not work.

On the other hand, May data support annotations from [PEP 526]? Thus like

data vector2:
    x: int = 0
    y: int = 0
1reaction
benji-yorkcommented, Dec 8, 2017

The dataclass decorator accepts a “freeze” argument which makes the instances read-only (well, as read-only as anything gets in Python).

On Fri, Dec 8, 2017 at 3:27 PM, Dileep Kishore notifications@github.com wrote:

@evhub https://github.com/evhub you’re right. I assumed they inherited from namedtuples but it looks like they just create normal classes.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/evhub/coconut/issues/376#issuecomment-350376198, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAkrw92l2B-HryokOOuaZNCODXzhnbfks5s-amkgaJpZM4Q7lbY .

– Benji York

Read more comments on GitHub >

github_iconTop Results From Across the Web

dataclasses - PyPI
This is an implementation of PEP 557, Data Classes. It is a backport for Python 3.6. Because dataclasses will be included in Python...
Read more >
Data Classes in Python 3.7+ (Guide)
If you do not yet have Python 3.7, there is also a data classes backport for Python 3.6. And now, go forth and...
Read more >
Backport slots=True and kw_only=True from Python 3.10 #166
The problem is that "import dataclasses" in 3.7 will use the stdlib version of dataclasses, which does not have kw_only. This could be...
Read more >
dataclasses — Data Classes — Python 3.11.1 documentation
Source code: Lib/dataclasses.py This module provides a decorator and functions for automatically adding generated special method s ... New in version 3.7.
Read more >
How to use Python dataclasses - InfoWorld
Dataclasses, introduced in Python 3.7 (and backported to Python 3.6), provide a handy way to make classes less verbose. Many of the common ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found