gahjelle / datadict Goto Github PK
View Code? Open in Web Editor NEWTreat dataclasses like dictionaries
License: MIT License
Treat dataclasses like dictionaries
License: MIT License
I needed a dict-like dataclass and was going to implement it myself, but I did some Googling and found that your implementation does the trick. Thanks!
One minor issue I found is that your "dataclass-like" decorator isn't understood by type checkers like mypy
and pyright
as of now. This is a known limitation of user-defined dataclass-like functions, described and fixed in PEP 681. The error given by pyright
is "Untyped class decorator obscures type of class; ignoring decorator"
.
If you're up for it, I can submit a Pull Request implementing this change. I recommend the "simple fix" below, which adds a dependency to typing_extensions
(which itself requires Python 3.7 at minimum). But there's also a fix that doesn't add any dependencies, though it will bump your minimum supported Python to 3.8.
The fix will be available in the standard library in 3.11, but is available today through typing_extensions
. Your package could be updated to support PEP 681 by adding the typing_extensions
dependency and declaring the import:
from typing_extensions import dataclass_transform
And changing this:
datadict/datadict/dataclass.py
Lines 6 to 7 in 4e9fb67
to this:
@dataclass_transform()
def dataclass(cls=None, **kwargs):
Since 3.11 will have dataclass_transform
built in, typing_extensions
conditionally chooses its own implementation for pre 3.11, and imports the built-in for 3.11 onward.
See the "Enforcing dataclasses" section of this StackOverflow answer.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.