Skip to main content

Mypy daemon extension for Python IDLE

Project description

IdleMypyExtension

Python IDLE extension to perform mypy analysis on an open file

CI

pre-commit.ci status pre-commit code style: black Ruff

What does this extension do?

This IDLE extension hooks into the mypy daemon to type check the currently open file or provide a function signature suggestion for the nearest function to the top from the current input cursor location. When type checking the currently open file with the "Type Check File" command, it will add comments to your code wherever mypy had something to say about about that line. You can remove type comments from the currently selected text with the "Remove Type Comments" command. Additionally, you can jump to the next comment this extension created in your file with the "Find Next Type Comment" command. Finally, you can add an inferred function signature to your file with the "Suggest Signature" command when you are close by a function definition.

Note: On use, creates folder mypy within the idle user directory. On Linux systems, this is usually ~/.idlerc/mypy.

Installation (Without root permissions)

  1. Go to terminal and install with pip install idlemypyextension[user].
  2. Run command idleuserextend; idlemypyextension. You should see the following output: Config should be good! Config should be good!.
  3. Open IDLE, go to Options -> Configure IDLE -> Extensions. If everything went well, alongside ZzDummy there should be and option called idlemypyextension. This is where you can configure how idlemypyextension works.

Installation (Legacy, needs root permission)

  1. Go to terminal and install with pip install idlemypyextension.
  2. Run command idlemypyextension. You will likely see a message saying idlemypyextension not in system registered extensions!. Run the command given to add idlemypyextension to your system's IDLE extension config file.
  3. Again run command idlemypyextension. This time, you should see the following output: Config should be good!.
  4. Open IDLE, go to Options -> Configure IDLE -> Extensions. If everything went well, alongside ZzDummy there should be and option called idlemypyextension. This is where you can configure how idlemypyextension works.

Information on options

action_max_sec controls how long an action is allowed to take at most, in seconds. Default is "None".

For daemon_flags, see mypy --help for a list of valid flags. This extension sets the following flags to be able to work properly:

    --hide-error-context
    --no-color-output
    --show-absolute-path
    --no-error-summary
    --soft-error-limit=-1
    --show-traceback
    --cache-dir="~/.idlerc/mypy"

If you add the --show-column-numbers flag to daemon_flags, when using the "Type Check File" command, it will add a helpful little ^ sign in a new line below the location of the mypy message that provided a column number, as long as that comment wouldn't break your file's indentation too much.

If you add the --show-error-codes flag to daemon_flags, when using the "Type Check File" command, when it puts mypy's comments in your code, it will tell you what type of error that comment is. For example, it would change the error comment

# types: error: Incompatible types in assignment (expression has type "str", variable has type "int")

to

# types: assignment error: Incompatible types in assignment (expression has type "str", variable has type "int")

search_wrap toggles weather searching for next type comment will wrap around or not.

suggest_replace toggles weather Suggest Signature will replace the existing function definition or just add a comment with the suggested definition

timeout_mins controls how long the mypy daemon will time out after, in minutes.

Annotating files from mypy error logs

I kept running into cases a lot where CI systems generate mypy error logs, and I needed to fix those errors with my local copy. If you copy all the mypy errors into a file, say error.txt, you can have idlemypyextension annotate all of those files with a command like this:

idlemypyextension error.txt

which will open a blank IDLE window, hook into idlemypyextension, have it add annotations to all files referenced in error log file, and then close that temporary blank window, leaving all the files with errors still open.

Links

License


Code and documentation are available according to the GNU General Public License v3.0 (see LICENSE).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

idlemypyextension-1.1.0.tar.gz (83.6 kB view details)

Uploaded Source

Built Distribution

idlemypyextension-1.1.0-py3-none-any.whl (69.5 kB view details)

Uploaded Python 3

File details

Details for the file idlemypyextension-1.1.0.tar.gz.

File metadata

  • Download URL: idlemypyextension-1.1.0.tar.gz
  • Upload date:
  • Size: 83.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for idlemypyextension-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ccfd92996c5dbf3d10c4d10f91b0e73460efe82238348add0b5633d5ae1010e8
MD5 6ce110cfc3e975316bb0a50ea5d64cc7
BLAKE2b-256 a456361780bf8a95616584ad7167fea09c80a8241db9bd4979e2513c932ec415

See more details on using hashes here.

Provenance

The following attestation bundles were made for idlemypyextension-1.1.0.tar.gz:

Publisher: python-publish.yml on CoolCat467/idlemypyextension

Attestations:

File details

Details for the file idlemypyextension-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for idlemypyextension-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a40a4be94bf3d56195c0786f4bbfe845b4467f2517135931e7d7df190d2b747
MD5 2c5ecf09664dad80caa7182533965af7
BLAKE2b-256 e6ba22a8173193c44059d6e6ab7f50e41a46c80bb1126b1d8220cb95ef787e4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for idlemypyextension-1.1.0-py3-none-any.whl:

Publisher: python-publish.yml on CoolCat467/idlemypyextension

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page