MCPcopy Index your code
hub / github.com/lutzroeder/netron / refineAndSetUnionTypeHintOrPopulateCandidatesVector

Method refineAndSetUnionTypeHintOrPopulateCandidatesVector

source/python.js:17155–17181  ·  view source on GitHub ↗
(type_hint, refined_type_hint_ptr, all_candidates, match_repr, src, type_match, do_if_match, do_if_anytype, is_dict_constructor)

Source from the content-addressed store, hash-verified

17153 return this.graph.create(kind, n_outputs).setSourceRange(loc);
17154 }
17155 refineAndSetUnionTypeHintOrPopulateCandidatesVector(type_hint, refined_type_hint_ptr, all_candidates, match_repr, src, type_match, do_if_match, do_if_anytype, is_dict_constructor) {
17156 is_dict_constructor = is_dict_constructor || false;
17157 if (refined_type_hint_ptr._ instanceof torch.UnionType) {
17158 const candidate_types = refined_type_hint_ptr._.containedTypes().filter((type_ptr) => type_match(type_ptr));
17159 if (!is_dict_constructor && candidate_types.length === 0) {
17160 throw new python.Error("No matching types found in Union type annotation.");
17161 } else if (candidate_types.length === 1) {
17162 [refined_type_hint_ptr._] = candidate_types;
17163 } else {
17164 all_candidates._ = candidate_types;
17165 }
17166 } else if (refined_type_hint_ptr._ instanceof torch.OptionalType) {
17167 refined_type_hint_ptr._ = refined_type_hint_ptr._.getElementType();
17168 }
17169 if (is_dict_constructor) {
17170 return;
17171 }
17172 if (all_candidates._.length === 0) {
17173 if (type_match(refined_type_hint_ptr._)) {
17174 do_if_match();
17175 } else if (refined_type_hint_ptr._.kind() === 'AnyType') {
17176 do_if_anytype();
17177 } else {
17178 throw new python.Error('Invalid annotation type.');
17179 }
17180 }
17181 }
17182 emitToBool(loc, v) {
17183 let out = null;
17184 const bool_cast = this.environment_stack.getSugaredVar('bool', loc);

Callers 2

emitDictLiteralMethod · 0.80
emitListLiteralMethod · 0.80

Calls 4

containedTypesMethod · 0.80
getElementTypeMethod · 0.80
filterMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected