python pep8 class in init imported but not used

后端 未结 3 853
轻奢々
轻奢々 2021-02-02 05:42

I\'m doing PEP8 checks in python using the python flake8 library. I have an import statement in an __init__.py file in one of my sub-modules which looks like this:<

相关标签:
3条回答
  • 2021-02-02 05:49

    According to PEP 8, you should include MyClass in __all__, which will also fix the imported-but-not-used issue:

    To better support introspection, modules should explicitly declare the names in their public API using the __all__ attribute.

    0 讨论(0)
  • 2021-02-02 05:59

    According to flake8's documention, you can in-line ignore this specific warning with:

    from .my_class import MyClass  # noqa: F401
    

    For reference, here are flake8's error codes.

    0 讨论(0)
  • 2021-02-02 06:08

    This is not actually a PEP8 violation. I simply do this:

    from .my_class import MyClass  # noqa
    

    Edit: Another possibility is to use __all__. In that case, flake8 understands what is going on:

    from .my_class import MyClass
    
    __all__ = ['MyClass',]
    
    0 讨论(0)
提交回复
热议问题