pep8

How to set correct indendation when using formatprg=autopep8?

寵の児 提交于 2019-12-23 16:43:36
问题 With the following option set: setlocal formatprg=autopep8\ -aa\ - When I select a single line in Visual Mode and press gq , the autopep8 makes its modification to the line but it also alters the indentation of the line: it defaults to an indent of 4 spaces, no matter the current indentation level of the line(s). I want it to assume that the lines are indented correctly and so to leave them alone. Similarly, if I set the --indent-size 8 switch for autopep8 it will push the lines to an indent

Break very long lines with access to deeply nested dictionaries

北城余情 提交于 2019-12-23 10:15:48
问题 I access a deeply nested dictionary and want to break very long lines properly. Let's assume I have this and want to break the line to conform with PEP8. (The actual line is of course longer, this is just an example.) some_dict['foo']['bar']['baz'] = 1 How would you break the line, assuming the whole some_dict['foo']['bar']['baz'] does not fit on one line anymore? There are a lot of examples for breaking long lines, but I couldn't find one for this dictionary access based question. Update:

How to indicate multiple unused values in Python?

被刻印的时光 ゝ 提交于 2019-12-23 08:47:07
问题 Normally in Python, one should use an _ to indicate an argument is unused. def example_basic(unused): pass becomes def example_basic(_): pass Then if there are multiple unused arguments, multiple _ s can't be used since they will conflict, so a *_ is used: def example_multiple(unused1, unused2): pass becomes def example_multiple(*_): pass Finally, what should be done if there are multiple non-adjacent arguments that go unused? def example_non_adjacent(unused1, used, unused2): return used

autopep8 doesn't seem to be finding config file?

大城市里の小女人 提交于 2019-12-23 01:40:40
问题 According to autopep8's documentation (here: https://github.com/hhatto/autopep8#configuration ), if I place a file called "setup.cfg" in the root of my git repo, with something like [pycodestyle] ignore = D203,E501,E201,E202,E203,E211,E261,E265,W503 exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,__init__.py,*_gui.py max-complexity = 25 max-line-length = 160 statistics = True then it should pick up that config. I'm using autopep8 via the pre-commit hook, here: https://github.com

How do I enable auto code formatting for flake8 in PyCharm

你说的曾经没有我的故事 提交于 2019-12-22 02:05:42
问题 I use Tox to run unit tests, with a flake8 command that checks for code formatting errors. Each time I code in PyCharm, I run tox then realise I have a bunch of annoying formatting errors I have to back and manually fix. I would like PyCharm to automatically format the code (according to flake8 google for me each time it auto-saves after I stop typing. my tox testenv looks like this: [testenv:flake8] commands=flake8 <my_code_directory> deps = flake8==2.4.1 flake8-import-order==0.11 pep8

autopep8 with vim

江枫思渺然 提交于 2019-12-21 09:14:11
问题 Is there a way to automatically apply autopep8 to a file being edited in vim? I have the following vimrc. Thank you in advance. 回答1: The correct way of using autopep8 is to rely on vim "formatprg" settings. So you add the line below to vimrc: au FileType python setlocal formatprg=autopep8\ - Now when you select lines in python and hit gq (the default mapping unless you remapped it). It will filter the lines through autopep8 and writes the nicely formatted version in place. The setting above

autopep8 with vim

女生的网名这么多〃 提交于 2019-12-21 09:13:06
问题 Is there a way to automatically apply autopep8 to a file being edited in vim? I have the following vimrc. Thank you in advance. 回答1: The correct way of using autopep8 is to rely on vim "formatprg" settings. So you add the line below to vimrc: au FileType python setlocal formatprg=autopep8\ - Now when you select lines in python and hit gq (the default mapping unless you remapped it). It will filter the lines through autopep8 and writes the nicely formatted version in place. The setting above

Tool for automatically check docstring style according to PEP257 [closed]

强颜欢笑 提交于 2019-12-20 17:27:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Tools like pep8 can check source code style, but they don't check if docstrings are fromatted according to pep257, pep287. Are there such tools? Update I decided to implement such a static analysis tool on my own, see: https://github.com/GreenSteam/pep257 Right now, most of pep257 is covered. Design was heavily

What is the naming convention for Python class references

廉价感情. 提交于 2019-12-20 10:19:38
问题 What is the naming convention for a variable referencing a class in Python? class MyClass(object): pass # which one is correct? reference_to_class = MyClass # or ReferenceToClass = MyClass Here is another example that resembles my situation: # cars.py class Car(object): pass class Sedan(Car): pass class Coupe(Car): pass class StatonWagon(Car): pass class Van(Car): pass def get_car_class(slug, config): return config.get(slug) # config.py CONFIG = { 'ford-mustang': Coupe, 'buick-riviera': Coupe

Python PEP8: Blank lines convention

大城市里の小女人 提交于 2019-12-20 09:48:03
问题 I am interested in knowing what is the Python convention for newlines between the program parts? For example, consider this: import os def func1(): def func2(): What should be the ideal newline separation between: The import modules and the functions? The functions themselves? I have read PEP8, but I wanted to confirm the above two points. 回答1: Two blank lines between the import statements and other code. Two blank lines between each function. 回答2: If one will check with 'Blank Lines' section