I have such code in python 3.7, as :
try:
import json
except ImportError:
import simplejson as json
And once I am running pre-commit, I have received such failure:
testcase.py:57: error: Name 'json' already defined (by an import)
my pre-commit is 1.20.0 on Ubuntu 16.04. Is there a way to make it pass ?
Here is my pre-commit command:
pre-commit run --all-files
Question update.
1) following is my .pre-commit-config.yaml file.
default_language_version:
python: python3.7
exclude: ^(creds/|utils/license_keygen/)|/migrations/|/node_modules/
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v1.24.0
hooks:
- id: pyupgrade
args: [--py3-plus]
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.7.0
hooks:
- id: reorder-python-imports
args: ['--application-directories=apps', --py3-plus]
- repo: https://github.com/asottile/blacken-docs
rev: v1.3.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
exclude: _pytest/debugging.py
- id: end-of-file-fixer
- id: fix-encoding-pragma
args: [--remove]
- id: name-tests-test
args: [--django]
exclude: ^(apps/fcldinfra/tests/settings/|apps/portal/src/extender/tests/expected_tests_api/)
- id: trailing-whitespace
# conflicts with black?
#- repo: https://github.com/asottile/add-trailing-comma
# rev: v1.4.1
# hooks:
# - id: add-trailing-comma
# args: [--py36-plus]
#- repo: https://gitlab.com/pycqa/flake8
# rev: 3.7.8
# hooks:
# - id: flake8
# args: [--config=.flake8]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.740'
hooks:
- id: mypy
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.4.1
hooks:
# - id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
#- repo: https://github.com/myint/docformatter
# rev: v1.3
# hooks:
# - id: docformatter
#- repo: https://github.com/PyCQA/pydocstyle
# rev: 4.0.1
# hooks:
# - id: pydocstyle
#- repo: local
# hooks:
# - id: unittest
# name: Check python unit test pass
# entry: pipenv run python -m unittest discover -p *_test.py --start-directory apps -v
# pass_filenames: false
# language: system
# types: [python]
2) And when I was executing pre-commit , following is the log message:
pre-commit run --all-files
pyupgrade................................................................Passed
Reorder python imports...................................................Passed
blacken-docs.............................................................Passed
black....................................................................Passed
Check for merge conflicts................................................Passed
Check for broken symlinks................................................Passed
Debug Statements (Python)................................................Passed
Fix End of Files.........................................................Passed
Fix python encoding pragma...............................................Passed
Tests should end in _test.py.............................................Passed
Trim Trailing Whitespace.................................................Passed
mypy.....................................................................Failed
hookid: mypy
.../testcase.py:57: error: Name 'json' already defined (by an import)
Found 1 error in 1 files (checked 500 source files)
use logger.warning(......................................................Passed
type annotations not comments............................................Passed