Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping to and from a class with a custom metaclass is not allowed #19

Open
toro2k opened this issue Aug 28, 2019 · 1 comment
Open

Comments

@toro2k
Copy link

toro2k commented Aug 28, 2019

The following the case fails:

from unittest import TestCase
from mapper.object_mapper import ObjectMapper

class MyMetaClass(type):
    pass

class MyFromClass(metaclass=MyMetaClass):
    pass

class MyToClass:
    pass

class Test(TestCase):
    def test_mapping_class_with_custom_metaclass(self):
        mapper = ObjectMapper()
        mapper.create_map(MyFromClass, MyToClass)

This behavior prevents to map to and from classes with a custom metaclass (i.e. Django models).
Is it intended or the check in ObjectMapper.create_map is just too strict?

@AlirezaRoshanzamir
Copy link

A more specific example is the use of classes inherited from an abstract class.

from abc import ABC, abstractmethod

from mapper.object_mapper import ObjectMapper


class Interface(ABC):
    @abstractmethod
    def foo(self):
        pass


class FirstImplementation(Interface):
    def __init__(self):
        self.member = 1

    def foo(self):
        print('foo')


class SecondImplementation(Interface):
    def __init__(self):
        self.member = 1

    def foo(self):
        print('foo')


mapper = ObjectMapper()
mapper.create_map(FirstImplementation, SecondImplementation)

The above code raises:
mapper.object_mapper_exception.ObjectMapperException: type_from must be a type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants