Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@tk0miya

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

More than 1 year has passed since last update.

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

実際に試してみた

これが

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 形式の型アノテーションはもう使うのをやめましょう。

2
Help us understand the problem. What is going on with this article?
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
tk0miya
timedia
創業20周年の技術者集団。 確かな技術力・豊富な実績をもとに、多種多様な案件を手掛けるシステム会社のパイオニア

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?