Closed Atry closed 6 months ago
Do you really want to use __class__
, or did you meant self.__class__
? The bare __class__
closure is rarely used in instance methods AFAICT, and I'm wondering if it is explicitly not added to pyflyby codebase to detect this.
__class__
is useful in @staticmethod
-decorated functions.
class MyClass:
_MY_REGEX: ClassVar = re.compile(r"[^\w]")
@staticmethod
def my_static_function(s: str):
return re.sub(__class__._MY_REGEX, "_", s)
Sure, yes, I understand the need for it in __new__
, static methods and other context, I was just checking for the use case you posted. One could also argue that if you need __class__
in a static method, then maybe it should be a class method as well, and you should refer to cls._MY_REGEX
.
Sometime you want the class where the method is defined, not the final class being instantiated. For example: https://stackoverflow.com/a/78306250/955091
Given the following file:
When running
I got the following error
I think the error message is a false positive.
Version information