Python: circular imports needed for type checking

后端 未结 4 1291
太阳男子
太阳男子 2021-02-08 02:51

First of all: I do know that there are already many questions and answers to the topic of the circular imports.

The answer is more or less: \"Design your Module/Class s

4条回答
  •  日久生厌
    2021-02-08 03:22

    You could just defer the import in bar.py like this:

    class Bar(object):
    
        def __init__(self, arg_instance_of_foo):
            from foo import Foo
            if not isinstance(arg_instance_of_foo, Foo):
                raise TypeError()
    

提交回复
热议问题