MCPcopy Index your code
hub / github.com/python/mypy / _shape_differs

Function _shape_differs

mypy/stubtest.py:517–536  ·  view source on GitHub ↗

Check whether two types differ in shape. Mirrors the shape_differs() function in typeobject.c in CPython.

(t1: type[object], t2: type[object])

Source from the content-addressed store, hash-verified

515
516
517def _shape_differs(t1: type[object], t2: type[object]) -> bool:
518 """Check whether two types differ in shape.
519
520 Mirrors the shape_differs() function in typeobject.c in CPython."""
521 if sys.version_info >= (3, 12):
522 return t1.__basicsize__ != t2.__basicsize__ or t1.__itemsize__ != t2.__itemsize__
523 else:
524 # CPython had more complicated logic before 3.12:
525 # https://github.com/python/cpython/blob/f3c6f882cddc8dc30320d2e73edf019e201394fc/Objects/typeobject.c#L2224
526 # We attempt to mirror it here well enough to support the most common cases.
527 if t1.__itemsize__ or t2.__itemsize__:
528 return t1.__basicsize__ != t2.__basicsize__ or t1.__itemsize__ != t2.__itemsize__
529 t_size = t1.__basicsize__
530 if not t2.__weakrefoffset__ and t1.__weakrefoffset__ + SIZEOF_PYOBJECT == t_size:
531 t_size -= SIZEOF_PYOBJECT
532 if not t2.__dictoffset__ and t1.__dictoffset__ + SIZEOF_PYOBJECT == t_size:
533 t_size -= SIZEOF_PYOBJECT
534 if not t2.__weakrefoffset__ and t2.__weakrefoffset__ == t_size:
535 t_size -= SIZEOF_PYOBJECT
536 return t_size != t2.__basicsize__
537
538
539def _is_disjoint_base(typ: type[object]) -> bool:

Callers 1

_is_disjoint_baseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…