MCPcopy Index your code
hub / github.com/ipython/ipython / _find_parts

Method _find_parts

IPython/core/interactiveshell.py:1660–1702  ·  view source on GitHub ↗

Given an object name, return a list of parts of this object name. Basically split on docs when using attribute access, and extract the value when using square bracket. For example foo.bar[3].baz[x] -> foo, bar, 3, baz, x Returns ------- p

(oname: str)

Source from the content-addressed store, hash-verified

1658 #-------------------------------------------------------------------------
1659 @staticmethod
1660 def _find_parts(oname: str) -> Tuple[bool, ListType[str]]:
1661 """
1662 Given an object name, return a list of parts of this object name.
1663
1664 Basically split on docs when using attribute access,
1665 and extract the value when using square bracket.
1666
1667
1668 For example foo.bar[3].baz[x] -> foo, bar, 3, baz, x
1669
1670
1671 Returns
1672 -------
1673 parts_ok: bool
1674 whether we were properly able to parse parts.
1675 parts: list of str
1676 extracted parts
1677
1678
1679
1680 """
1681 raw_parts = oname.split(".")
1682 parts = []
1683 parts_ok = True
1684 for p in raw_parts:
1685 if p.endswith("]"):
1686 var, *indices = p.split("[")
1687 if not var.isidentifier():
1688 parts_ok = False
1689 break
1690 parts.append(var)
1691 for ind in indices:
1692 if ind[-1] != "]" and not is_integer_string(ind[:-1]):
1693 parts_ok = False
1694 break
1695 parts.append(ind[:-1])
1696 continue
1697
1698 if not p.isidentifier():
1699 parts_ok = False
1700 parts.append(p)
1701
1702 return parts_ok, parts
1703
1704 def _ofind(
1705 self, oname: str, namespaces: Optional[Sequence[Tuple[str, AnyType]]] = None

Callers 1

_ofindMethod · 0.95

Calls 1

is_integer_stringFunction · 0.85

Tested by

no test coverage detected