MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / __new__

Method __new__

lib/sqlalchemy/util/langhelpers.py:1689–1717  ·  view source on GitHub ↗
(
        cls,
        name: str,
        doc: Optional[str] = None,
        canonical: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

1687 _lock = threading.Lock()
1688
1689 def __new__(
1690 cls,
1691 name: str,
1692 doc: Optional[str] = None,
1693 canonical: Optional[int] = None,
1694 ) -> symbol:
1695 with cls._lock:
1696 sym = cls.symbols.get(name)
1697 if sym is None:
1698 assert isinstance(name, str)
1699 if canonical is None:
1700 canonical = hash(name)
1701 sym = int.__new__(symbol, canonical)
1702 sym.name = name
1703 if doc:
1704 sym.__doc__ = doc
1705
1706 # NOTE: we should ultimately get rid of this global thing,
1707 # however, currently it is to support pickling. The best
1708 # change would be when we are on py3.11 at a minimum, we
1709 # switch to stdlib enum.IntFlag.
1710 cls.symbols[name] = sym
1711 else:
1712 if canonical and canonical != sym:
1713 raise TypeError(
1714 f"Can't replace canonical symbol for {name!r} "
1715 f"with new int value {canonical}"
1716 )
1717 return sym
1718
1719 def __reduce__(self):
1720 return symbol, (self.name, "x", int(self))

Callers 6

_from_listMethod · 0.45
differenceMethod · 0.45
intersectionMethod · 0.45
symmetric_differenceMethod · 0.45
copyMethod · 0.45
__new__Method · 0.45

Calls 1

getMethod · 0.45

Tested by

no test coverage detected