dapper91 / pydantic-xml

python xml for humans
https://pydantic-xml.readthedocs.io
The Unlicense
155 stars 16 forks source link

forward refs support added. #61

Closed dapper91 closed 1 year ago

dapper91 commented 1 year ago

fixes https://github.com/dapper91/pydantic-xml/issues/60

This fix resolves the problem with postponed type declaration:

class TestModel(BaseXmlModel, tag='model1'):
    model1: 'TestSubModel' = element()

class TestSubModel(BaseXmlModel, tag='model2'):
    attr1: str = attr()

in suck case the type of the field model1 is ForwardRef and should be resolved after the TestSubModel model declared using update_forward_refs method.

TestModel.update_forward_refs()
codecov-commenter commented 1 year ago

Codecov Report

Merging #61 (22808c9) into dev (f6580e6) will decrease coverage by 0.66%. The diff coverage is 87.17%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##              dev      #61      +/-   ##
==========================================
- Coverage   93.73%   93.08%   -0.66%     
==========================================
  Files          22       23       +1     
  Lines        1038     1085      +47     
==========================================
+ Hits          973     1010      +37     
- Misses         65       75      +10     
Flag Coverage Δ
unittests 93.08% <87.17%> (-0.66%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ydantic_xml/serializers/factories/heterogeneous.py 91.07% <66.66%> (-3.58%) :arrow_down:
pydantic_xml/serializers/factories/homogeneous.py 91.37% <66.66%> (-3.45%) :arrow_down:
pydantic_xml/serializers/factories/wrapper.py 92.68% <66.66%> (-4.76%) :arrow_down:
pydantic_xml/serializers/factories/union.py 87.80% <71.42%> (-2.79%) :arrow_down:
pydantic_xml/serializers/factories/forwardref.py 90.47% <90.47%> (ø)
pydantic_xml/model.py 100.00% <100.00%> (ø)
pydantic_xml/serializers/factories/__init__.py 100.00% <100.00%> (ø)
pydantic_xml/serializers/factories/model.py 95.28% <100.00%> (+0.13%) :arrow_up:
pydantic_xml/serializers/serializer.py 97.47% <100.00%> (+0.44%) :arrow_up: