Skip to content

Suggest nested type names verbatim and filter attribute hints by member usage#140

Merged
jhonabreul merged 2 commits into
QuantConnect:masterfrom
jhonabreul:bug-nested-type-attribute-hint
Jul 14, 2026
Merged

Suggest nested type names verbatim and filter attribute hints by member usage#140
jhonabreul merged 2 commits into
QuantConnect:masterfrom
jhonabreul:bug-nested-type-attribute-hint

Conversation

@jhonabreul

Copy link
Copy Markdown
Collaborator

Problem

An algorithm accessing OptionPriceModels.quant_lib() got:

type object 'OptionPriceModels' has no attribute 'quant_lib' Did you mean: 'quant_lib'?

The hint suggested the exact name that just failed. QuantLib is a nested static class of OptionPriceModels in Lean, and nested types are exposed to Python only under their original PascalCase name (ClassManager registers no snake_case alias for them). The suggestion builder, however, snake-cased every member name — including nested types — so it offered a name that can never resolve.

Changes

  • GetCandidateMemberNames keeps nested type names verbatim, so the hint above now reads Did you mean: 'QuantLib'?, pointing at the accessible name.
  • Each candidate is tagged with how it is used from Python: callable (methods and nested types, since a nested type access can be an attempted constructor call) or data (fields, properties, events). Suggestions are filtered to the kind of the closest match, so a mistyped method no longer suggests properties and vice versa. A name exposed as both (e.g. a method and a property collapsing to the same snake_case name) carries both flags and survives either filter.

Tests

  • New Python.Test.SuggestionTest fixture with a nested class (Calculator), methods (Calculate, CalculationResults) and a property (CalculationResult) with deliberately similar names.
  • New tests in tests/test_class.py covering: nested-type miss suggests the PascalCase name (and not the snake-cased one), method-like miss suggests callables only, property-like miss suggests data members only.
  • Full Python suite (--runtime netcore): 457 passed, 23 skipped. Embed test TestGetMisspelledDynamicObjectPropertySuggestsSimilarMembers passes.

…er usage

A missing-attribute hint could suggest the exact name that just failed:
accessing OptionPriceModels.quant_lib() produced "has no attribute
'quant_lib'. Did you mean: 'quant_lib'?", because the suggestion list
snake-cased nested type names while ClassManager only registers nested
types under their original PascalCase name.

Nested types are now suggested under their original name, and
suggestions are filtered by how the closest match is used from Python:
a miss that best matches a method or nested type (a possible
constructor call) only suggests callables, while one that best matches
a field or property only suggests data members.
@jhonabreul jhonabreul marked this pull request as ready for review July 14, 2026 17:28
@jhonabreul jhonabreul merged commit 1e5186d into QuantConnect:master Jul 14, 2026
8 checks passed
@jhonabreul jhonabreul deleted the bug-nested-type-attribute-hint branch July 14, 2026 18:54
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.

2 participants