author : Jean-Yves Mengant

Python Hints And Quick Fixes

As many other languages in Netbeans, the Python editor supports pluggable quickfixes and hints. Accessing the Python hints configuration is straightforward from the Netbeans MainMenu :

select Tools/Options/Editor select Python as the language

The Python available hints will be displayed as follow :

Hints in dynamic languages

In dynamic languages like Python, the role of hints feature is more important than in compiled languages(like C++ or java) : since you do not have any visible compiler step to check your errors, you need a complementary tool to check your code : hints feature comes to the rescue dynamically pinpointing errors , warnings or informations while you're typing. In this ways hint tools inside an IDE like Netbeans may be compared to kind of dynamic 'lint' features made available from inside the editor

The list of available hints is far from being frozen and new hints will be added in the near future to provide more and more dynamic coding facilities ; the only limit for hints implementors is do reasonable syntax/semantic controls to keep the Python editor responsive.

Please contribute your ideas there or via the issue tracker for new Hints.

Standard Hints

Symbol defined in
does not exist

python variable is used inside a module to defined public symbols exposed by the module ; this implies that all names located inside the {all} list must be existing symbols. Here's the editor showing a snippet which has a code fragment containing a
builtin containing undefined names

Assign expression to a variable

This warning is issued as soon as you have an orphan expression on a python line source which would be better assign to a local or global variable ; for instance in the screen shot below not assigning the expression 2+3 on line 7 to a variable does not make any sense at all

Find unused imports

A warning is issued by this hint when an imported python module is no used in a given python source


  • removes the unused import
  • removes all unused imports

Multiple imports per import statement is discouraged

Cleanly separating python imports using one import statement per import is a recommended coding style , this hint issues a warning and proposes to reformat the imports as a fix.

Access protected attributes

By convention attributes starting with a single
are assumed to be protected in Python.

This hint issues a warning when protected class attributes are acceded by non child classes.

Parent Child circular redundancy

This hint shows an error (you can switch it to a warning by decreasing this hint severity option) as soon as a circular redundancy is detected in parent / child relationships of python classes.

NB : the case may be more intricated than the simple one showed by the code fragment below

Document comment

When defining a function , a class or a method activating this hint provides the opportunity to create associated documentations using different fixes options :


  • add a one liner docstring
  • add a multi liner docstring
  • preview the chosen option

Naming convention

The naming convention hint is there to facilitate the python coding rules as defined by PEP-008 Complementary options for this hint may be customized from the hints option panel.

As soon a naming convention rule is violated inside a python source a warning is issued as shown below and replacement alternatives are provided accordingly

Relative imports for intra packages imports are actively discouraged

Relative imports are imports whose imported package start with at least one '.' are defined as relative to the package containing the import statement (example : from .foo import name ) Most of the time relative imports are ambiguous an decrease the readability of your code and it's better to avoid them.

This hints will warn when such imports are encountered


When checked the deprecated hints warns as soon as an obsolete (deprecated) python package is used inside a python module

The following code sample shows the problem:

Attribute defined outside

clean definitions of class attributes are achieved by initing then in the init class constructor This hints tracks for class attributes which are not inited in the init method.

Find unused variables

This hint is very useful to cleanup your code by detecting the variables that have been assigned a value and which are not been used again , or defined function arguments which are never used inside the function unused function or method argument are just underlined by the editor.

Find unresolved class attributes and parentages

This hint locates class attributes which are used in expression without being previously initted and also the unresolved parent classes in children declarations

Find undefined names

This hint locates variables which have been used but have never been initted to a value
Tor has provided a more detailed example about unused variables on his blog here

Selection hints

Extract Code

The Extract Code hint applies to text selection. If you select a set of lines, you will get a lightbulb which offers to extract the code into a separate method. In other words, this is an Extract Method refactoring. In addition to the option of applying the extract method operation, you have the option of previewing the refactoring which will bring up a diff view showing the extracted method and the call site modification.

Once you run the extract method refactoring, you are placed in instant rename refactoring mode where you can enter the new name of the method and press return to commit.

Surround With

The Surround With refactoring is a text selection hint, like Extract Code above. As soon as you've selected a set of lines, a lightbulb is shown which when clicked on (or when you press Alt Enter) allows you to choose between several surround-with options. You can surround the set of lines with try/except, try/finally, and so on. There is also an option to preview the operation.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo