python - PyCharm - Trailing type hints and line width limit -


in pycharm, typically use trailing type hints (not sure of right way of calling them) variables such this:

my_var = my_other_variable  # type: myobject 

however, have long line cannot split, or type hint bit long, such as:

my_var = my_really_long_variable_name  # type: qtwidgets.qverylongqtclassname 

this make full line longer line width limit (79 characters), , hence pycharm flag warning.

hence, is there way put type hint in different line? tried these not seem work:

# type: qtwidgets.qverylongqtclassname my_var = my_really_long_variable_name  my_var = my_really_long_variable_name \     # type: qtwidgets.qverylongqtclassname 

the closest thing can think of this, may not shorten line width:

my_var = \     my_really_long_variable_name  # type: qtwidgets.qverylongqtclassname 

otherwise, alternative have this:

v = my_really_long_variable_name my_var = v  # type: qtwidgets.qverylongqtclassname 

the other alternative of shortening type not seem work based on tests have done; pycharm seems struggle recognising my_var's type qtwidgets.qverylongqtclassname in case:

t = qtwidgets.qverylongqtclassname my_var = my_really_long_variable_name  # type: t 

i found convenient import class names directly module type annotation usage. example:

from qtwidgets import qverylongqtclassname my_var = my_really_long_variable_name  # type: qverylongqtclassname 

i have not encountered problem yours yet attitude.

however, found version readable , convenient way annotate long line:

my_var = \     my_really_long_variable_name  # type: qtwidgets.qverylongqtclassname 

update: way implement this:

my_var = (     my_really_long_variable_name )  # type: qtwidgets.qverylongqtclassname 

in addition, supported , not cause problems in ides.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -