dropbox / mypy-PyCharm-plugin

A simple plugin that allows running mypy from PyCharm and navigate between errors
Apache License 2.0
313 stars 14 forks source link

java.lang.NullPointerException #15

Closed leinardi closed 5 years ago

leinardi commented 5 years ago

The plugin crashes with a NPE with this mypy output:

gsi/model.py:101:5: error: Function is missing a type annotation
gsi/model.py:111:5: error: Function is missing a type annotation
gsi/model.py:119:5: error: Function is missing a type annotation
gsi/model.py:160:5: error: Function is missing a type annotation
gsi/model.py:169:80: error: Call to untyped function "Processor" in typed context
gsi/model.py:174:5: error: Function is missing a type annotation
gsi/model.py:187:5: error: Function is missing a type annotation
gsi/model.py:195: error: Function is missing a type annotation
gsi/model.py:196:34: error: Call to untyped function "CpuInfo" in typed context
gsi/model.py:197:36: error: Call to untyped function "MoboInfo" in typed context
gsi/repository.py:43:1: error: Function is missing a type annotation
gsi/repository.py:72:1: error: Function is missing a type annotation
gsi/repository.py:79: error: Function is missing a type annotation
gsi/repository.py:87:9: warning: Returning Any from function declared to return "Optional[CpuDbModel]"
gsi/repository.py:93: error: The return type of "__init__" must be None
gsi/repository.py:93: error: Function is missing a return type annotation
gsi/repository.py:98: error: Function is missing a type annotation for one or more arguments
gsi/repository.py:124:5: error: Function is missing a return type annotation
gsi/repository.py:139:9: error: Incompatible types in assignment (expression has type "None", variable has type "Processor")
gsi/repository.py:146:38: error: Call to untyped function "Processor" in typed context
gsi/repository.py:148:17: error: Call to untyped function "__parse_data" in typed context
gsi/repository.py:157:17: error: Argument 2 to "__update_processor_with_cpu" of "ProcCpuinfoRepository" has incompatible type "Optional[CpuDbModel]"; expected "CpuDbModel"
gsi/repository.py:167:5: error: Function is missing a type annotation
gsi/repository.py:178:47: error: Call to untyped function "clean_cpu_string" in typed context
gsi/repository.py:183: error: Function is missing a return type annotation
gsi/repository.py:206: error: Function is missing a type annotation
gsi/repository.py:213:5: error: Function is missing a return type annotation
gsi/repository.py:230:17: error: Call to untyped function "__read_cache_info" in typed context
gsi/repository.py:233:19: error: Call to untyped function "__update_cache_count" in typed context
gsi/repository.py:243: error: Function is missing a type annotation
gsi/repository.py:245:21: error: Call to untyped function "Cache" in typed context
gsi/repository.py:265: error: Function is missing a type annotation
gsi/repository.py:266:9: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:267:9: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:268:9: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:269:9: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:294: error: Function is missing a type annotation
gsi/repository.py:301:5: error: Function is missing a return type annotation
gsi/util.py:109:5: warning: Returning Any from function declared to return "Optional[str]"
gsi/util.py:144: error: Syntax error in type annotation
gsi/util.py:144: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
gsi/interactor.py:32: error: The return type of "__init__" must be None
gsi/interactor.py:32: error: Function is missing a return type annotation
gsi/interactor.py:45: error: The return type of "__init__" must be None
gsi/interactor.py:45: error: Function is missing a return type annotation
gsi/interactor.py:58: error: The return type of "__init__" must be None
gsi/interactor.py:58: error: Function is missing a return type annotation
gsi/interactor.py:70: error: Function is missing a type annotation
gsi/interactor.py:73:5: error: Function is missing a type annotation
gsi/presenter.py:35:5: error: Function is missing a type annotation
gsi/presenter.py:38:5: error: Function is missing a type annotation
gsi/presenter.py:41:5: error: Function is missing a type annotation
gsi/presenter.py:44:5: error: Function is missing a return type annotation
gsi/presenter.py:47:5: error: Function is missing a return type annotation
gsi/presenter.py:50:5: error: Function is missing a type annotation
gsi/presenter.py:53:5: error: Function is missing a type annotation
gsi/presenter.py:56:5: error: Function is missing a type annotation
gsi/presenter.py:59:5: error: Function is missing a type annotation
gsi/presenter.py:66: error: The return type of "__init__" must be None
gsi/presenter.py:66: error: Function is missing a return type annotation
gsi/presenter.py:74:9: error: Incompatible types in assignment (expression has type "None", variable has type "ViewInterface")
gsi/presenter.py:81:5: error: Function is missing a type annotation
gsi/presenter.py:96:5: error: Function is missing a type annotation
gsi/presenter.py:109:5: error: Function is missing a type annotation
gsi/presenter.py:112:5: error: Function is missing a type annotation
gsi/presenter.py:115:5: error: Function is missing a type annotation
gsi/presenter.py:118:5: error: Function is missing a type annotation
gsi/presenter.py:121:5: error: Function is missing a type annotation
gsi/presenter.py:124:5: error: Function is missing a type annotation
gsi/presenter.py:127:5: error: Function is missing a type annotation
gsi/presenter.py:143: error: Function is missing a type annotation for one or more arguments
gsi/view.py:40: error: The return type of "__init__" must be None
gsi/view.py:40: error: Function is missing a return type annotation
gsi/view.py:50:9: error: Call to untyped function "__init_widgets" in typed context
gsi/view.py:52:5: error: Function is missing a type annotation
gsi/view.py:62:5: error: Function is missing a type annotation
gsi/view.py:65:5: error: Function is missing a type annotation
gsi/view.py:73:5: error: Function is missing a type annotation
gsi/view.py:78:5: error: Function is missing a type annotation
gsi/view.py:82:5: error: Function is missing a return type annotation
gsi/view.py:85:13: error: Call to untyped function "init_system_info" in typed context
gsi/view.py:87:5: error: Function is missing a return type annotation
gsi/view.py:90:13: error: Call to untyped function "init_system_info" in typed context
gsi/view.py:92:5: error: Function is missing a type annotation
gsi/view.py:95:5: error: Function is missing a type annotation
gsi/view.py:98:5: error: Function is missing a type annotation
gsi/view.py:101:5: error: Function is missing a type annotation
gsi/view.py:104:5: error: Function is missing a return type annotation
gsi/view.py:127:13: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:133:13: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:139:13: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:145:13: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:170:5: error: Function is missing a return type annotation
gsi/view.py:182:5: error: Function is missing a return type annotation
gsi/view.py:194:5: error: Function is missing a return type annotation
gsi/view.py:205:5: error: Function is missing a return type annotation
gsi/view.py:216:5: error: Function is missing a return type annotation
gsi/view.py:225:5: error: Function is missing a return type annotation
gsi/view.py:240:5: error: Function is missing a return type annotation
gsi/view.py:256:5: error: Function is missing a return type annotation
gsi/app.py:33: error: The return type of "__init__" must be None
gsi/app.py:33: error: Function is missing a return type annotation
gsi/app.py:33: error: Function is missing a type annotation for one or more arguments
gsi/app.py:54:5: error: Function is missing a type annotation
gsi/app.py:64:5: error: Function is missing a type annotation
gsi/app.py:67:5: error: Function is missing a type annotation

