Returns if the type annotation ``type_`` allows ``None``. This function supports: * forward refs * unions * pep593 - Annotated * pep695 - TypeAliasType (does not support looking into fw reference of other pep695) * NewType * plain types like ``int``, ``None``, etc
(type_: Any)
| 538 | |
| 539 | |
| 540 | def includes_none(type_: Any) -> bool: |
| 541 | """Returns if the type annotation ``type_`` allows ``None``. |
| 542 | |
| 543 | This function supports: |
| 544 | * forward refs |
| 545 | * unions |
| 546 | * pep593 - Annotated |
| 547 | * pep695 - TypeAliasType (does not support looking into |
| 548 | fw reference of other pep695) |
| 549 | * NewType |
| 550 | * plain types like ``int``, ``None``, etc |
| 551 | """ |
| 552 | if is_fwd_ref(type_): |
| 553 | return _de_optionalize_fwd_ref_union_types(type_, True) |
| 554 | if is_union(type_): |
| 555 | return any(includes_none(t) for t in get_args(type_)) |
| 556 | if is_pep593(type_): |
| 557 | return includes_none(get_args(type_)[0]) |
| 558 | if is_pep695(type_): |
| 559 | return any(includes_none(t) for t in pep695_values(type_)) |
| 560 | if is_newtype(type_): |
| 561 | return includes_none(type_.__supertype__) |
| 562 | try: |
| 563 | return type_ in (NoneType, None) or is_fwd_none(type_) |
| 564 | except TypeError: |
| 565 | # if type_ is Column, mapped_column(), etc. the use of "in" |
| 566 | # resolves to ``__eq__()`` which then gives us an expression object |
| 567 | # that can't resolve to boolean. just catch it all via exception |
| 568 | return False |
| 569 | |
| 570 | |
| 571 | def is_a_type(type_: Any) -> bool: |
no test coverage detected