Minus sign in front of python method

I read the ocstyle source code and I came across the methods that are in front of them. here is an example

@rule(modifier[...] + (sizedCType | anyIdentifier) + -implementedProtocols + (Present(Regex(r'[(),<>:]')) | sp(1)) + Literal('*')[...]) 

There are times when methods have a '-' before calling a method before returning it. is there anyone who can determine what this is called, or point me to some other resource? I tried looking for him and came to the conclusion that this would be my best choice.

+4
source share
2 answers

In python, you can define a magic function for a series of unary operators. The one you give is usually defined by __neg__(self) . I recommend looking for the source to find out what this function does in your example.

For reference, there is a list of available "magic functions" here .

+2
source

Regardless of the type implementedProtocols its own semantics for the negation operator belongs. You will need to look at the documentation or source to find out what semantics are.

0
source

Source: https://habr.com/ru/post/1497097/


All Articles