MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / includes_none

Function includes_none

lib/sqlalchemy/util/typing.py:540–568  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

538
539
540def 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
571def is_a_type(type_: Any) -> bool:

Callers 3

declarative_scanMethod · 0.85

Calls 8

is_fwd_refFunction · 0.85
is_unionFunction · 0.85
is_pep593Function · 0.85
is_pep695Function · 0.85
pep695_valuesFunction · 0.85
is_newtypeFunction · 0.85
is_fwd_noneFunction · 0.85

Tested by

no test coverage detected