Help us understand the problem. What is going on with this article?

type comment 形式の変数アノテーションでは ignore 型が記述できない

とてもどうでもいいことに気づきました。

実際に試してみた

これが

class ignore:
    pass


class Ignore:
    pass


foo = 1  # type: ignore
bar = 1  # type: Ignore

こうじゃ

$ mypy test.py
test.py:10: error: Incompatible types in assignment (expression has type "int", variable has type "Ignore")
Found 1 error in 1 file (checked 1 source file)

foo はエラーになりません。

変数アノテーションとして書くとうまく動く

class ignore:
    pass


class Ignore:
    pass


foo: ignore = 1
bar: Ignore = 1
$ mypy test.py
test.py:9: error: Incompatible types in assignment (expression has type "int", variable has type "ignore")
test.py:10: error: Incompatible types in assignment (expression has type "int", variable has type "Ignore")
Found 2 errors in 1 file (checked 1 source file)

まとめ

type_comment 形式の型アノテーションはもう使うのをやめましょう。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした