Skip to content

Simplify overriding selective evaluation policy settings for modules - #14943

Merged
krassowski merged 4 commits into
ipython:mainfrom
krassowski:easier_policy_overrides
Aug 7, 2025
Merged

krassowski merged 4 commits into
ipython:mainfrom
krassowski:easier_policy_overrides

Conversation

@krassowski

Copy link
Copy Markdown
Member

References

Code changes

  • allow to pass module-level allow list for attribute evaluation
  • allows to pass allow-lists using dotted paths rather than tuples; this is especially helpful to avoid a common mistake of passing ("my") where ("my", ) would have been expected before
  • fixes issue with invalid prefix trimming which came up again when writing tests for this PR

User-facing changes

It is now possible to enable eager attribute evaluation in completer on an entire package with:

c.Completer.policy_overrides = {
    "allowed_getattr_external": {
        "my_trusted_library"
    }
}

@krassowski krassowski added this to the 9.5 milestone Jul 19, 2025
@krassowski
krassowski marked this pull request as ready for review July 19, 2025 12:40
@krassowski
krassowski requested a review from Copilot August 5, 2025 16:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR simplifies the configuration of selective evaluation policy settings for modules by allowing module-level allow lists and supporting dotted path notation. The main goal is to make it easier to enable eager attribute evaluation for entire packages without having to specify individual components as tuples.

Key changes:

  • Allow dotted string paths (e.g., "my.trusted.library") in addition to tuple paths for specifying allowed modules
  • Add support for module-level allow lists that apply to all submodules and objects within a package
  • Fix prefix trimming issues in expression evaluation that could cause incorrect behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/test_completer.py Adds comprehensive test coverage for module-level allow list functionality and prefix trimming fixes
IPython/core/guarded_eval.py Implements dotted path coercion, enhanced module resolution for namespace packages, and improved type checking logic
IPython/core/completer.py Refines exception handling in expression evaluation to fix prefix trimming issues
Comments suppressed due to low confidence (1)

IPython/core/guarded_eval.py:157

  • This line is missing the string literal before .join(). It should be ".".join([module_name, *access_path]).
        full_module_path = ".".join([module_name, *access_path])

Comment thread IPython/core/guarded_eval.py Outdated
@Darshan808

Copy link
Copy Markdown
Collaborator

This looks good to me! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow evaluation of attributes from given (trusted) library Invalid completions shown when evaluation policy forbids access

3 participants