peterjc / flake8-black

flake8 plugin to run black for checking Python coding style
MIT License
165 stars 10 forks source link

BLK999 Unexpected exception: 'PY310' #66

Closed Minipada closed 2 years ago

Minipada commented 2 years ago

Setup

pyproject.toml contains:

[tool.black]
diff = false
verbose = false
line-length = 100
target-version = ['py38', 'py39', 'py310']

python 3.8.10 flake8-black version: 0.3.3 poetry version: 1.1.13

pre-commit:

  - repo: https://gitlab.com/pycqa/flake8
    rev: 3.9.2
    hooks:
      - id: flake8
        additional_dependencies:
          [
            ...
            flake8-black,
            ...
          ]

What I did

running:

poetry shell
flake8 ...

works

As does poetry run flake8 ...

But

poetry run pre-commit run flake8 ...

and

poetry shell
pre-commit run flake8 ...

returns

BLK999 Unexpected exception: 'PY310'

Only this extension gives problems on pre-commit, not sure why:

flake8...................................................................Failed
- hook id: flake8
- duration: 0.43s
- exit code: 1

flake8.plugins.manager    MainProcess     41 INFO     Loading entry-points for "flake8.extension".
flake8.plugins.manager    MainProcess     50 INFO     Loading entry-points for "flake8.report".
flake8.plugins.manager    MainProcess     58 INFO     Loading plugin "A00" from entry-point.
flake8.plugins.manager    MainProcess     59 INFO     Loading plugin "B" from entry-point.
flake8.plugins.manager    MainProcess     78 INFO     Loading plugin "B1" from entry-point.
flake8.plugins.manager    MainProcess    137 INFO     Loading plugin "BLK" from entry-point.
flake8.plugins.manager    MainProcess    211 INFO     Loading plugin "C4" from entry-point.
flake8.plugins.manager    MainProcess    214 INFO     Loading plugin "C90" from entry-point.
flake8.plugins.manager    MainProcess    214 INFO     Loading plugin "CFQ" from entry-point.
flake8.plugins.manager    MainProcess    219 INFO     Loading plugin "D" from entry-point.
flake8.plugins.manager    MainProcess    256 INFO     Loading plugin "DAR" from entry-point.
flake8.plugins.manager    MainProcess    281 INFO     Loading plugin "E8" from entry-point.
flake8.plugins.manager    MainProcess    283 INFO     Loading plugin "EXE00" from entry-point.
flake8.plugins.manager    MainProcess    284 INFO     Loading plugin "F" from entry-point.
flake8.plugins.manager    MainProcess    294 INFO     Loading plugin "O10" from entry-point.
flake8.plugins.manager    MainProcess    294 INFO     Loading plugin "Q0" from entry-point.
flake8.plugins.manager    MainProcess    295 INFO     Loading plugin "S001" from entry-point.
flake8.plugins.manager    MainProcess    295 INFO     Loading plugin "T" from entry-point.
flake8.plugins.manager    MainProcess    296 INFO     Loading plugin "T00" from entry-point.
flake8.plugins.manager    MainProcess    297 INFO     Loading plugin "T100" from entry-point.
flake8.plugins.manager    MainProcess    298 INFO     Loading plugin "VNE" from entry-point.
flake8.plugins.manager    MainProcess    298 INFO     Loading plugin "flake8_copyright" from entry-point.
flake8.plugins.manager    MainProcess    299 INFO     Loading plugin "logging-format" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.ambiguous_identifier" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.bare_except" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.blank_lines" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.break_after_binary_operator" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.break_before_binary_operator" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.comparison_negative" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.comparison_to_singleton" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.comparison_type" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.compound_statements" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.continued_indentation" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.explicit_line_join" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.extraneous_whitespace" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.imports_on_separate_lines" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.indentation" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.maximum_doc_length" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.maximum_line_length" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.missing_whitespace" from entry-point.
flake8.plugins.manager    MainProcess    300 INFO     Loading plugin "pycodestyle.missing_whitespace_after_import_keyword" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.missing_whitespace_around_operator" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.module_imports_on_top_of_file" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.python_3000_async_await_keywords" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.python_3000_backticks" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.python_3000_has_key" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.python_3000_invalid_escape_sequence" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.python_3000_not_equal" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.python_3000_raise_comma" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.tabs_obsolete" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.tabs_or_spaces" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.trailing_blank_lines" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.trailing_whitespace" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.whitespace_around_comma" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.whitespace_around_keywords" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.whitespace_around_named_parameter_equals" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.whitespace_around_operator" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.whitespace_before_comment" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "pycodestyle.whitespace_before_parameters" from entry-point.
flake8.plugins.manager    MainProcess    301 INFO     Loading plugin "default" from entry-point.
flake8.plugins.manager    MainProcess    302 INFO     Loading plugin "pylint" from entry-point.
flake8.plugins.manager    MainProcess    302 INFO     Loading plugin "quiet-filename" from entry-point.
flake8.plugins.manager    MainProcess    302 INFO     Loading plugin "quiet-nothing" from entry-point.
flake8.options.manager    MainProcess    302 WARNING  option --max-complexity: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
flake8.options.manager    MainProcess    303 WARNING  option --quotes: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
flake8.options.manager    MainProcess    303 WARNING  option --inline-quotes: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
flake8.options.manager    MainProcess    303 WARNING  option --multiline-quotes: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
flake8.options.manager    MainProcess    303 WARNING  option --docstring-quotes: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
flake8.options.manager    MainProcess    303 WARNING  option --copyright-min-file-size: please update from optparse string `type=` to argparse callable `type=` -- this will be an error in the future
flake8                    MainProcess    306 INFO     flake8-black: No black configuration set
flake8.checker            MainProcess    307 INFO     Making checkers
flake8.checker            MainProcess    309 INFO     Checking 1 files
flake8                    MainProcess    333 INFO     flake8-black: loading black settings from /home/david/dev/ros2_windrose/pyproject.toml
flake8.main.application   MainProcess    360 INFO     Finished running
flake8.main.application   MainProcess    360 INFO     Reporting errors
windrose_robots_peter/windrose_robots_peter_bringup/launch/sensors.launch.py:0:1: BLK999 Unexpected exception: 'PY310'
Minipada commented 2 years ago

I think the error is triggered because some other extension interfers...If i remove darglint or flake8-variables-names in the the precommit configuration, this is not displayed anymore... I'm a bit lost on this one

peterjc commented 2 years ago

Unfortunately I can't immediately reproduce this on my default macOS setup:

$ flake8 --version
4.0.1 (black: 0.3.3, flake8-darglint: 1.8.1, flake8-variables-names: 0.0.5, mccabe: 0.6.1, pycodestyle:
2.8.0, pyflakes: 2.4.0) CPython 3.9.13 on Darwin

Using the GitHub code search, "PY310" does not seem to in the code of https://github.com/terrencepreilly/darglint/ or https://github.com/best-doctor/flake8-variables-names/ as a plain string.

Unfortunately "PY310" is effectively the output of str(exception) rather than repr(exception), so we don't immediately know what the class is - which may help with tracking down where the exception comes from.

I suggest you try this change in the hope of getting a clue:

$ git diff
diff --git a/flake8_black.py b/flake8_black.py
index aaf762c..309f06b 100644
--- a/flake8_black.py
+++ b/flake8_black.py
@@ -223,7 +223,7 @@ class BlackStyleChecker:
             except BadBlackConfig as err:
                 msg = "997 Invalid TOML file: %s" % err
             except Exception as err:
-                msg = "999 Unexpected exception: %s" % err
+                msg = "999 Unexpected exception: %r" % err
             else:
                 assert (
                     new_code != source

You might also try changing that line to raise err in the hope of getting a traceback when run via flake8?

Minipada commented 2 years ago

Before trying to edit the flake8_black.py, I cleaned up my pre-commit cache directory. After that, the error disappeared. I can't reproduce it at all now. I will close the issue and if it comes back, I or other users could reproduce it.

peterjc commented 2 years ago

Curious - hopefully it won't come back. Thanks for the update.