expressions ¤
This module contains the data classes that represent resolvable names and expressions.
Classes:
-
Expr
–Base class for expressions.
-
ExprAttribute
–Attributes like
a.b
. -
ExprBinOp
–Binary operations like
a + b
. -
ExprBoolOp
–Boolean operations like
a or b
. -
ExprCall
–Calls like
f()
. -
ExprCompare
–Comparisons like
a > b
. -
ExprComprehension
–Comprehensions like
a for b in c if d
. -
ExprConstant
–Constants like
"a"
or1
. -
ExprDict
–Dictionaries like
{"a": 0}
. -
ExprDictComp
–Dict comprehensions like
{k: v for k, v in a}
. -
ExprExtSlice
–Extended slice like
a[x:y, z]
. -
ExprFormatted
–Formatted string like
{1 + 1}
. -
ExprGeneratorExp
–Generator expressions like
a for b in c for d in e
. -
ExprIfExp
–Conditions like
a if b else c
. -
ExprJoinedStr
–Joined strings like
f"a {b} c"
. -
ExprKeyword
–Keyword arguments like
a=b
. -
ExprLambda
–Lambda expressions like
lambda a: a.b
. -
ExprList
–Lists like
[0, 1, 2]
. -
ExprListComp
–List comprehensions like
[a for b in c]
. -
ExprName
–This class represents a Python object identified by a name in a given scope.
-
ExprNamedExpr
–Named/assignment expressions like
a := b
. -
ExprParameter
–Parameters in function signatures like
a: int = 0
. -
ExprSet
–Sets like
{0, 1, 2}
. -
ExprSetComp
–Set comprehensions like
{a for b in c}
. -
ExprSlice
–Slices like
[a:b:c]
. -
ExprSubscript
–Subscripts like
a[b]
. -
ExprTuple
–Tuples like
(0, 1, 2)
. -
ExprUnaryOp
–Unary operations like
-1
. -
ExprVarKeyword
–Variadic keyword parameters like
**kwargs
. -
ExprVarPositional
–Variadic positional parameters like
*args
. -
ExprYield
–Yield statements like
yield a
. -
ExprYieldFrom
–Yield statements like
yield from a
.
Functions:
-
get_expression
–Build an expression from an AST.
-
safe_get_expression
–Safely (no exception) build a resolvable annotation.
Expr dataclass
¤
Expr()
Base class for expressions.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprAttribute dataclass
¤
flowchart TD
griffe.expressions.ExprAttribute[ExprAttribute]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprAttribute
click griffe.expressions.ExprAttribute href "" "griffe.expressions.ExprAttribute"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Attributes like a.b
.
Methods:
-
append
–Append a name to this attribute.
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –The canonical path of this attribute.
-
classname
(str
) –The expression class name.
-
first
(str | Expr
) –The first part of this attribute (on the left).
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
last
(ExprName
) –The last part of this attribute (on the right).
-
path
(str
) –The path of this attribute.
-
values
(list[str | Expr]
) –The different parts of the dotted chain.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
modernize ¤
modernize() -> ExprName | ExprAttribute
Modernize the expression.
For example, use PEP 604 type unions |
instead of typing.Union
.
Returns:
-
Expr
–A modernized expression.
ExprBinOp dataclass
¤
flowchart TD
griffe.expressions.ExprBinOp[ExprBinOp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprBinOp
click griffe.expressions.ExprBinOp href "" "griffe.expressions.ExprBinOp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Binary operations like a + b
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
left
(str | Expr
) –Left part.
-
operator
(str
) –Binary operator.
-
path
(str
) –Path of the expressed name/attribute.
-
right
(str | Expr
) –Right part.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprBoolOp dataclass
¤
flowchart TD
griffe.expressions.ExprBoolOp[ExprBoolOp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprBoolOp
click griffe.expressions.ExprBoolOp href "" "griffe.expressions.ExprBoolOp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Boolean operations like a or b
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
operator
(str
) –Boolean operator.
-
path
(str
) –Path of the expressed name/attribute.
-
values
(Sequence[str | Expr]
) –Operands.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprCall dataclass
¤
flowchart TD
griffe.expressions.ExprCall[ExprCall]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprCall
click griffe.expressions.ExprCall href "" "griffe.expressions.ExprCall"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Calls like f()
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
arguments
(Sequence[str | Expr]
) –Passed arguments.
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –The canonical path of this subscript's left part.
-
classname
(str
) –The expression class name.
-
function
(Expr
) –Function called.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprCompare dataclass
¤
flowchart TD
griffe.expressions.ExprCompare[ExprCompare]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprCompare
click griffe.expressions.ExprCompare href "" "griffe.expressions.ExprCompare"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Comparisons like a > b
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
comparators
(Sequence[str | Expr]
) –Things compared.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
left
(str | Expr
) –Left part.
-
operators
(Sequence[str]
) –Comparison operators.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprComprehension dataclass
¤
ExprComprehension(
target: str | Expr,
iterable: str | Expr,
conditions: Sequence[str | Expr],
is_async: bool = False,
)
flowchart TD
griffe.expressions.ExprComprehension[ExprComprehension]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprComprehension
click griffe.expressions.ExprComprehension href "" "griffe.expressions.ExprComprehension"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Comprehensions like a for b in c if d
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
conditions
(Sequence[str | Expr]
) –Conditions to include the target in the result.
-
is_async
(bool
) –Async comprehension or not.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
iterable
(str | Expr
) –Value iterated on.
-
path
(str
) –Path of the expressed name/attribute.
-
target
(str | Expr
) –Comprehension target (value added to the result).
conditions instance-attribute
¤
Conditions to include the target in the result.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprConstant dataclass
¤
ExprConstant(value: str)
flowchart TD
griffe.expressions.ExprConstant[ExprConstant]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprConstant
click griffe.expressions.ExprConstant href "" "griffe.expressions.ExprConstant"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Constants like "a"
or 1
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(str
) –Constant value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprDict dataclass
¤
flowchart TD
griffe.expressions.ExprDict[ExprDict]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprDict
click griffe.expressions.ExprDict href "" "griffe.expressions.ExprDict"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Dictionaries like {"a": 0}
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
keys
(Sequence[str | Expr | None]
) –Dict keys.
-
path
(str
) –Path of the expressed name/attribute.
-
values
(Sequence[str | Expr]
) –Dict values.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprDictComp dataclass
¤
flowchart TD
griffe.expressions.ExprDictComp[ExprDictComp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprDictComp
click griffe.expressions.ExprDictComp href "" "griffe.expressions.ExprDictComp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Dict comprehensions like {k: v for k, v in a}
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
generators
(Sequence[Expr]
) –Generators iterated on.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
key
(str | Expr
) –Target key.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(str | Expr
) –Target value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprExtSlice dataclass
¤
flowchart TD
griffe.expressions.ExprExtSlice[ExprExtSlice]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprExtSlice
click griffe.expressions.ExprExtSlice href "" "griffe.expressions.ExprExtSlice"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Extended slice like a[x:y, z]
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
dims
(Sequence[str | Expr]
) –Dims.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprFormatted dataclass
¤
flowchart TD
griffe.expressions.ExprFormatted[ExprFormatted]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprFormatted
click griffe.expressions.ExprFormatted href "" "griffe.expressions.ExprFormatted"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Formatted string like {1 + 1}
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(str | Expr
) –Formatted value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprGeneratorExp dataclass
¤
flowchart TD
griffe.expressions.ExprGeneratorExp[ExprGeneratorExp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprGeneratorExp
click griffe.expressions.ExprGeneratorExp href "" "griffe.expressions.ExprGeneratorExp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Generator expressions like a for b in c for d in e
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
element
(str | Expr
) –Yielded element.
-
generators
(Sequence[Expr]
) –Generators iterated on.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprIfExp dataclass
¤
flowchart TD
griffe.expressions.ExprIfExp[ExprIfExp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprIfExp
click griffe.expressions.ExprIfExp href "" "griffe.expressions.ExprIfExp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Conditions like a if b else c
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
body
(str | Expr
) –Value if test.
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
orelse
(str | Expr
) –Other expression.
-
path
(str
) –Path of the expressed name/attribute.
-
test
(str | Expr
) –Condition.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprJoinedStr dataclass
¤
flowchart TD
griffe.expressions.ExprJoinedStr[ExprJoinedStr]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprJoinedStr
click griffe.expressions.ExprJoinedStr href "" "griffe.expressions.ExprJoinedStr"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Joined strings like f"a {b} c"
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
values
(Sequence[str | Expr]
) –Joined values.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprKeyword dataclass
¤
flowchart TD
griffe.expressions.ExprKeyword[ExprKeyword]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprKeyword
click griffe.expressions.ExprKeyword href "" "griffe.expressions.ExprKeyword"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Keyword arguments like a=b
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed keyword.
-
classname
(str
) –The expression class name.
-
function
(Expr | None
) –Expression referencing the function called with this parameter.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
name
(str
) –Name.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(str | Expr
) –Value.
function class-attribute
instance-attribute
¤
function: Expr | None = None
Expression referencing the function called with this parameter.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprLambda dataclass
¤
ExprLambda(
parameters: Sequence[ExprParameter], body: str | Expr
)
flowchart TD
griffe.expressions.ExprLambda[ExprLambda]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprLambda
click griffe.expressions.ExprLambda href "" "griffe.expressions.ExprLambda"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Lambda expressions like lambda a: a.b
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
body
(str | Expr
) –Lambda's body.
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
parameters
(Sequence[ExprParameter]
) –Lambda's parameters.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprList dataclass
¤
flowchart TD
griffe.expressions.ExprList[ExprList]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprList
click griffe.expressions.ExprList href "" "griffe.expressions.ExprList"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Lists like [0, 1, 2]
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
elements
(Sequence[Expr]
) –List elements.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprListComp dataclass
¤
flowchart TD
griffe.expressions.ExprListComp[ExprListComp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprListComp
click griffe.expressions.ExprListComp href "" "griffe.expressions.ExprListComp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
List comprehensions like [a for b in c]
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
element
(str | Expr
) –Target value.
-
generators
(Sequence[Expr]
) –Generators iterated on.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprName dataclass
¤
flowchart TD
griffe.expressions.ExprName[ExprName]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprName
click griffe.expressions.ExprName href "" "griffe.expressions.ExprName"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
This class represents a Python object identified by a name in a given scope.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –The canonical name (resolved one, not alias name).
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_enum_class
(bool
) –Whether this name resolves to an enumeration class.
-
is_enum_instance
(bool
) –Whether this name resolves to an enumeration instance.
-
is_enum_value
(bool
) –Whether this name resolves to an enumeration value.
-
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
name
(str
) –Actual name.
-
parent
(str | ExprName | Module | Class | None
) –Parent (for resolution in its scope).
-
path
(str
) –The full, resolved name.
-
resolved
(Module | Class | None
) –The resolved object this name refers to.
is_enum_instance property
¤
is_enum_instance: bool
Whether this name resolves to an enumeration instance.
parent class-attribute
instance-attribute
¤
Parent (for resolution in its scope).
path property
¤
path: str
The full, resolved name.
If it was given when creating the name, return that. If a callable was given, call it and return its result. It the name cannot be resolved, return the source.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprNamedExpr dataclass
¤
flowchart TD
griffe.expressions.ExprNamedExpr[ExprNamedExpr]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprNamedExpr
click griffe.expressions.ExprNamedExpr href "" "griffe.expressions.ExprNamedExpr"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Named/assignment expressions like a := b
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
target
(Expr
) –Target name.
-
value
(str | Expr
) –Value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprParameter dataclass
¤
ExprParameter(
name: str,
kind: ParameterKind = positional_or_keyword,
annotation: Expr | None = None,
default: str | Expr | None = None,
)
flowchart TD
griffe.expressions.ExprParameter[ExprParameter]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprParameter
click griffe.expressions.ExprParameter href "" "griffe.expressions.ExprParameter"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Parameters in function signatures like a: int = 0
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
annotation
(Expr | None
) –Parameter type.
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
default
(str | Expr | None
) –Parameter default.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
kind
(ParameterKind
) –Parameter kind.
-
name
(str
) –Parameter name.
-
path
(str
) –Path of the expressed name/attribute.
kind class-attribute
instance-attribute
¤
kind: ParameterKind = positional_or_keyword
Parameter kind.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprSet dataclass
¤
flowchart TD
griffe.expressions.ExprSet[ExprSet]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprSet
click griffe.expressions.ExprSet href "" "griffe.expressions.ExprSet"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Sets like {0, 1, 2}
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
elements
(Sequence[str | Expr]
) –Set elements.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprSetComp dataclass
¤
flowchart TD
griffe.expressions.ExprSetComp[ExprSetComp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprSetComp
click griffe.expressions.ExprSetComp href "" "griffe.expressions.ExprSetComp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Set comprehensions like {a for b in c}
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
element
(str | Expr
) –Target value.
-
generators
(Sequence[Expr]
) –Generators iterated on.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprSlice dataclass
¤
ExprSlice(
lower: str | Expr | None = None,
upper: str | Expr | None = None,
step: str | Expr | None = None,
)
flowchart TD
griffe.expressions.ExprSlice[ExprSlice]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprSlice
click griffe.expressions.ExprSlice href "" "griffe.expressions.ExprSlice"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Slices like [a:b:c]
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
lower
(str | Expr | None
) –Lower bound.
-
path
(str
) –Path of the expressed name/attribute.
-
step
(str | Expr | None
) –Iteration step.
-
upper
(str | Expr | None
) –Upper bound.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprSubscript dataclass
¤
flowchart TD
griffe.expressions.ExprSubscript[ExprSubscript]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprSubscript
click griffe.expressions.ExprSubscript href "" "griffe.expressions.ExprSubscript"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Subscripts like a[b]
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –The canonical path of this subscript's left part.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
left
(str | Expr
) –Left part.
-
path
(str
) –The path of this subscript's left part.
-
slice
(Expr
) –Slice part.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
modernize ¤
modernize() -> ExprBinOp | ExprSubscript
Modernize the expression.
For example, use PEP 604 type unions |
instead of typing.Union
.
Returns:
-
Expr
–A modernized expression.
ExprTuple dataclass
¤
flowchart TD
griffe.expressions.ExprTuple[ExprTuple]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprTuple
click griffe.expressions.ExprTuple href "" "griffe.expressions.ExprTuple"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Tuples like (0, 1, 2)
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
elements
(Sequence[str | Expr]
) –Tuple elements.
-
implicit
(bool
) –Whether the tuple is implicit (e.g. without parentheses in a subscript's slice).
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
implicit class-attribute
instance-attribute
¤
implicit: bool = False
Whether the tuple is implicit (e.g. without parentheses in a subscript's slice).
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprUnaryOp dataclass
¤
flowchart TD
griffe.expressions.ExprUnaryOp[ExprUnaryOp]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprUnaryOp
click griffe.expressions.ExprUnaryOp href "" "griffe.expressions.ExprUnaryOp"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Unary operations like -1
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
operator
(str
) –Unary operator.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(str | Expr
) –Value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprVarKeyword dataclass
¤
ExprVarKeyword(value: Expr)
flowchart TD
griffe.expressions.ExprVarKeyword[ExprVarKeyword]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprVarKeyword
click griffe.expressions.ExprVarKeyword href "" "griffe.expressions.ExprVarKeyword"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Variadic keyword parameters like **kwargs
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(Expr
) –Double-starred value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprVarPositional dataclass
¤
ExprVarPositional(value: Expr)
flowchart TD
griffe.expressions.ExprVarPositional[ExprVarPositional]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprVarPositional
click griffe.expressions.ExprVarPositional href "" "griffe.expressions.ExprVarPositional"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Variadic positional parameters like *args
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(Expr
) –Starred value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprYield dataclass
¤
flowchart TD
griffe.expressions.ExprYield[ExprYield]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprYield
click griffe.expressions.ExprYield href "" "griffe.expressions.ExprYield"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Yield statements like yield a
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(str | Expr | None
) –Yielded value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
ExprYieldFrom dataclass
¤
flowchart TD
griffe.expressions.ExprYieldFrom[ExprYieldFrom]
griffe.expressions.Expr[Expr]
griffe.expressions.Expr --> griffe.expressions.ExprYieldFrom
click griffe.expressions.ExprYieldFrom href "" "griffe.expressions.ExprYieldFrom"
click griffe.expressions.Expr href "" "griffe.expressions.Expr"
Yield statements like yield from a
.
Methods:
-
as_dict
–Return the expression as a dictionary.
-
iterate
–Iterate on the expression elements.
-
modernize
–Modernize the expression.
Attributes:
-
canonical_name
(str
) –Name of the expressed name/attribute.
-
canonical_path
(str
) –Path of the expressed name/attribute.
-
classname
(str
) –The expression class name.
-
is_classvar
(bool
) –Whether this attribute is annotated with
ClassVar
. -
is_generator
(bool
) –Whether this expression is a generator.
-
is_iterator
(bool
) –Whether this expression is an iterator.
-
is_tuple
(bool
) –Whether this expression is a tuple.
-
path
(str
) –Path of the expressed name/attribute.
-
value
(str | Expr
) –Yielded-from value.
as_dict ¤
iterate ¤
Iterate on the expression elements.
Parameters:
-
flat
(bool
, default:True
) –Expressions are trees.
When flat is false, this method iterates only on the first layer of the tree. To iterate on all the subparts of the expression, you have to do so recursively. It allows to handle each subpart specifically (for example subscripts, attribute, etc.), without them getting rendered as strings.
On the contrary, when flat is true, the whole tree is flattened as a sequence of strings and instances of Names.
Yields:
get_expression ¤
get_expression(
node: AST | None,
parent: Module | Class,
*,
parse_strings: bool | None = None
) -> Expr | None
Build an expression from an AST.
Parameters:
-
node
(AST | None
) –The annotation node.
-
parent
(Module | Class
) –The parent used to resolve the name.
-
parse_strings
(bool | None
, default:None
) –Whether to try and parse strings as type annotations.
Returns:
-
Expr | None
–A string or resovable name or expression.
safe_get_expression ¤
safe_get_expression(
node: AST | None,
parent: Module | Class,
*,
parse_strings: bool | None = None,
log_level: LogLevel | None = error,
msg_format: str = "{path}:{lineno}: Failed to get expression from {node_class}: {error}"
) -> Expr | None
Safely (no exception) build a resolvable annotation.
Parameters:
-
node
(AST | None
) –The annotation node.
-
parent
(Module | Class
) –The parent used to resolve the name.
-
parse_strings
(bool | None
, default:None
) –Whether to try and parse strings as type annotations.
-
log_level
(LogLevel | None
, default:error
) –Log level to use to log a message. None to disable logging.
-
msg_format
(str
, default:'{path}:{lineno}: Failed to get expression from {node_class}: {error}'
) –A format string for the log message. Available placeholders: path, lineno, node, error.
Returns:
-
Expr | None
–A string or resovable name or expression.