question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If mypy fails and only prints to stdout, not stderr, this leads to a cryptic event log message without details or stacktrace

See original GitHub issue

Step 1: Are you in the right place?

  • I have verified there are no duplicate active or recent bugs, questions, or requests
  • I have verified that I am using the latest version of the plugin.

Step 2: Describe your environment

  • Plugin version: 0.14.0
  • PyCharm/IDEA version: 2021.3.2 (Build 213.6777.50)
  • Mypy version: 0.931
  • Python version: 3.10.2 <-- note python 3.10

Step 3: Describe the problem:

Steps to reproduce:

  1. use a match statement
  2. use the plugin to run mypy on that file

Observed Results:

Error in event log (see below)

Expected Results:

  • plain error report of mypy result as with other mypy violations, instead of plugin crash
  • detailed information about what caused the error

Relevant Code:

MWE:

def print_hi(name):
    match name:
        case "Mypy":
            print("Doesn't work")
        case _:
            print(f'Hi, {name}')


if __name__ == '__main__':
    print_hi('PyCharm')
Mypy Plugin (Mypy exited abnormally)

The scan failed due to an exception: Mypy failed with code 2 
com.leinardi.pycharm.mypy.exception.MypyToolException: Mypy failed with code 2
   at com.leinardi.pycharm.mypy.mpapi.MypyRunner.runMypy(MypyRunner.java:324)
   at com.leinardi.pycharm.mypy.mpapi.MypyRunner.scan(MypyRunner.java:266)
   at com.leinardi.pycharm.mypy.checker.ScanFiles.scan(ScanFiles.java:109)
   at com.leinardi.pycharm.mypy.checker.ScanFiles.checkFiles(ScanFiles.java:100)
   at com.leinardi.pycharm.mypy.checker.ScanFiles.call(ScanFiles.java:74)
   at com.leinardi.pycharm.mypy.checker.ScanFiles.call(ScanFiles.java:46)
   at com.intellij.openapi.application.impl.ApplicationImpl$2.call(ApplicationImpl.java:294)
   at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
   at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
   at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
   at java.base/java.security.AccessController.doPrivileged(Native Method)
   at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
   at java.base/java.lang.Thread.run(Thread.java:829)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
intgrcommented, Mar 10, 2022

If you point me to the correct file(s), I’d be happy to prepare a PR.

Thanks, any help would be welcome. The error handling logic lives in the MypyRunner.runMypy() method – see the diffs in https://github.com/leinardi/mypy-pycharm/pull/92/files

1reaction
christian-steinmeyercommented, Mar 10, 2022

If I run mypy --show-column-numbers --follow-imports silent <FILE> from the same virtual env and directory, mypy runs, and doesn’t crash, but finds an error (Match statement not supported). Aaaaand there we go, that seems to be the issue.

In a MWE in the same environment, this yields the same error:

def print_hi(name):
    match name:
        case "Mypy":
            print("Doesn't work")
        case _:
            print(f'Hi, {name}')


if __name__ == '__main__':
    print_hi('PyCharm')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · leinardi/mypy-pycharm - GitHub
If mypy fails and only prints to stdout, not stderr, this leads to a cryptic event log message without details or stacktrace.
Read more >
How do I print to stderr in Python? - Stack Overflow
I found this to be the only one short, flexible, portable and readable: import sys def eprint(*args, **kwargs): print(*args, file=sys.stderr ...
Read more >
Write better error messages - Hacker News
Just use both. A globally unique but static "error code" to google plus a serial number of that distinct instance of the failure....
Read more >
structlog Documentation
structlog is the production-ready logging solution for Python: • Simple: At its core, everything is about functions that take and return dictionaries –...
Read more >
Changelog — Python 3.5.9 documentation
TextCalendar().prmonth() no longer prints a space at the start of new line ... Python startup if the file descriptor of stdin (0), stdout...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found