MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _chop_path

Method _chop_path

lib/sqlalchemy/orm/strategy_options.py:931–966  ·  view source on GitHub ↗
(
        cls,
        to_chop: _PathRepresentation,
        path: PathRegistry,
        debug: bool = False,
    )

Source from the content-addressed store, hash-verified

929
930 @classmethod
931 def _chop_path(
932 cls,
933 to_chop: _PathRepresentation,
934 path: PathRegistry,
935 debug: bool = False,
936 ) -> Optional[_PathRepresentation]:
937 i = -1
938
939 for i, (c_token, p_token) in enumerate(
940 zip(to_chop, path.natural_path)
941 ):
942 if isinstance(c_token, str):
943 if i == 0 and (
944 c_token.endswith(f":{_DEFAULT_TOKEN}")
945 or c_token.endswith(f":{_WILDCARD_TOKEN}")
946 ):
947 return to_chop
948 elif (
949 c_token != f"{_RELATIONSHIP_TOKEN}:{_WILDCARD_TOKEN}"
950 and c_token != p_token.key # type: ignore
951 ):
952 return None
953
954 if c_token is p_token:
955 continue
956 elif (
957 isinstance(c_token, InspectionAttr)
958 and insp_is_mapper(c_token)
959 and insp_is_mapper(p_token)
960 and c_token.isa(p_token)
961 ):
962 continue
963
964 else:
965 return None
966 return to_chop[i + 1 :]
967
968
969class Load(_AbstractLoad):

Callers 2

_processMethod · 0.80

Calls 3

insp_is_mapperFunction · 0.85
isaMethod · 0.80
endswithMethod · 0.45

Tested by

no test coverage detected