Skip to content

Emit __delitem__ on IDictionary and IList - #100

Merged
Martin-Molinero merged 1 commit into
QuantConnect:masterfrom
jhonabreul:feature-delitem-stubs
Sep 3, 2026
Merged

Martin-Molinero merged 1 commit into
QuantConnect:masterfrom
jhonabreul:feature-delitem-stubs

Conversation

@jhonabreul

@jhonabreul jhonabreul commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Companion to QuantConnect/pythonnet#149.

Problem

  • Python.NET now supports del obj[key] on IDictionary<K,V> and IList<T> implementers.
  • The stubs have no __delitem__ anywhere, so type checkers flag valid code:
"ConcurrentDictionary[str, str]" has no attribute "__delitem__"; maybe "__getitem__" or "__setitem__"?  [attr-defined]

Changes

  • MethodParser.VisitIndexerDeclaration: emit __delitem__ on System.Collections.Generic.IDictionary and IList only. Implementers inherit it.
  • RendererTests: new golden case for both interfaces plus a plain indexer class that must not get __delitem__.

Verification

  • Generator unit tests: 74 passed.
  • Full regeneration: exactly two __delitem__ definitions, on IDictionary and IList.
  • mypy (--check-untyped-defs) on the regenerated stubs: Dictionary, ConcurrentDictionary, List and algo.securities deletes are clean; BitArray is still flagged, matching the runtime.

Ordering

Publish with or after the pythonnet release containing #149, otherwise the checker goes quiet on code that still crashes.

🤖 Generated with Claude Code

Python.NET now supports del obj[key] through IDictionary<K,V>.Remove and IList<T>.RemoveAt. Emit __delitem__ on those two interfaces so implementers inherit it and type checkers stop flagging valid deletes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@jhonabreul
jhonabreul force-pushed the feature-delitem-stubs branch from badc432 to 509d422 Compare September 2, 2026 15:19
@Martin-Molinero
Martin-Molinero merged commit f2718ae into QuantConnect:master Sep 3, 2026
1 check failed
@jhonabreul
jhonabreul deleted the feature-delitem-stubs branch September 3, 2026 21:06
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