type (10)
datetime
datetime(value: Any) -> bool
Return whether a value is a datetime.
Example
Jinja call:
{% if "a" is datetime %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def _is_datetime ( value : Any ) -> bool :
"""Return whether a value is a datetime."""
return isinstance ( value , dt . datetime )
dict
dict(value: Any) -> bool
Return whether a value is a tuple.
Example
Jinja call:
{% if { "a" : "b" } is dict %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def _is_dict ( value : Any ) -> bool :
"""Return whether a value is a tuple."""
return isinstance ( value , dict )
instance
instance(obj: object, typ: str | type) -> bool
Like the isinstance builtin, but also accepts strs as type.
Example
Jinja call:
{% if { "a" : "b" } is instance ( "dict" ) %}
True!
{% endif %}
Result:
DocStrings
Parameters:
Name
Type
Description
Default
obj
object
required
typ
str | type
required
Source code in src/jinjarope/envtests.py
def is_instance ( obj : object , typ : str | type ) -> bool :
"""Like the isinstance builtin, but also accepts strs as type.
Args:
obj: The object to check
typ: A type (name)
"""
kls = utils . resolve ( typ ) if isinstance ( typ , str ) else typ
if not isinstance ( kls , type ):
raise TypeError ( kls )
return isinstance ( obj , kls )
list
list(value: Any) -> bool
Return whether a value is a list.
Example
Jinja call:
{% if [] is list %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def _is_list ( value : Any ) -> bool :
"""Return whether a value is a list."""
return isinstance ( value , list )
number
number(value: Any) -> bool
Try to convert value to a float.
Example
Jinja call:
{% if 5 is number %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def is_number ( value : Any ) -> bool :
"""Try to convert value to a float."""
try :
fvalue = float ( value )
except ( ValueError , TypeError ):
return False
return math . isfinite ( fvalue )
set
set(value: Any) -> bool
Return whether a value is a set.
Example
Jinja call:
{% if [] is set %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def _is_set ( value : Any ) -> bool :
"""Return whether a value is a set."""
return isinstance ( value , set )
string_like
string_like(value: Any) -> bool
Return whether a value is a string or string like object.
Example
Jinja call:
{% if "abc" is string_like %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def _is_string_like ( value : Any ) -> bool :
"""Return whether a value is a string or string like object."""
return isinstance ( value , str | bytes | bytearray )
subclass
subclass(obj: type, typ: str | type) -> bool
Like the issubclass builtin, but also accepts strs as type.
Example
Jinja call:
{% if cycler is subclass ( "dict" ) %}
True!
{% endif %}
Result:
DocStrings
Parameters:
Name
Type
Description
Default
obj
type
required
typ
str | type
required
Source code in src/jinjarope/envtests.py
def is_subclass ( obj : type , typ : str | type ) -> bool :
"""Like the issubclass builtin, but also accepts strs as type.
Args:
obj: The class to check
typ: A type (name)
"""
kls = utils . resolve ( typ ) if isinstance ( typ , str ) else typ
if not isinstance ( kls , type ):
raise TypeError ( kls )
return issubclass ( obj , kls )
tuple
tuple(value: Any) -> bool
Return whether a value is a tuple.
Example
Jinja call:
{% if () is tuple %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def _is_tuple ( value : Any ) -> bool :
"""Return whether a value is a tuple."""
return isinstance ( value , tuple )
type
type(value: Any) -> bool
Return whether a value is a type.
Example
Jinja call:
{% if zip is type %}
True!
{% endif %}
Result:
DocStrings
Source code in src/jinjarope/envtests.py
def _is_type ( value : Any ) -> bool :
"""Return whether a value is a type."""
return isinstance ( value , type )