class_docstr: To support automatic labeling of mutables.
  
  Labels are named like a file-system. The analogy here is that:
  scope is like a directory, and label is like a file.
  The label name is like a file name. It can't contain slash (``/``) or underscore (``_``).
  The scope name is like a directory name. It also can't contain ``/`` or ``_``.
  When we refer to a "label", we will usually use the full name, which is like an absolute file path.
  
  :class:`label_scope` is usually jointly used with :func:`auto_label`,
  where :class:`label_scope` is used to generate the "scope" (directory) part,
  and :func:`auto_label` is used to generate the "name" (file) part.
  A :class:`label_scope` can be entered, and then :func:`auto_label` can be called inside.
  The labels as well as scopes generated inside can be automatically named with natural integers starting from 1
  (see examples below), and we guarantee the generation of labels to be reproducible.
  It can also be naturally nested.
  
  :class:`label_scope` is NOT thread-safe. The behavior is undefined if multiple threads are
  trying to enter the scope at the same time.
  
  :class:`label_scope` is implemented based on :class:`ContextStack`.
  
  Parameters
  ----------
  basename
      The last part of current scope name. If not specified, it will be generated by the parent scope.
      If the parent scope is not found, the scope name will be ``param`` by default.
      :class:`label_scope` is idempotent, so ``basename`` also accepts :class:`label_scope` and :class:`label`,
      though it will return a new instance.
  
  Examples
  --------
  >>> with label_scope('model'):
  ...     label1 = auto_label()       # model/1
  ...     label2 = auto_label()       # model/2
  ...     label3 = auto_label('foo')  # model/foo
  ...     with label_scope():
  ...         label4 = auto_label()   # model/3/1
  ...         label5 = auto_label()   # model/3/2
  ...     with label_scope('another'):
  ...         label6 = auto_label()   # model/another/1
  ...     with label_scope('model'):
  ...         label7 = auto_label()   # model/model/1
  >>> with label_scope('model'):
  ...     label8 = auto_label()       # model/1, because the counter is reset
  >>> with label_scope():
  ...     label9 = auto_label()       # global/1/1
class_docstr_tok: ["To","support","automatic","labeling","of","mutables",".","Labels","are","named","like","a","file-system",".","The","analogy","here","is","that",":","scope","is","like","a","directory",",","and","label","is","like","a","file",".","The","label","name","is","like","a","file","name",".","It","ca","n't","contain","slash","(","``","\/","``",")","or","underscore","(","``","_","``",")",".","The","scope","name","is","like","a","directory","name",".","It","also","ca","n't","contain","``","\/","``","or","``","_","``",".","When","we","refer","to","a","``","label","''",",","we","will","usually","use","the","full","name",",","which","is","like","an","absolute","file","path",".",":","class",":","`","label_scope","`","is","usually","jointly","used","with",":","func",":","`","auto_label","`",",","where",":","class",":","`","label_scope","`","is","used","to","generate","the","``","scope","''","(","directory",")","part",",","and",":","func",":","`","auto_label","`","is","used","to","generate","the","``","name","''","(","file",")","part",".","A",":","class",":","`","label_scope","`","can","be","entered",",","and","then",":","func",":","`","auto_label","`","can","be","called","inside",".","The","labels","as","well","as","scopes","generated","inside","can","be","automatically","named","with","natural","integers","starting","from","1","(","see","examples","below",")",",","and","we","guarantee","the","generation","of","labels","to","be","reproducible",".","It","can","also","be","naturally","nested",".",":","class",":","`","label_scope","`","is","NOT","thread-safe",".","The","behavior","is","undefined","if","multiple","threads","are","trying","to","enter","the","scope","at","the","same","time",".",":","class",":","`","label_scope","`","is","implemented","based","on",":","class",":","`","ContextStack","`",".","Parameters","--","--","--","--","--","basename","The","last","part","of","current","scope","name",".","If","not","specified",",","it","will","be","generated","by","the","parent","scope",".","If","the","parent","scope","is","not","found",",","the","scope","name","will","be","``","param","``","by","default",".",":","class",":","`","label_scope","`","is","idempotent",",","so","``","basename","``","also","accepts",":","class",":","`","label_scope","`","and",":","class",":","`","label","`",",","though","it","will","return","a","new","instance",".","Examples","--","--","--","--",">",">",">","with","label_scope","(","'model","'",")",":","...","label1","=","auto_label","(",")","#","model\/1","...","label2","=","auto_label","(",")","#","model\/2","...","label3","=","auto_label","(","'foo","'",")","#","model\/foo","...","with","label_scope","(",")",":","...","label4","=","auto_label","(",")","#","model\/3\/1","...","label5","=","auto_label","(",")","#","model\/3\/2","...","with","label_scope","(","'another","'",")",":","...","label6","=","auto_label","(",")","#","model\/another\/1","...","with","label_scope","(","'model","'",")",":","...","label7","=","auto_label","(",")","#","model\/model\/1",">",">",">","with","label_scope","(","'model","'",")",":","...","label8","=","auto_label","(",")","#","model\/1",",","because","the","counter","is","reset",">",">",">","with","label_scope","(",")",":","...","label9","=","auto_label","(",")","#","global\/1\/1"]
code: def __repr__(self):
      return f"label_scope({self.absolute_scope!r})"
  
imports: from __future__ import annotations
  import logging
  from collections import defaultdict
  from typing import Any, List, cast
label_desc: Use image node_id 8 for calling the label_scope obj's underlying member method code with example usage: obj.__repr__() and returns: str, self, str