1

I came across this code from Azure Python SDK

class BlobConverter(meta.InConverter,
                    meta.OutConverter,
                    binding='blob',
                    trigger='blobTrigger'):
    @classmethod
    def check_input_type_annotation(cls, pytype: type) -> bool:
        return issubclass(pytype, (azf_abc.InputStream, bytes, str))
...

What does it mean that binding and trigger have default values assigned? I thought that space was used for defining inheritance.

Note that this is different from questions like python-class-default-value-inheritance, where they discuss default values in the __init__-method

1 Answer 1

2

These arguments get passed top the metaclass machinery during the class creation process. You should read about the details here in the data model documentation.

In brief,

By default, classes are constructed using type(). The class body is executed in a new namespace and the class name is bound locally to the result of type(name, bases, namespace).

The class creation process can be customized by passing the metaclass keyword argument in the class definition line, or by inheriting from an existing class that included such an argument. In the following example, both MyClass and MySubclass are instances of Meta:

class Meta(type):
    pass

class MyClass(metaclass=Meta):
    pass

class MySubclass(MyClass):
    pass

Any other keyword arguments that are specified in the class definition are passed through to all metaclass operations described below.

So, more concretely, this will be passed to:

namespace = metaclass.__prepare__(name, bases, **kwds)

When the namespace is prepared, where **kwds come from the class definition statement (excluding metaclass).

And, it also gets passed to the metaclass itself when constructing the class object:

metaclass(name, bases, namespace, **kwds) 

And also, it will get passed to the parent class's __init_subclass__, but as the docs note, the default implementation object.__init_subclass__ does nothing, but raises an error if it is called with any arguments.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.