Skip to content

Matchers

Matchers

Module and object matchers.

MatchByAttribute dataclass

Object matcher that selects objects having an attribute with the given name.

The same as lambda obj: hasattr(obj, attribute_name)

Example:

Find all objects that have an attribute init_app.

MatchByAttribute("init_app")

Attributes:

Name Type Description
attribute_name str

attribute name as a string.

MatchByMethod dataclass

Object matcher that selects objects having a method with a specific name.

Example:

Find all objects having a method init_app() (a common way for initializing Flask plugins.)

MatchByMethod("init_app")

Attributes:

Name Type Description
method_name str

method name as a string.

MatchByPattern dataclass

Module matcher that selects module names by patterns.

Example:

matcher = MatchByPattern(["*.models", "*.models.*"])

Attributes:

Name Type Description
patterns List[str]

the list of Unix shell-style wildcards for module names. E.g. the following instance will match all files models.py and models/<something>.py in a flat list of packages inside your application.

MatchBySubclass dataclass

Object matcher that select classes that are subclasses of a given type.

Almost the same as lambda obj: issubclass(obj, object_type).

Example:

Find all Django models.

from django.db import models
matcher = MatchBySubclass(models.Model)

Attributes:

Name Type Description
object_type Type

a type or a tuple of types.

MatchByType dataclass

Object matcher that selects instances by their type.

Same as lambda obj: isintance(obj, object_type).

Example:

Find all Flask blueprints in a module.

from flask import Blueprint
matcher = MatchByType(Blueprint)

Attributes:

Name Type Description
object_type Type

object type or a list of types.