Stacktrace:

java.lang.NullPointerException
    at javax.swing.JComponent.scrollRectToVisible(JComponent.java:3109)
    at com.dropbox.plugins.mypy_plugin.MypyRunner.runMypyDaemon(MypyRunner.java:86)
    at com.dropbox.plugins.mypy_plugin.MypyTerminal$10.run(MypyTerminal.java:344)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

mypy.ini

[mypy]
# Specify the target platform details in config, so your developers are
# free to run mypy on Windows, Linux, or macOS and get consistent
# results.
python_version=3.6
platform=linux

show_column_numbers=True

# show error messages from unrelated files
follow_imports=skip

# suppress errors about unsatisfied imports
ignore_missing_imports=True

# be strict
disallow_untyped_calls=True
warn_return_any=True
strict_optional=True
warn_no_return=True
warn_redundant_casts=True
warn_unused_ignores=True

# The following are off by default.  Flip them on if you feel
# adventurous.
disallow_untyped_defs=True
check_untyped_defs=True

# No incremental mode
cache_dir=/dev/null

PyCharm 2018.2.1 (Community Edition) Build #PC-182.3911.33, built on August 5, 2018 JRE: 1.8.0_152-release-1248-b8 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.15.0-32-generic

ilevkivskyi commented 5 years ago

Thanks for reporting!

My first guess is that you use show_column_numbers = True and mypy still doesn't report column numbers for some errors. Could you please try if you can reproduce the crash with show_column_numbers = False?

leinardi commented 5 years ago

Hey thanks for the quick reply!

Yep, show_column_numbers = False fixed the crash :+1:

leinardi commented 5 years ago

Oh wait, now is crashing again...

