Skip to content

Commit

Permalink
Merge pull request #187 from dapper91/dev
Browse files Browse the repository at this point in the history
- mypy plugin dataclass_transform decorated model bug fixed. See #152 (comment).
  • Loading branch information
dapper91 authored Apr 18, 2024
2 parents 188d61a + 3e7b493 commit d92402e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

2.9.2 (2024-04-19)
------------------

- mypy plugin dataclass_transform decorated model bug fixed. See https://github.com/dapper91/pydantic-xml/issues/152#issuecomment-2057949479.


2.9.1 (2024-04-12)
------------------

Expand Down
6 changes: 6 additions & 0 deletions pydantic_xml/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from mypy.plugin import ClassDefContext, FunctionContext, Plugin, Type
from pydantic.mypy import PydanticModelTransformer, PydanticPlugin

MODEL_METACLASS_FULLNAME = 'pydantic_xml.model.XmlModelMeta'
ATTR_FULLNAME = 'pydantic_xml.model.attr'
ELEMENT_FULLNAME = 'pydantic_xml.model.element'
WRAPPED_FULLNAME = 'pydantic_xml.model.wrapped'
Expand All @@ -15,6 +16,11 @@ def plugin(version: str) -> type[Plugin]:


class PydanticXmlPlugin(PydanticPlugin):
def get_metaclass_hook(self, fullname: str) -> Optional[Callable[[ClassDefContext], None]]:
if fullname == MODEL_METACLASS_FULLNAME:
return self._pydantic_model_metaclass_marker_callback
return super().get_metaclass_hook(fullname)

def get_function_hook(self, fullname: str) -> Optional[Callable[[FunctionContext], Type]]:
sym = self.lookup_fully_qualified(fullname)
if sym and sym.fullname == ATTR_FULLNAME:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pydantic-xml"
version = "2.9.1"
version = "2.9.2"
description = "pydantic xml extension"
authors = ["Dmitry Pershin <[email protected]>"]
license = "Unlicense"
Expand Down

0 comments on commit d92402e

Please sign in to comment.