Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the bracket [ ] mean when it comes after a class name?

For example,

class BasicTransitionFunction(TransitionFunction[GrammarBasedState]):
      ...

where TransitionFunction is the base class of BasicTransitionFunction, and GrammarBasedState is also a class name. I only know that [] can be used to indexed arrays. What does it mean here?

like image 394
Yu Gu Avatar asked Nov 06 '22 13:11

Yu Gu


1 Answers

This is the syntax for generic types. Like @Sraw said, it means that TransitionFunction is a generic type. For example, List is a generic type, so you can have List[Int].

This is the same idea as for C++ templates (e.g. std::vector<int>).

So here BasicTransitionFunction is a subclass of a TransitionFunction between GrammarBasedStates.

like image 175
Arusekk Avatar answered Nov 14 '22 22:11

Arusekk