Skip to content
Advertisement

Python – TypeHint for Descriptor

I would like to have a base class for all my descriptors which is of type descriptor:

  1. Is it correct to use the GetSetDescriptorType?
JavaScript

Now when I declare

JavaScript

A pycharm inspection complains:

get() does not match signature.

I have looked up the signature which is:

JavaScript
  1. Is it an error in inspection or is my declaration wrong?

Advertisement

Answer

No, using GetSetDescriptor class as base is invalid for type checking since this class is final.

You don’t really need this base, because descriptors have good support now.

The problem in your definition is missing default value of objtype: parent can be called with one argument and your child – no, so this violates LSP. So the following is compatible:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement