hikari.internal.spel#
HikariSPEL (Hikari SimPle Expression Language).
HikariSPEL (Hikari SimPle Expression Language) is a super-simple expression language used in this module for quickly mapping values to other values and producing streams of changes. This somewhat mirrors other programming languages like Java which have a proper Stream API.
The concept of HikariSPEL is that you are trying to look at the attribute
of something. So, running "bar.baz.bork"
against an object foo
would be
equivalent to foo.bar.baz.bork
in pure Python. The reason for doing this is
Python lambdas are clunky, and using a nested function is nasty boilerplate.
For applying "bar.baz"
to foo
, we assume bar
is an attribute or property
of foo
, and baz
is an attribute or property of foo.bar
. We may instead
want to invoke a method that takes no parameters (looking at str.islower
, as
an example. To do this, we append ()
onto the attribute name. For example,
applying author.username.islower()
to a hikari.messages.Message
object.
All expressions may start with a .
. You can negate the whole expression
by instead starting them with .
.
You may also want to negate a condition. To do this, prepend to the
attribute name. For example, to check if a message was not made by a bot,
you could run
author.!is_bot
on a Message
object. Likewise, to check if
the input was not a number, you could run content.!isdigit()
.
This expression language is highly experimental and may change without prior notice for the time being.
Module Contents#
- class hikari.internal.spel.AttrGetter(attr_name)[source]#
Bases:
Generic
[InputValueT
,ReturnValueT
]An attribute getter that can resolve nested attributes and methods.
This follows the SPEL definition for how to define expressions. Expressions may be preceded with an optional
.
to aid in readability.