Fix union of class type and instance factory, and bash completion without tput - #968
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #968 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 28 28
Lines 9374 9388 +14
=========================================
+ Hits 9374 9388 +14 ☔ View full report in Codecov by Harness. |
|
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.



What does this PR do?
Two independent fixes, both with tests and changelog entries.
Union of a class type and an instance factory for it
A
Unionof a class and a factory that returns it, e.g.Union[Optimizer, Callable[[Iterable], Optimizer]], accepted no value at all. When the value was adapted against the class subtype, sub-defaults added a placeholder for the parameter that the factory receives when called (e.g.params). That placeholder made the value invalid for the class subtype itself, and since adapting modifies the value in place, it also invalidated the subtypes that would have accepted the original value.Changes in
_typehints.py:sub_defaults_invalidate_valuecheck: when a subclass spec value comes back from a subtype but only validates because of leniently added sub-defaults, the union keeps trying the other subtypes instead of stopping at it.Both directions now work:
--optimizer=Adam --optimizer.lr=0.01resolves to the factory subtype and is callable with the runtime argument, while a value that providesparamsexplicitly resolves to the class subtype and instantiates.Bash completion with tput unavailable
The
shtab-bashcompletion script rantputinside theprintfformat string, so every completion printedtput: command not foundin environments withouttput(some containers) or withTERMunset.The colors are now resolved once when the script is sourced, into
_jsonargparse_{prog}_color_message/_jsonargparse_{prog}_color_reset, withtputerrors ignored. Completion messages are colored whentputis available and plain, without any error output, when it is not.Before submitting