Comments (1)
Hmm, this is a problem caused by both typing and dataclassy using metaclasses to do their magic. The TypeError
is a little cryptic, but what Python means is that both the metaclasses must be in the same inheritance chain, which obviously they are not.
>>> from typing import Mapping
>>> type(Mapping)
<class 'typing._SpecialGenericAlias'>) # recall that the type of a data class is DataClassMeta
typing.Generic
is just a regular class, so works, which is nice because generic data classes can be useful.
There are other examples of metaclasses in the standard library that would cause the same issue. For example, if you tried to create an abstract dataclass with collections.ABC
:
from abc import ABC
from dataclassy import dataclass
@dataclass
class AbstractDataClass(ABC):
pass
you would get the same error, because ABC
has the metaclass ABCMeta
.
Sadly, this is not easily solvable. In theory, you can merge the metaclasses by inheriting them to create a new metaclass, and then use the meta
option to tell dataclassy to use that. But this is often difficult, as it seems to be here (though I tried only very briefly). If you absolutely need to subclass Mapping
here, you can't use a dataclassy data class, sorry.
from dataclassy.
Related Issues (20)
- __dataclass_fields__ is missing HOT 3
- TypeError: argument of type 'NoneType' is not iterable HOT 3
- Add Python 3.10 to CI HOT 2
- Tests: make signature checks version-agnostic HOT 1
- __post_init__ and repeated decorator produces max recursion depth HOT 2
- Removing support for post-initialisation logic in `__init__`
- Question - How does this play with dacite? HOT 2
- Inheriting from a dataclass using ABCMeta causes `AttributeError` HOT 21
- Python 3.10 pattern matching HOT 6
- Circular references to dataclasses cause infinite recursion in __repr__ HOT 3
- Multi-level inheritance causes __get__ to fail on properties HOT 3
- Derived classes with @dataclass(slots=True) generate empty __slots__ HOT 2
- Bug when mixing metaclasses w/ `dataclassy` (Python 3.6 only) HOT 7
- Internals are not considered in __eq__ HOT 10
- No "post-init only" marker HOT 1
- New mypy error with 0.11.0: Cannot instantiate type "Type[<nothing>]" HOT 2
- Error with dataclass with InitVar variable HOT 1
- Short-cut for the factory function (Feature request) HOT 2
- Late-init fields still appear in `__init__` HOT 1
- Add `internals` parameter to `as_dict`/`as_tuple` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataclassy.