0

Example code:

def __init__(self, input_retailer, pull_gen_fun, login_class: typing.ClassVar):
    self.input_retailer = input_retailer
    self.pull_gen_fun = pull_gen_fun
    self.login_class = login_class

I think typing.ClassVar isn't for this kind of case correct?

Jing He
  • 794
  • 1
  • 9
  • 17

2 Answers2

1

In general, all class objects in Python are subclasses of the builtin type:

class T:
    pass

print(type(T))              # outputs "<class 'type'>
print(isinstance(T, type))  # outputs "True"

If you want to accept essentially any class object for login_class, annotating it using type is the way to go:

def __init__(self, input_retailer, pull_gen_fun, login_class: type):
    ...
Brian61354270
  • 8,690
  • 4
  • 21
  • 43
-2

Please check this. This is what you want?

from typing import ClassVar


def __init__(self, input_retailer, pull_gen_fun, login_class: ClassVar):
    self.input_retailer = input_retailer
    self.pull_gen_fun = pull_gen_fun
    self.login_class = login_class
krishna
  • 1,029
  • 6
  • 12
  • 1
    You still use `ClassVar`. How does this differ from the OP's solution? – Brian61354270 Mar 13 '20 at 17:09
  • 1
    OP's is trying to use **typing.ClassVar** which through error. He should import. – krishna Mar 13 '20 at 17:10
  • 1
    You misinterpret the OP's question. Their issue has nothing to do with a `NameError`. They are asking what type hint is appropriate for class objects, and point out the documentation for `typing.ClassVar` indicates that it isn't appropriate for this use. – Brian61354270 Mar 13 '20 at 17:13