PyCharm 4.0.0 Web Help

PyCharm helps you handle the situations when you use classes that haven't been imported, or methods that haven't been written etc., which can result in errors. When a possible problem is suspected, PyCharm suggests a solution, and in certain cases can implement this solution (properly assign variables, create missing references and more). Besides syntax problems, PyCharm recognizes code constructs that can be optimized or improved, and suggests appropriate intention actions, denoted with the special icons.

One this page:

    In this section:

    Intention action icons

    Item Icon Description
    Intention actions suggested intentionBulb.png A yellow bulb indicates that PyCharm just proposes to alter your code. It covers a range of situations from warning correction to suggestions for code improvement (like micro-refactorings).
    Specific intention action icon_intentionActionEnabled.png This sign appears in the suggestion list before each specific intention action. If an intention action alert is disabled, the sign turns to icon_intentionActionDisabled.png. Disabled intention action is still available and can be enabled again.
    Quick-fix suggested quickfixBulb.png A red bulb with an exclamation mark indicates that PyCharm suggests a way to fix an error. It is related to Create from usage intentions and Quick fixes.
    Disabled intentionBulbGrey Alert is disabled, but the intention action is still available and can be enabled again.

    Intention action types

    Find descriptions of specific intention actions on the Intentions page of the Settings dialog, where they are grouped according to the areas of their usage. Generally, intention actions can be divided into several categories, for example:

    Create from usage
    This type of intention action creates new code items: classes, methods, etc. They are smart enough to analyze your code and provide actions suitable for a particular case. The main concept behind this type is that you can begin using new things without declaring them first. You are not taken away from your current task for mundane minutiae like creating declarations, new files, etc. which PyCharm handles while you keep focused.

    For example, if you refer to a non-existent symbol, PyCharm suggests you to create one:

    python_createFromUsage

    Quick fixes
    This type of intention action responds to common coding mistakes: using an improper access modifier, or an expression of the wrong type, or missing resources, etc. PyCharm catches these kinds of problems as you type, and provides a quick way to fix them using Intentions Actions with appropriate suggestions for the error.

    intentionActionExternalResource.png

    4.0+

    It is a common practice to delay import of a symbol to the point where it is actually used. For this purpose, PyCharm suggests a dedicated quick fix Import this name locally:

    python_import_locally

    Micro-refactorings
    These intention actions appear for code that is syntactically correct, but can be structurally improved by such things as:

    - Converting code constructs.
    - Splitting declarations and assignments.
    - Splitting or merging statements and tags, etc.

    • Convert lambda to function. A lambda function can be turned into def statements:

      py_lambda

    • Split/join if's. PyCharm provides two inverse intention actions: split if statement into two, and join the nested if statements provided that only the inner one contains code:

      py_joinifs

    • Marking an unresolved variable as global, to have it ignored in the future. This can be done "on-the-fly":
      py_ignore_variable
      or in the inspection settings:
      py_ignore_variable_in_settings
    • 1.2+Converting parameters between normal and variadic:

      py_convert_variadic

    Edit <Injected Language> Fragment
    For string literals that represent language injections, the Edit <Injected Language> Fragment intention action is available. You can use this intention action to open the corresponding code fragment in a separate editor.

    editInjectedLanguageFragmentIntention.png

    See Also

    Concepts:

    Reference:

    Web Resources: