# Instant reverse python source can't handle metaclass inheritance

**URL:** <https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078>\
**Category:** Bug Reports\
**Created:** [October 21, 2021, 12:10pm UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078 "2021-10-21T12:10:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduard\_hendriksen](https://avatars.discourse-cdn.com/v2/letter/e/2bfe46/32.png) [@eduard\_hendriksen](https://forums.visual-paradigm.com/u/eduard_hendriksen)\
**Post date:** [October 21, 2021, 12:10pm UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/1 "2021-10-21T12:10:56Z")

</div>

Hi there,

It appears the ‘Instant reverse’ → ‘python source’ function can’t handle classes that are created with the `metaclass` parameter.  
A message is shown that instant reverse has been ‘completed with errors’ and none of these classes are part of the generated model.  
Classes that inherit from these classes are also completely excluded.

I have looked into the `vp.log` file for an error message, but none is shown.

To reproduce the bug a python module containing this code can be given to the instant reverse tool;

```auto
class Test(metaclass=type):
    A = 1

class InheritedTest(Test):
    B = 2

class NoMeta:
    C = 3

```

We are actually using the [sqlalchemy package](https://sqlalche.me/) in our project and using the declarative base mapping to map our python classes to the sqlalchemy orm.  
This is done by inheriting classes that should be persisted from the sqlalchemy declarative base class.  
Since the declarative base class is a metaclass, our complete orm model is missing when using this visual paradigm feature.

It would be wonderful if this piece of code could be successfully reversed:

```auto
from sqlalchemy.orm.decl_api import registry, DeclarativeMeta

sql_alchemy_registry = registry()

class SqlAlchemyBase(metaclass=DeclarativeMeta):
    
    registry = sql_alchemy_registry
    metadata = sql_alchemy_registry.metadata
    __abstract__ = True
    __init__ = sql_alchemy_registry.constructor

```

Thank you in advance for considering this report. I look forward to your response.

---

<div class="post-metadata">

**Author:** ![Jick](https://avatars.discourse-cdn.com/v2/letter/j/ea666f/32.png) [@Jick](https://forums.visual-paradigm.com/u/Jick)\
**Post date:** [October 25, 2021, 9:49am UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/2 "2021-10-25T09:49:58Z")

</div>

Hi eduard\_hendriksen,

Thank you for your post. Your question has been forwarded to our team for further studying. When there is any news, I will share with you.

Best regards,  
Jick Yeung

---

<div class="post-metadata">

**Author:** ![Jick](https://avatars.discourse-cdn.com/v2/letter/j/ea666f/32.png) [@Jick](https://forums.visual-paradigm.com/u/Jick)\
**Post date:** [October 26, 2021, 9:54am UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/3 "2021-10-26T09:54:03Z")

</div>

Hi eduard\_hendriksen,

I am glad to inform you that the problem has been fixed. Please update to the latest patch build to obtain the fix. The steps can be found in the article below:

> **[Update Visual Paradigm to Latest Patch - Visual Paradigm Know-how](https://knowhow.visual-paradigm.com/technical-support/update-to-patch/)**
>
> Upon receiving a problem report or request of enhancement, we do our best to make the necessary changes. You will then be suggested to update your Visual Paradigm installation to the patch release, in which the fix or enhancement has been made. In...

Should you have any questions, please feel free to let me know.

Best regards,  
Jick Yeung

---

<div class="post-metadata">

**Author:** ![eduard\_hendriksen](https://avatars.discourse-cdn.com/v2/letter/e/2bfe46/32.png) [@eduard\_hendriksen](https://forums.visual-paradigm.com/u/eduard_hendriksen)\
**Post date:** [October 26, 2021, 10:05am UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/4 "2021-10-26T10:05:13Z")

</div>

Thank you very much for the quick fix and update.

---

<div class="post-metadata">

**Author:** ![eduard\_hendriksen](https://avatars.discourse-cdn.com/v2/letter/e/2bfe46/32.png) [@eduard\_hendriksen](https://forums.visual-paradigm.com/u/eduard_hendriksen)\
**Post date:** [October 26, 2021, 1:46pm UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/5 "2021-10-26T13:46:20Z")

</div>

During testing of the new update, I found that the metaclass import is currently working as intended, so thanks very much for the fix.

I did, however, stumble upon another item that prevented a class from being reversed.  
After some testing, I think the problem is the use of list comprehension during `dict` instantiation.

The smallest example I have causing this error is the following;

```auto
attributes = ["a", "b", "c"]
test_dict = {attr: index for index, attr in enumerate(attributes)}

```

The error message found in the `vp.log` is the following;  
`[message] java.lang.ClassCastException: class v.bdm.bm cannot be cast to class v.bdm.bj (v.bdm.bm and v.bdm.bj are in unnamed module of loader 'app')`

And one example showcasing the class reversal not occurring when this error occurs;

```auto
from typing import Dict, Sequence

class Test(metaclass=type):
    def attribute_dict(self, attributes: Sequence[str]) -> Dict:
        return {attr_name: getattr(self, attr_name) for attr_name in attributes}

```

Thanks in advance for looking into this!

---

<div class="post-metadata">

**Author:** ![Jick](https://avatars.discourse-cdn.com/v2/letter/j/ea666f/32.png) [@Jick](https://forums.visual-paradigm.com/u/Jick)\
**Post date:** [October 28, 2021, 8:47am UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/6 "2021-10-28T08:47:29Z")

</div>

Hi eduard\_hendriksen,

We are glad to know that the fix works. Thanks for your post. I have just asked our engineers to take a look at the new problem you described. Again, I will let you know when there is any news.

Best regards,  
Jick Yeung

---

<div class="post-metadata">

**Author:** ![Jick](https://avatars.discourse-cdn.com/v2/letter/j/ea666f/32.png) [@Jick](https://forums.visual-paradigm.com/u/Jick)\
**Post date:** [October 28, 2021, 11:00am UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/7 "2021-10-28T11:00:36Z")

</div>

Hi eduard\_hendriksen,

Problem fixed. You may update again to the latest patch build to get the fix. 🙂

Best regards,  
Jick Yeung

---

<div class="post-metadata">

**Author:** ![eduard\_hendriksen](https://avatars.discourse-cdn.com/v2/letter/e/2bfe46/32.png) [@eduard\_hendriksen](https://forums.visual-paradigm.com/u/eduard_hendriksen)\
**Post date:** [October 28, 2021, 12:43pm UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/8 "2021-10-28T12:43:49Z")

</div>

Hi Jick,

Thanks again for the quick fix!  
I will get on it right away.

Best wishes,  
Eduard

---

<div class="post-metadata">

**Author:** ![eduard\_hendriksen](https://avatars.discourse-cdn.com/v2/letter/e/2bfe46/32.png) [@eduard\_hendriksen](https://forums.visual-paradigm.com/u/eduard_hendriksen)\
**Post date:** [October 28, 2021, 12:55pm UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/9 "2021-10-28T12:55:23Z")

</div>

Hi Jick,

Unfortunately the fix doesn’t seem to have helped on my system.  
Neither of the two examples I provided are currently functioning on my end.  
Thanks again for being so responsive.

Best wishes,

Eduard

---

<div class="post-metadata">

**Author:** ![Jick](https://avatars.discourse-cdn.com/v2/letter/j/ea666f/32.png) [@Jick](https://forums.visual-paradigm.com/u/Jick)\
**Post date:** [October 29, 2021, 1:59am UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/10 "2021-10-29T01:59:54Z")

</div>

Hi Eduard,

Sorry about that. Let me check…

Best regards,  
Jick Yeung

---

<div class="post-metadata">

**Author:** ![Jick](https://avatars.discourse-cdn.com/v2/letter/j/ea666f/32.png) [@Jick](https://forums.visual-paradigm.com/u/Jick)\
**Post date:** [October 29, 2021, 4:15am UTC](https://forums.visual-paradigm.com/t/instant-reverse-python-source-cant-handle-metaclass-inheritance/17078/11 "2021-10-29T04:15:11Z")

</div>

Hi Eduard,

I found that the previous build was not properly deployed. It should be working now. Please try again.

Best regards,  
Jick Yeung
