简体   繁体   中英

Why does PyCharm throw type-hint wigglies when I decorate a nested class with `@dataclass`?

I am using Python's support for nested classes to group and organise class definitions. Some of these inner classes are pure data classes and I am benefitting from the boilerplate reduction of @dataclass ( __init__ , __repr__ etc).

Unfortunately, when I try to create an instance of the inner class, PyCharm can't seem to get the arguments' type hinting correct and puts a wigglie (wiggly line indicating, usually, poor code) under the first argument. Note that:

  • The code runs fine, this is just an issue with type hinting.
  • @dataclass on a module level class produces no such issue.
  • Removing @dataclass and manually inserting the boilerplate for __init__

Here is a screenshot of the code with PyCharm's warning: 在此处输入图像描述

It is a bug, please vote for https://youtrack.jetbrains.com/issue/PY-35698 (thumbs up near the title)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM