Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nillable element support added. #146

Merged
merged 1 commit into from Dec 6, 2023
Merged

nillable element support added. #146

merged 1 commit into from Dec 6, 2023

Conversation

dapper91
Copy link
Owner

@dapper91 dapper91 commented Dec 3, 2023

Adds nillable elements support. See https://www.w3.org/TR/xmlschema-1/#xsi_nil.

Code example:

>>> from typing import Optional
>>> from pydantic_xml import BaseXmlModel, element
>>> 
>>> class Company(BaseXmlModel):
...     title: Optional[str] = element(default=None, nillable=True)
... 
>>> company = Company()
>>> print(company.to_xml(pretty_print=True).decode())
<Company>
  <title xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"></title>
</Company>

>>> company = Company(title='SpaceX')
>>> print(company.to_xml(pretty_print=True).decode())
<Company>
  <title>SpaceX</title>
</Company>

Fixes #145 issue.

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7f26d33) 91.79% compared to head (af59b91) 91.98%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #146      +/-   ##
==========================================
+ Coverage   91.79%   91.98%   +0.18%     
==========================================
  Files          25       26       +1     
  Lines        1378     1410      +32     
==========================================
+ Hits         1265     1297      +32     
  Misses        113      113              
Flag Coverage Δ
unittests 91.98% <100.00%> (+0.18%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dapper91 dapper91 force-pushed the nillable-element-feat branch 2 times, most recently from 1b0a6d1 to af59b91 Compare December 4, 2023 19:11
@dapper91 dapper91 merged commit 2db95c3 into dev Dec 6, 2023
7 checks passed
@dapper91 dapper91 mentioned this pull request Dec 6, 2023
Merged
@dapper91 dapper91 deleted the nillable-element-feat branch December 7, 2023 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants