Skip to content

Commit

Permalink
Workaround misleading metaclass conflict mypy errors
Browse files Browse the repository at this point in the history
Fix hundreds of errors reported by mypy since 0.990, e.g.:

```
lib/galaxy/model/__init__.py:9626: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
    class CleanupEventLibraryAssociation(Base):
    ^
```

It should be possible to revert this workaround once
python/mypy#14182 is fixed.
  • Loading branch information
nsoranzo committed Nov 26, 2022
1 parent 13642bc commit 7e11578
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
relationship,
)
from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.orm.decl_api import DeclarativeMeta
from sqlalchemy.sql import exists
from typing_extensions import Protocol

Expand Down Expand Up @@ -176,6 +175,12 @@


if TYPE_CHECKING:
# Workaround for https://github.com/python/mypy/issues/14182
from sqlalchemy.orm.decl_api import DeclarativeMeta as _DeclarativeMeta

class DeclarativeMeta(_DeclarativeMeta, type):
pass

from galaxy.datatypes.data import Data
from galaxy.tools import DefaultToolState
from galaxy.workflow.modules import WorkflowModule
Expand All @@ -185,6 +190,8 @@ class _HasTable:
__table__: Table

else:
from sqlalchemy.orm.decl_api import DeclarativeMeta

_HasTable = object


Expand Down
8 changes: 7 additions & 1 deletion lib/galaxy/model/tool_shed_install/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
registry,
relationship,
)
from sqlalchemy.orm.decl_api import DeclarativeMeta

from galaxy.model.custom_types import (
MutableJSONType,
Expand All @@ -40,11 +39,18 @@
mapper_registry = registry()

if TYPE_CHECKING:
# Workaround for https://github.com/python/mypy/issues/14182
from sqlalchemy.orm.decl_api import DeclarativeMeta as _DeclarativeMeta

class DeclarativeMeta(_DeclarativeMeta, type):
pass

class _HasTable:
table: Table

else:
from sqlalchemy.orm.decl_api import DeclarativeMeta

_HasTable = object


Expand Down
8 changes: 7 additions & 1 deletion lib/tool_shed/webapp/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
registry,
relationship,
)
from sqlalchemy.orm.decl_api import DeclarativeMeta

import tool_shed.repository_types.util as rt_util
from galaxy import util
Expand All @@ -60,11 +59,18 @@
WEAK_HG_REPO_CACHE: Mapping["Repository", Any] = weakref.WeakKeyDictionary()

if TYPE_CHECKING:
# Workaround for https://github.com/python/mypy/issues/14182
from sqlalchemy.orm.decl_api import DeclarativeMeta as _DeclarativeMeta

class DeclarativeMeta(_DeclarativeMeta, type):
pass

class _HasTable:
table: Table

else:
from sqlalchemy.orm.decl_api import DeclarativeMeta

_HasTable = object


Expand Down

0 comments on commit 7e11578

Please sign in to comment.