This is the output (show_column_numbers still False):

gsi/presenter.py:93: error: "init_system_info" of "ViewInterface" does not return a value
gsi/presenter.py:94: error: "__start_refresh" of "Presenter" does not return a value
gsi/presenter.py:111: error: Function is missing a type annotation for one or more arguments
gsi/presenter.py:114: error: Function is missing a type annotation for one or more arguments
gsi/presenter.py:117: error: Function is missing a type annotation for one or more arguments
gsi/presenter.py:120: error: Function is missing a type annotation
gsi/presenter.py:123: error: Function is missing a type annotation
gsi/presenter.py:126: error: Function is missing a type annotation
gsi/presenter.py:129: error: Function is missing a type annotation
gsi/presenter.py:145: error: Function is missing a type annotation for one or more arguments
gsi/interactor.py:32: error: The return type of "__init__" must be None
gsi/interactor.py:32: error: Function is missing a return type annotation
gsi/interactor.py:45: error: The return type of "__init__" must be None
gsi/interactor.py:45: error: Function is missing a return type annotation
gsi/interactor.py:58: error: The return type of "__init__" must be None
gsi/interactor.py:58: error: Function is missing a return type annotation
gsi/interactor.py:73: error: Function is missing a type annotation
gsi/repository.py:43: error: Function is missing a type annotation
gsi/repository.py:72: error: Function is missing a type annotation
gsi/repository.py:87: warning: Returning Any from function declared to return "Optional[CpuDbModel]"
gsi/repository.py:93: error: The return type of "__init__" must be None
gsi/repository.py:93: error: Function is missing a return type annotation
gsi/repository.py:98: error: Function is missing a type annotation for one or more arguments
gsi/repository.py:124: error: Function is missing a return type annotation
gsi/repository.py:139: error: Incompatible types in assignment (expression has type "None", variable has type "Processor")
gsi/repository.py:148: error: Call to untyped function "__parse_data" in typed context
gsi/repository.py:156: error: Argument 1 to "get_cpu_by_name" of "CpuDatabaseRepository" has incompatible type "Optional[str]"; expected "str"
gsi/repository.py:157: error: Argument 2 to "__update_processor_with_cpu" of "ProcCpuinfoRepository" has incompatible type "Optional[CpuDbModel]"; expected "CpuDbModel"
gsi/repository.py:167: error: Function is missing a type annotation
gsi/repository.py:178: error: Call to untyped function "clean_cpu_string" in typed context
gsi/repository.py:183: error: Function is missing a return type annotation
gsi/repository.py:213: error: Function is missing a return type annotation
gsi/repository.py:230: error: Call to untyped function "__read_cache_info" of "SysDevicesCacheRepository" in typed context
gsi/repository.py:233: error: Call to untyped function "__update_cache_count" of "SysDevicesCacheRepository" in typed context
gsi/repository.py:243: error: Function is missing a type annotation
gsi/repository.py:265: error: Function is missing a type annotation
gsi/repository.py:266: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:267: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:268: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:269: error: Incompatible types in assignment (expression has type "None", variable has type "Cache")
gsi/repository.py:275: error: Unsupported operand types for + ("Optional[int]" and "int")
gsi/repository.py:279: error: Unsupported operand types for + ("Optional[int]" and "int")
gsi/repository.py:283: error: Unsupported operand types for + ("Optional[int]" and "int")
gsi/repository.py:287: error: Unsupported operand types for + ("Optional[int]" and "int")
gsi/repository.py:301: error: Function is missing a return type annotation
gsi/util.py:109: warning: Returning Any from function declared to return "Optional[str]"
gsi/util.py:130: error: Incompatible types in string interpolation (expression has type "Optional[int]", placeholder has type "Union[int, float]")
gsi/util.py:132: error: Unsupported left operand type for * (some union)
gsi/util.py:132: error: Unsupported operand types for * (likely involving Union)
gsi/util.py:136: error: Incompatible types in string interpolation (expression has type "Optional[int]", placeholder has type "Union[int, float]")
gsi/util.py:140: error: Incompatible types in string interpolation (expression has type "Optional[int]", placeholder has type "Union[int, float]")
gsi/util.py:144: error: Syntax error in type annotation
gsi/util.py:144: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn)
gsi/view.py:40: error: The return type of "__init__" must be None
gsi/view.py:40: error: Function is missing a return type annotation
gsi/view.py:50: error: Call to untyped function "__init_widgets" in typed context
gsi/view.py:52: error: Function is missing a type annotation
gsi/view.py:65: error: Function is missing a type annotation
gsi/view.py:73: error: Function is missing a type annotation
gsi/view.py:78: error: Function is missing a type annotation
gsi/view.py:82: error: Function is missing a return type annotation
gsi/view.py:85: error: Call to untyped function "init_system_info" in typed context
gsi/view.py:87: error: Function is missing a return type annotation
gsi/view.py:90: error: Call to untyped function "init_system_info" in typed context
gsi/view.py:92: error: Function is missing a type annotation
gsi/view.py:95: error: Function is missing a type annotation
gsi/view.py:98: error: Function is missing a type annotation
gsi/view.py:101: error: Function is missing a type annotation
gsi/view.py:104: error: Function is missing a return type annotation
gsi/view.py:121: error: Incompatible types in string interpolation (expression has type "Optional[float]", placeholder has type "Union[int, float]")
gsi/view.py:123: error: Argument 1 to "format_cache_size" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:124: error: Argument 1 to "format_cache_ways" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:125: error: Argument 1 to "format_cache_sets" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:127: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:129: error: Argument 1 to "format_cache_size" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:130: error: Argument 1 to "format_cache_ways" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:131: error: Argument 1 to "format_cache_sets" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:133: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:135: error: Argument 1 to "format_cache_size" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:136: error: Argument 1 to "format_cache_ways" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:137: error: Argument 1 to "format_cache_sets" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:139: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:141: error: Argument 1 to "format_cache_size" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:142: error: Argument 1 to "format_cache_ways" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:143: error: Argument 1 to "format_cache_sets" has incompatible type "Optional[Cache]"; expected "Cache"
gsi/view.py:145: error: Argument 2 to "__set_entries_with_label_text" of "View" has incompatible type "Dict[str, Optional[str]]"; expected "Dict[str, str]"
gsi/view.py:149: error: Incompatible types in string interpolation (expression has type "Optional[float]", placeholder has type "Union[int, float]")
gsi/view.py:150: error: Argument 1 to "__setup_flags_widgets" of "View" has incompatible type "Optional[List[str]]"; expected "List[str]"
gsi/view.py:151: error: Argument 1 to "__setup_bugs_widgets" of "View" has incompatible type "Optional[List[str]]"; expected "List[str]"
gsi/view.py:170: error: Function is missing a return type annotation
gsi/view.py:182: error: Function is missing a return type annotation
gsi/view.py:194: error: Function is missing a return type annotation
gsi/view.py:205: error: Function is missing a return type annotation
gsi/view.py:209: error: Invalid index type "Optional[int]" for "List[Dict[int, Processor]]"; expected type "int"
gsi/view.py:216: error: Function is missing a return type annotation
gsi/view.py:225: error: Function is missing a return type annotation
gsi/view.py:240: error: Function is missing a return type annotation
gsi/view.py:256: error: Function is missing a return type annotation
java.lang.NullPointerException
    at javax.swing.JComponent.scrollRectToVisible(JComponent.java:3109)
    at com.dropbox.plugins.mypy_plugin.MypyRunner.runMypyDaemon(MypyRunner.java:86)
    at com.dropbox.plugins.mypy_plugin.MypyTerminal$10.run(MypyTerminal.java:344)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
leinardi commented 5 years ago

Mmm this is weird: if I stop dmypy, restart PyCharm, it works only the first time (if I press run again it crashes).

I was starting the scan with dmypy run -- ``--config-file=mypy.ini gsi. Now I added dmypy start on front and it seems to work fine! (dmypy start; dmypy run -- ``--config-file=mypy.ini gsi).

Any idea why?

ilevkivskyi commented 5 years ago

I actually never tried it with dmypy run. I typically do dmypy start <options> ; dmypy check <target>. dmypy run supposed to be equivalent to the former, but maybe there is a subtle difference, I need to investigate.

leinardi commented 5 years ago

I was not able to use the --config-file=mypy.ini option using the check parameter.

Off topic question: I am trying to build this plugin myself but, I have imported it on my IntelliJ IDEA and I am able to build using the green hummer icon, but how can I test my build on PyCharm?

Edit: Never mind, I just had to select Build | Prepare Plugin Module ‘’ for Deployment.

ilevkivskyi commented 5 years ago

I think I finally understand why it crashes. On this line if there were no debug output from the daemon (like Daemon started, or Daemon is already running, etc.), then max will be zero, and getCellBounds returns null in this case instead of an empty rectangle.

This should be easy to fix, we just need to make this call conditional on max > 0.