Skip to content

python (3)

in_std_library

in_std_library(fn: 'str | Callable[..., Any]') -> 'bool'

Return true when given fn / string is part of the std library.

Example

Jinja call:

{% if "inspect.getsource" is in_std_library %}
True!
{% endif %}
Result:
True!

DocStrings

Parameters:

Name Type Description Default
fn str | Callable[..., Any]

(Name of) function to check

required
Source code in src/jinjarope/envtests.py
145
146
147
148
149
150
151
152
def is_in_std_library(fn: str | Callable[..., Any]) -> bool:
    """Return true when given fn / string is part of the std library.

    Args:
        fn: (Name of) function to check
    """
    name = fn if isinstance(fn, str) else fn.__module__
    return name.split(".")[0] in sys.stdlib_module_names

python_builtin

python_builtin(fn: 'str | Callable[..., Any]') -> 'bool'

Return true when given fn / string represents a python builtin.

Example

Jinja call:

{% if "repr" is python_builtin %}
True!
{% endif %}
Result:
True!

DocStrings

Parameters:

Name Type Description Default
fn str | Callable[..., Any]

(Name of) function to check

required
Source code in src/jinjarope/envtests.py
136
137
138
139
140
141
142
def is_python_builtin(fn: str | Callable[..., Any]) -> bool:
    """Return true when given fn / string represents a python builtin.

    Args:
        fn: (Name of) function to check
    """
    return fn in dir(builtins) if isinstance(fn, str) else inspect.isbuiltin(fn)

python_keyword

python_keyword(string: str) -> bool

Return true when given string represents a python keyword.

Example

Jinja call:

{% if "for" is python_keyword %}
True!
{% endif %}
Result:
True!

DocStrings

Parameters:

Name Type Description Default
string str

The string to check

required
Source code in src/jinjarope/envtests.py
125
126
127
128
129
130
131
132
133
def is_python_keyword(string: str) -> bool:
    """Return true when given string represents a python keyword.

    Args:
        string: The string to check
    """
    import keyword

    return keyword.iskeyword(string)