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

Method create_name

source/python.js:8807–8837  ·  view source on GitHub ↗
(candidate, obj)

Source from the content-addressed store, hash-verified

8805 this._base_count = {};
8806 }
8807 create_name(candidate, obj) {
8808 if (obj && this._obj_to_name.has(obj)) {
8809 return self._obj_to_name.get(obj);
8810 }
8811 candidate = candidate || '_unnamed';
8812 candidate = /^\d+$/.test(candidate) ? `_${candidate}` : candidate;
8813 candidate = candidate.replace(/[^0-9a-zA-Z_]+/, '_');
8814 const match = candidate.match(/(.*)_(\d+)$"/);
8815 let base = candidate;
8816 let num = null;
8817 if (match) {
8818 [, base] = match;
8819 num = parseInt(match[2], 10);
8820 }
8821 candidate = num ? `${base}_${num}` : base;
8822 if (!num) {
8823 num = this._base_count[base] || 0;
8824 }
8825 while (this._used_names.has(candidate) || this._is_illegal_name(candidate, obj)) {
8826 num += 1;
8827 candidate = `${base}_${num}`;
8828 }
8829 this._used_names.add(candidate);
8830 this._base_count[base] = num;
8831 if (obj) {
8832 this._obj_to_name[obj] = candidate;
8833 } else {
8834 this._unassociated_names.add(candidate);
8835 }
8836 return candidate;
8837 }
8838 _is_illegal_name(/* name, obj */) {
8839 /*
8840 if name in keyword.kwlist:

Callers 1

create_nodeMethod · 0.80

Calls 5

_is_illegal_nameMethod · 0.80
hasMethod · 0.45
getMethod · 0.45
matchMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected