Repository navigation
Resolve the defining class of unbound nested methods - #1862
Closed
tleonhardt wants to merge 9 commits into
Closed
tleonhardt wants to merge 9 commits into
tleonhardt wants to merge 9 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1862 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 23 23
Lines 6777 6840 +63
=======================================
+ Hits 6761 6824 +63
Misses 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Skip qualified-name traversal for local functions so choices providers returned by CommandSet methods receive the application. Cover the nested factory case with a regression test.
Check whether the enclosing class stores the exact function returned by a factory. This gives class-assigned choices providers the registered command set while standalone callbacks from the same factory receive the application.
Search the factory class hierarchy for the callback and match the underlying function when a parser copies an installed partial. Cover both receiver regressions through tab completion.
Keep the original partial identity for receiver lookup when argparse copies a parser. Resolve shared providers using the command receiver and registered instances, and visit factory subclasses by identity so unhashable metaclasses work.
…commands Use the active command receiver before looking for a registered fallback. Keep partial callback identity across parser copies while preserving action pickling and custom completion parameters.
Track the declaration scope of argparse callbacks to recognize inline parser-factory providers. Match live owners by nominal class identity so application fallbacks and concrete protocol providers work.
Recognize local callbacks when they are registered through action setters, parser helpers, or command decorators. Exercise both tab completion and command execution with distinct application and command set state.
Member
Author
|
I'm going to abandon this. Initially I thought this was going to be a simple fix for an obscure edge case. But the code complexity for supporting this obscure edge case was more than I anticipated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the nested-class review comment on #1861.
An unbound completer such as
ColorPlugin.Commands.complete_colorneeds the registeredColorPlugin.Commandsinstance asself. Looking upColorPlugin.Commandsas a single module attribute returnedNone, so cmd2 passed the application and completion returned no matches.get_defining_class()now walks the qualified name from the module, one attribute at a time. A missing owner still falls through to the existing descriptor fallback.Factory-created callbacks can share a qualified name. For these callbacks, cmd2 checks which classes in the factory’s hierarchy actually installed the function or partial. A standalone callback receives the application.
When a command set’s factory registers an inline completion callback, that callback receives the set. This holds for prebuilt and lazily built parsers, including registration through
add_argument(), action setters, and parser helpers. Inline namespace providers registered withwith_argparserorwith_annotatedalso receive the set during command execution.When an application and command sets share a callback, completion uses the command’s own receiver if it matches. Attached subcommands use their registered owner, including when a different command set owns the parent command. For an unrelated command, cmd2 considers the application and registered command sets together. It prefers a unique instance of an installing class, then a unique instance of a subclass. An ambiguous match follows the existing completion error path. Receiver matching uses class identity along the method resolution order. This supports concrete methods on protocols without requiring
@runtime_checkable. The hierarchy walk also handles unhashable metaclasses.When a parser is copied, cmd2 uses the original partial to look up its owner and invokes the copy with its own bound arguments. Two partials around the same callback can therefore read choices from different receivers. The original identity is used only within the process, so actions with picklable partials still round-trip through pickle. Applications can register custom parameters named
completer_sourceandchoices_provider_source.Regression tests exercise nested and inherited methods, subclass-installed providers, standalone and installed partials, shared callbacks on app commands and attached subcommands, sibling command sets, and an unhashable class in a diamond hierarchy. Regression tests also check the choices returned through
app.complete()and the namespace values observed by a running command. Additional tests cover shared callbacks with one or two eligible live owners, concrete protocol methods, custom parameters, and pickling a partial provider.Verification
make checkandmake docs-testpassed.make testwith branch coverage passed with 3,265 tests passing and 3 skipped.main, tests covered all 92 changed executable production lines and all 38 measured branch outcomes (100%).