Skip to content

Metaclass conflict when combine class with a custom metaclass and str class #14818

Closed
@kabell

Description

@kabell

Bug Report

Mypy returns

error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

when I combine a class with a custom metaclass and a str class

To Reproduce

This works

class M1(type): pass
class A1(metaclass=M1): pass

class CorrectMeta(M1, type): pass
class B2(A1, int, metaclass=CorrectMeta): pass  

but this not - I only replaced int with str

class M1(type): pass
class A1(metaclass=M1): pass

class CorrectMeta(M1, type): pass
class B2(A1, str, metaclass=CorrectMeta): pass 

Expected Behavior

There is no error

Actual Behavior

Mypy returned an error

Your Environment

  • Mypy version used: >=0.991
  • Mypy command-line flags: mypy -p mypackage
  • Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
files = "**/**.py"
plugins = [
    "pydantic.mypy"
]

ignore_missing_imports = false
scripts_are_modules = false
namespace_packages = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
no_implicit_optional = true
show_error_context = true
show_traceback = true
strict_equality = true
check_untyped_defs = true

[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true

[[tool.mypy.overrides]]
module = [
    "tests.*"
]
disallow_untyped_defs = false
disallow_incomplete_defs = false

[[tool.mypy.overrides]]
module = [
    "request_session.*",
    "sentry_sdk.*",
    "structlog.*",
]
ignore_missing_imports = true
ignore_errors = true
  • Python version used:
    3.9, 3.10, 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions