Repository: psf/black

Issue:
Add Python version to output of `black --version`
<!--
-->

**Describe the bug**

<!-- A clear and concise description of what the bug is. -->
With structural pattern matching, Black fails with an invalid syntax, even though target version is `py310`.

**To Reproduce**

<!--
Minimal steps to reproduce the behavior with source code and Black's configuration.
-->

For example, take this code:

```python
from rest_framework import serializers
from audit.models.health_check import ParentModel

class ServiceRelatedField(serializers.Serializer):
    def to_representation(self, value):
        match value:
            case ParentModel():
                data = {"name": value.actor.login}
            case _:
                raise Exception("Unexpected type of service object")
        data["id"] = value.id
        data["class"] = self.context["class"]
        return data
```

And run it with these arguments:

```sh
$ black  --target-version py310 file.py
```

The resulting error is:

> error: cannot format file.py: cannot use --safe with this file; failed to parse source file AST: invalid syntax (<unknown>, line 6)
This could be caused by running Black with an older Python version that does not support new syntax used in your source file.

Reproduced also with [black show](https://black.vercel.app/?version=stable&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4AI6AT9dAD2IimZxl1N_WlkPinBFoVHoZHronELbdQu0EutpnLVEzwa0xCLMRcoDr3wSOFz0mMmeH3_Z22MV6N9gd19nEbYT0sl2gHUcW0_flq16VQMUk6UoCqMFuYzCskFaA8Sf_7k8Xczsu1OyGFaCPBL1fJ1npT5Q80SuweBlIL6dfj9vMginB_MF0K8jG1-SRkB1BGieVM0bfaEpUfg1mDgsh5ewrYVyHqsSK09hCamYduCzsb3Dd7IjymD79zNFMXLPTUNbrCGCXbeDtA0X3FfHGaOECPVVUnLZvBUf6qgqMiRPuNakPWI2XzfV_NtPCDyOb_luOaHVA9jwNwPvzcNQ5QXJY7oue2quTGxN7FNuTzMW5ZRZTcsS-XFX8JtdRjUhgDAf-9PY2MvaOMTJU-6VW_Q_y1WgkX8SS20_f8-aaIAAAHGKX4a9HSSAAAHbArsEAAAWChYMscRn-wIAAAAABFla)

**Expected behavior**

<!-- A clear and concise description of what you expected to happen. -->

**Environment**

<!-- Please complete the following information: -->

- Black's version: 2.33.0
- OS and Python version: MacOs 12.3/Python 3.10.2




Discussion:
I can't reproduce this. Make sure you're running Black itself under Python 3.10+ too:

```
% python -m black --target-version=py310 matchsamplebug.py
All done! ✨ 🍰 ✨
1 file left unchanged.
% python -m black --version
python -m black, 22.3.0 (compiled: no)
% python --version 
Python 3.11.0a6+
```
Thanks, that was the error indeed!
BTW it would be helpful to know with which is the Python version in the output of `black --version`
> BTW it would be helpful to know with which is the Python version in the output of `black --version`

Good point, reopening this issue to reflect that suggestion
Also it may be fair to issue an error or a warning if `--target-version` is py310 but isn't running with Python 3.10


Resolving patch:
diff --git a/src/black/__init__.py b/src/black/__init__.py
--- a/src/black/__init__.py
+++ b/src/black/__init__.py
@@ -10,6 +10,7 @@
 import os
 from pathlib import Path
 from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
+import platform
 import re
 import signal
 import sys
@@ -381,7 +382,10 @@ def validate_regex(
 )
 @click.version_option(
     version=__version__,
-    message=f"%(prog)s, %(version)s (compiled: {'yes' if COMPILED else 'no'})",
+    message=(
+        f"%(prog)s, %(version)s (compiled: {'yes' if COMPILED else 'no'})\n"
+        f"Python ({platform.python_implementation()}) {platform.python_version()}"
+    ),
 )
 @click.argument(
     "src",


Test patch: