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.

Python 3.7 dataclasses

See original GitHub issue

I don’t know if this is supposed to work. Would be nice. I can try to fix it if you propose the way.

@dataclasses.dataclass
class C(pydantic.BaseModel):
     i:int
c = C(1)
....
RecursionError: maximum recursion depth exceeded

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
samuelcolvincommented, Jul 12, 2018

Proposal:

pydantic adds a decorator to validate dataclasses input data and equivalently it’s own version of dataclass which performs the same as normal dataclasses except for validating input data.

Something like:

from dataclasses import dataclasee
import pydantic

@pydantic.dataclasses.validate
@dataclass
class InventoryItem:
    name: str
    unit_price: float
    quantity_on_hand: int = 0

# which would be exactly the same as:

@pydantic.dataclasses.dataclass
class InventoryItem:
    name: str
    unit_price: float
    quantity_on_hand: int = 0

@Gaunt @pawelswiecki, if this was achievable, would be work for you?

This would require a significant rewrite of pydantic, but I think it would be worth it to support a big new language feature.

5reactions
pauleverittcommented, Jul 16, 2018

I disagree on the point about data classes: I don’t think it will get rich serialization and validation in the core. The standard library is very conservative.

—Paul

On Jul 15, 2018, at 7:23 PM, Majid alDosari notifications@github.com wrote:

the delta b/w dataclasses and pydantic are: serialization/deserialization, auto schema, and validation. i love pedantic but it seems like it’s only a matter of time before dataclasses gets such features. if not, then ya the decorator idea would keep pedantic relevant.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/samuelcolvin/pydantic/issues/178#issuecomment-405126033, or mute the thread https://github.com/notifications/unsubscribe-auth/AAbx5m68gTyvsPKMvxrbrY36HktEim7Wks5uG87VgaJpZM4UBBf7.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dataclasses — Data Classes — Python 3.11.1 documentation
The dataclass() decorator examines the class to find field s. A field is defined as a class variable that has a type annotation....
Read more >
Data Classes in Python 3.7+ (Guide)
Data classes are one of the new features of Python 3.7. With data classes you do not have to write boilerplate code to...
Read more >
The Ultimate Guide to Data Classes in Python 3.7
Data Class is a new concept introduced in Python 3.7 version. You can use data classes not only as a knowledge container but...
Read more >
dataclasses — Data Classes — Stackless-Python 3.7.9 ...
This function is a decorator that is used to add generated special methods to classes, as described below. The dataclass() decorator examines ...
Read more >
Python Dataclasses - Python Cheatsheet
Dataclasses are python classes, but are suited for storing data objects. This module provides a decorator and functions for automatically adding generated ...
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