class_docstr: Helper for globbing paths.
  
  Parameters
  ----------
  patterns : list of str
      Call `glob.glob` with each of these patterns. "." is considered as
      datalad's special "." path argument; it is not passed to glob and is
      always left unexpanded. Each set of glob results is sorted
      alphabetically.
  pwd : str, optional
      Glob in this directory.
  expand : bool, optional
     Whether the `paths` property returns unexpanded or expanded paths.
class_docstr_tok: ["Helper","for","globbing","paths",".","Parameters","--","--","--","--","--","patterns",":","list","of","str","Call","`","glob.glob","`","with","each","of","these","patterns",".","``",".","''","is","considered","as","datalad","'s","special","``",".","''","path","argument",";","it","is","not","passed","to","glob","and","is","always","left","unexpanded",".","Each","set","of","glob","results","is","sorted","alphabetically",".","pwd",":","str",",","optional","Glob","in","this","directory",".","expand",":","bool",",","optional","Whether","the","`","paths","`","property","returns","unexpanded","or","expanded","paths","."]
docstr: Extract sub-patterns from the leading path of `pattern`.
  
  The right-most path component is successively peeled off until there
  are no patterns left.
docstr_tok: ["Extract","sub-patterns","from","the","leading","path","of","`","pattern","`",".","The","right-most","path","component","is","successively","peeled","off","until","there","are","no","patterns","left","."]
code: def _get_sub_patterns(pattern: str) -> list[str]:
      """Extract sub-patterns from the leading path of `pattern`.
  
      The right-most path component is successively peeled off until there
      are no patterns left.
      """
      head, tail = op.split(pattern)
      if not tail:
          # Pattern ended with a separator. Take the first directory as the
          # base.
          head, tail = op.split(head)
  
      sub_patterns = []
      seen_magic = glob.has_magic(tail)
      while head:
          new_head, tail = op.split(head)
          if seen_magic and not glob.has_magic(head):
              break
          elif not seen_magic and glob.has_magic(tail):
              seen_magic = True
  
          if seen_magic:
              sub_patterns.append(head + op.sep)
          head = new_head
      return sub_patterns
  
imports: from __future__ import annotations
  import glob
  import logging
  import os.path
  from functools import lru_cache
  from itertools import chain
  from typing import Iterable, Optional
  from datalad.utils import chpwd, ensure_unicode, getpwd, partition
label_desc: Use image node_id 3 for calling the GlobbedPaths obj's underlying member method code with example usage: obj._get_sub_patterns(pattern) and returns: sub_patterns