Skip to content

Commit 9f7a752

Browse files
committed
Add some documentation regarding comparing data types
1 parent f26b017 commit 9f7a752

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/rule_engine/ast.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,29 @@ def __len__(cls):
329329

330330
class DataType(metaclass=DataTypeMeta):
331331
"""
332-
A collection of constants representing the different supported data types.
332+
A collection of constants representing the different supported data types. There are three ways to compare data
333+
types. All three are effectively the same when dealing with scalars.
334+
335+
Equality checking
336+
.. code-block::
337+
338+
dt == DataType.TYPE
339+
This is the most explicit form of testing and when dealing with compound data types, it recursively checks that
340+
all of the member types are also equal.
341+
342+
Class checking
343+
.. code-block::
344+
345+
isinstance(dt, DataType.TYPE.__class__)
346+
This checks that the data types are the same but when dealing with compound data types, the member types are
347+
ignored.
348+
349+
Compatibility checking
350+
.. code-block::
351+
352+
DataType.is_compatible(dt, DataType.TYPE)
353+
This checks that the types are compatible without any kind of conversion. When dealing with compound data types,
354+
this ensures that the member types are either the same or :py:attr:`~.UNDEFINED`.
333355
"""
334356
ARRAY = _ArrayDataTypeDef('ARRAY', tuple)
335357
"""

0 commit comments

Comments
 (0)