PyCharm 2023.3 Help

Scope

A scope the Scope icon is a subset of files, packages and directories in your project, to which you can limit the application of specific operations, for example search, code inspection, etc . Besides, you can configure coloring for each scope to see at once what sort of file you are dealing with.

Scopes get more helpful as your project grows larger. There is a number of predefined scopes that cover basic cases. Additionally, it is possible to add custom scopes to your project. For example, you can create custom scopes for tests or for the files you are responsible for in your team.

Types of scopes

Scopes can be either shared or local:

  • Local scopes are intended for personal use only and are stored in your workspace in the workspace.xml file under .idea

    .

  • Shared scopes are accessible for the team members via VCS and are stored at the project level. in the scopes directory under .idea, as a file with the .xml extension, that is .idea/scopes/<scope_name>.xml.

You can quickly share a local scope (or make a shared scope local) by using the Store as project file checkbox on the Appearance & Behavior | Scopes page of the Settings dialog (Ctrl+Alt+S) . For more information about managing scopes, refer to Scopes and file colors.

Defining scopes

PyCharm provides a special language that enables you to flexibly define the sets of entities included in a scope.

For more information, refer to Scope language syntax reference.

To create and edit scopes, use the Scopes page of the Settings dialog.

Scopes are defined in the following modes:

  • Manually, by specifying file masks according to the scope language syntax in the Pattern field.

  • By selecting files and folders and clicking the buttons Include, Include Recursively, Exclude, and Exclude Recursively. Based on the inclusion/exclusion, PyCharm creates an expression and displays it in the Pattern.

    For more information, refer to Scopes and file colors.

To view the available scopes, click the the Down icon (next to the Project header of the Project tool window.

Scopes in the Project tool window

Scopes coloring

Files that belong to different scopes can be highlighted in different colors throughout the PyCharm's user interface: in navigation lists, in the editor tabs , in the Project tool window. This allows much faster and easier navigation in large projects.

Scope highlighting in the editor tabs and search results

If some file is included into several scopes, the order of the scopes becomes important: PyCharm uses the color of the uppermost scope (shown in the Scopes settings page) to highlight such file. Of course, you can change the order of the scopes, and thus the resulted highlighting.

For more information about configuring the scope order and scope-color associations, refer to Scopes and file colors.

Predefined scopes

PyCharm provides a number of predefined scopes, for example:

  • Project Files. This scope includes all the files within the project content roots (refer to Content root). External libraries, generally, are not included in this scope.

  • Problems. This scope includes the files within the project content roots in which syntactic errors are found.

  • Open files .This scope corresponds to the files opened in PyCharm editor.

  • Scratches and Consoles. This scope includes project scratch files and consoles content.

Predefined scopes cannot be edited.

Last modified: 11 February 2024