0
0

VScodeで型ヒントのパイプ表記が利用できないとき

Last updated at Posted at 2024-07-25

現象

  • VScode上でのデバッグ時、下記コードのint | Noneの箇所でエラーが起きる
def double(arg: int = 1) -> int | None:

エラー文言
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

  • ローカルにインストールされているPythonのバージョンは3.12.4である

原因

  • VScodeで利用しているPythonインタプリタのバージョンが3.8のままだった

対処

image.png

image.png

image.png

上記でVScodeのPythonインタプリタのバージョンを3.10以降に変更することで、
エラーが出ることなく実行できるようになった

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0