Skip to content

Commit e7f345a

Browse files
authored
Merge pull request #163 from dapper91/dev
- mypy plugin added. See https://pydantic-xml.readthedocs.io/en/latest/pages/misc.html#mypy. - optional raw element bug fixed. See #158.
2 parents bc9c724 + ee40d03 commit e7f345a

File tree

23 files changed

+327
-77
lines changed

23 files changed

+327
-77
lines changed

.coveragerc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
omit =
3+
pydantic_xml/mypy.py

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
2.8.0 (2024-01-13)
5+
------------------
6+
7+
- mypy plugin added. See https://pydantic-xml.readthedocs.io/en/latest/pages/misc.html#mypy.
8+
- optional raw element bug fixed. See https://github.com/dapper91/pydantic-xml/issues/158.
9+
10+
411
2.7.0 (2023-12-18)
512
------------------
613

docs/source/pages/contribute.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Initialize the development environment installing dev dependencies:
1414
Code style
1515
__________
1616

17-
After any code changes make sure that code style is followed.
17+
After any code changes made make sure that the code style is followed.
1818
To control that automatically install pre-commit hooks:
1919

2020
.. code-block:: console
2121
2222
$ pre-commit install
2323
24-
It will be checking your changes for coding conventions used in the project before any commit.
24+
They will be checking your changes for the coding conventions used in the project before any commit.
2525

2626

2727
Pull Requests
@@ -40,7 +40,7 @@ To make a PR to version 1 checkout branch ``v1`` and create a new branch impleme
4040
Version 2
4141
*********
4242

43-
To contribute to version 2 checkout branch ``dev``, create a feature branch and make pull request setting
43+
To contribute to version 2 checkout branch ``dev``, create a feature branch and make a pull request setting
4444
``dev`` as a target.
4545

4646

docs/source/pages/data-binding/aliases.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ________________
66
Aliased fields
77
**************
88

9-
``pydantic`` library allows to set an alias for a field that is used during serialization/deserialization
10-
instead of field name. ``pydantic-xml`` respects field aliases too:
9+
``pydantic`` library allows to set the alias for a field that is used during serialization/deserialization
10+
instead of the field name. ``pydantic-xml`` respects field aliases too:
1111

1212
.. grid:: 2
1313
:gutter: 2
@@ -44,8 +44,8 @@ Template models
4444
***************
4545

4646
``pydantic`` aliases make it possible to declare so-called template models.
47-
The base model implements all data-validation and data-processing logic and
48-
fields mapping is described in the inherited classes:
47+
The base model implements the data-validation and data-processing logic but
48+
the fields mapping is described in the inherited classes:
4949

5050
.. grid:: 2
5151
:gutter: 2

docs/source/pages/data-binding/attributes.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ __________
77
Primitive types
88
***************
99

10-
Field of a primitive type marked as :py:func:`pydantic_xml.attr` is bound to a local element attribute.
10+
A field of a primitive type marked as :py:func:`pydantic_xml.attr` is bound to a local element attribute.
1111
Parameter ``name`` is used to declare the attribute name from which the data is extracted.
12-
If it is omitted field name is used (respecting ``pydantic`` field aliases).
12+
If it is omitted the field name is used (respecting ``pydantic`` field aliases).
1313

1414
.. grid:: 2
1515
:gutter: 2
@@ -45,8 +45,8 @@ If it is omitted field name is used (respecting ``pydantic`` field aliases).
4545
Namespaces
4646
**********
4747

48-
Namespace can be defined for attributes. To bind a model field to a namespaced attribute
49-
pass parameter ``ns`` to a :py:func:`pydantic_xml.attr` and define namespace map for the model.
48+
The namespace can be defined for attributes as well. To bind a model field to a namespaced attribute
49+
pass parameter ``ns`` to a :py:func:`pydantic_xml.attr` and define a namespace map for the model.
5050

5151
.. grid:: 2
5252
:gutter: 2
@@ -82,9 +82,9 @@ pass parameter ``ns`` to a :py:func:`pydantic_xml.attr` and define namespace map
8282
Namespace inheritance
8383
*********************
8484

85-
Attribute namespace can be inherited from the model.
86-
To make attributes inherit the model namespace define model-level namespace and namespace map
87-
and set parameter ``ns_attrs``.
85+
The attribute namespace can be inherited from the model.
86+
To make attributes inherit the model namespace define the model-level namespace and namespace map
87+
and set ``ns_attrs`` flag.
8888

8989
.. grid:: 2
9090
:gutter: 2

docs/source/pages/data-binding/elements.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ ________
77
Primitive types
88
***************
99

10-
Field of a primitive type marked as :py:func:`pydantic_xml.element` is bound to a sub-element text.
11-
Parameter ``tag`` is used to declare a sub-element tag from which the text is extracted.
12-
If it is omitted field name is used (respecting ``pydantic`` field aliases).
10+
A field of a primitive type marked as :py:func:`pydantic_xml.element` is bound to the sub-element text.
11+
Parameter ``tag`` is used to declare the sub-element tag to which the field is bound.
12+
If it is omitted the field name is used (respecting ``pydantic`` field aliases).
1313

1414
.. grid:: 2
1515
:gutter: 2
@@ -45,12 +45,12 @@ If it is omitted field name is used (respecting ``pydantic`` field aliases).
4545
Model types
4646
***********
4747

48-
Field of a model type marked as :py:func:`pydantic_xml.element` is bound to a sub-element.
49-
Then the sub-element is used as a root for that sub-model. For more information
48+
A field of a model type marked as :py:func:`pydantic_xml.element` is bound to a sub-element.
49+
Then the sub-element is used as the root for that sub-model. For more information
5050
see :ref:`model data binding <pages/data-binding/models:model>`.
5151
Parameter ``tag`` is used to declare a sub-element tag to which the sub-model is bound.
5252
If it is omitted the sub-model ``tag`` setting is used.
53-
If it is omitted too field name is used (respecting ``pydantic`` field aliases).
53+
If it is omitted too the field name is used (respecting ``pydantic`` field aliases).
5454
So the order is the following: element tag, model tag, field alias, field name.
5555

5656
.. grid:: 2
@@ -87,7 +87,7 @@ So the order is the following: element tag, model tag, field alias, field name.
8787
Namespaces
8888
**********
8989

90-
You can declare an element namespace passing parameters ``ns`` and ``nsmap`` to :py:func:`pydantic_xml.element`
90+
You can declare the element namespace passing parameters ``ns`` and ``nsmap`` to :py:func:`pydantic_xml.element`
9191
where ``ns`` is the element namespace alias and ``nsmap`` is a namespace mapping:
9292

9393
.. grid:: 2
@@ -120,7 +120,7 @@ where ``ns`` is the element namespace alias and ``nsmap`` is a namespace mapping
120120
:start-after: json-start
121121
:end-before: json-end
122122

123-
Namespace and namespace mapping can be declared for a model. In that case all fields
123+
The namespace and namespace mapping can be declared for a model. In that case all fields
124124
:ref:`except attributes <pages/data-binding/attributes:namespace inheritance>` inherit them:
125125

126126
.. grid:: 2
@@ -154,8 +154,8 @@ Namespace and namespace mapping can be declared for a model. In that case all fi
154154
:end-before: json-end
155155

156156

157-
Namespace and namespace mapping can be also applied to model types passing ``ns`` and ``nsmap``
158-
to :py:func:`pydantic_xml.element`. If they are omitted model namespace and namespace mapping is used:
157+
The namespace and namespace mapping can be also applied to model types passing ``ns`` and ``nsmap``
158+
to :py:func:`pydantic_xml.element`. If they are omitted the model namespace and namespace mapping is used:
159159

160160
.. grid:: 2
161161
:gutter: 2
@@ -198,7 +198,7 @@ Strict (default)
198198

199199
The element to which a field will be bound is searched sequentially one by one (without skipping unknown elements).
200200
If the tag of a next element doesn't match the field tag that field is considered unbound.
201-
This mode is used when strong document validation is required. If you parse a large document it is the best
201+
This mode is used when the strong document validation is required. If you parse a large document it is the best
202202
choice because it works in predictable time since it doesn't require any look-ahead operations.
203203

204204
.. grid:: 2
@@ -212,7 +212,7 @@ choice because it works in predictable time since it doesn't require any look-ah
212212
:end-before: model-end
213213

214214
.. error::
215-
code raises an exception because of incorrect field order
215+
code raises an exception because of the incorrect field order
216216

217217
.. grid-item-card:: Document
218218

@@ -239,7 +239,7 @@ Ordered
239239
.......
240240

241241
The element to which a field will be bound is searched sequentially skipping unknown elements.
242-
If the tag of a next element doesn't match the field tag that element is skipped and the search continues.
242+
If the tag of the next element doesn't match the field tag that element is skipped and the search continues.
243243
This mode is used when the elements order matters but unexpected (or irrelevant) elements could appear in a document.
244244

245245
.. grid:: 2
@@ -282,7 +282,7 @@ This mode is used when the elements order matters but unexpected (or irrelevant)
282282
field2: str = element(tag='element2')
283283
field3: str = element(tag='element1')
284284
285-
will fail for the following document:
285+
fails for the following document:
286286

287287
.. code-block:: xml
288288

docs/source/pages/data-binding/heterogeneous.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Heterogeneous collections
55
_________________________
66

77
Heterogeneous collections are similar to :ref:`homogeneous collections <homogeneous>`
8-
except that the number of elements is predefined which means they follow the same binding rules.
8+
except that the number of the elements is predefined which means they follow the same binding rules.
99
The most common heterogeneous collection is :py:obj:`typing.Tuple` (like ``Tuple[int, int, int]``)

docs/source/pages/data-binding/homogeneous.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ variable-length tuple :py:obj:`typing.Tuple` (like ``Tuple[int, ...]``)
1212
Primitive homogeneous collection
1313
********************************
1414

15-
Field of a primitive homogeneous collection type marked as :py:func:`pydantic_xml.element` is bound
16-
to sub-elements text.
15+
A field of a primitive homogeneous collection type marked as :py:func:`pydantic_xml.element` is bound
16+
to the sub-elements texts.
1717

1818
.. grid:: 2
1919
:gutter: 2
@@ -49,9 +49,9 @@ to sub-elements text.
4949
Model homogeneous collection
5050
****************************
5151

52-
Field of a model homogeneous collection type is bound to sub-elements. Then the sub-element is used
53-
as a root for that sub-model. For more information see :ref:`model data binding <pages/data-binding/models:model>`.
54-
Parameter ``tag`` is used to declare sub-elements tag to which the sub-models are bound.
52+
A field of a model homogeneous collection type is bound to sub-elements. Then the sub-element is used
53+
as the root for that sub-model. For more information see :ref:`model data binding <pages/data-binding/models:model>`.
54+
The ``tag`` parameter is used to declare sub-elements tag to which the sub-models are bound.
5555
If it is omitted the sub-model ``tag`` parameter is used.
5656
If it is omitted too field name is used (respecting ``pydantic`` field aliases).
5757

@@ -89,7 +89,7 @@ If it is omitted too field name is used (respecting ``pydantic`` field aliases).
8989
Dict homogeneous collection
9090
***************************
9191

92-
Field of a mapping homogeneous collection type is bound to sub-elements attributes:
92+
A field of a mapping homogeneous collection type is bound to sub-elements attributes:
9393

9494
.. grid:: 2
9595
:gutter: 2

docs/source/pages/data-binding/mappings.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ________
77
Local attributes
88
****************
99

10-
Field of a mapping type is bound to a local element attributes.
10+
A field of a mapping type is bound to local element attributes.
1111

1212
.. grid:: 2
1313
:gutter: 2
@@ -43,9 +43,9 @@ Field of a mapping type is bound to a local element attributes.
4343
Sub-element attributes
4444
**********************
4545

46-
Field of a mapping type marked as :py:func:`pydantic_xml.element` is bound to a sub-element attributes.
47-
Parameter ``tag`` of :py:func:`pydantic_xml.element` is used as a sub-element tag to which attributes
48-
the field is bound. If it is omitted field name is used (respecting ``pydantic`` field aliases).
46+
A field of a mapping type marked as :py:func:`pydantic_xml.element` is bound to sub-element attributes.
47+
The ``tag`` parameter of :py:func:`pydantic_xml.element` is used as a sub-element tag to which attributes
48+
the field is bound. If it is omitted the field name is used (respecting ``pydantic`` field aliases).
4949

5050
.. grid:: 2
5151
:gutter: 2

docs/source/pages/data-binding/models.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ _____
77
Root model
88
**********
99

10-
Root model is bound to the root xml element with the tag matching the model ``tag`` or class name.
10+
A root model is bound to the root xml element with the tag matching the model ``tag`` or class name.
1111
If the corresponding element not found :py:class:`pydantic_xml.ParsingError` exception is raised.
1212

1313
.. grid:: 2
@@ -52,7 +52,7 @@ Namespaces
5252

5353
You can declare the root model namespace by setting parameters ``ns`` and ``nsmap``.
5454
where ``ns`` is the element namespace alias and ``nsmap`` is a namespace mapping.
55-
Namespace mapping is inherited by all the model field:
55+
The namespace mapping is inherited by all the model field:
5656

5757
.. grid:: 2
5858
:gutter: 2

0 commit comments

Comments
 (0)