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

Class Capsule

mypyc/ir/deps.py:6–42  ·  view source on GitHub ↗

Defines a C extension capsule that a primitive may require.

Source from the content-addressed store, hash-verified

4
5
6class Capsule:
7 """Defines a C extension capsule that a primitive may require."""
8
9 def __init__(self, name: str) -> None:
10 # Module fullname, e.g. 'librt.base64'
11 self.name: Final = name
12
13 def __repr__(self) -> str:
14 return f"Capsule(name={self.name!r})"
15
16 def __eq__(self, other: object) -> bool:
17 return isinstance(other, Capsule) and self.name == other.name
18
19 def __hash__(self) -> int:
20 return hash(("Capsule", self.name))
21
22 def internal_dep(self) -> SourceDep:
23 """Internal source dependency of the capsule that should only be included in the C extensions
24 that depend on the capsule, eg. by importing a type or function from the capsule.
25 """
26 module = self.name.split(".")[-1]
27 return SourceDep(f"{module}/librt_{module}_api.c", include_dirs=[module])
28
29 def external_dep(self) -> HeaderDep:
30 """External header dependency of the capsule that may be included in external headers of C
31 extensions that depend on the capsule.
32
33 The external headers of the C extensions are included by other C extensions that don't
34 necessarily import the capsule. However, they may need type definitions from the capsule
35 for types that are used in the exports table of the included C extensions.
36
37 Only the external header should be included in this case because if the other C extension
38 doesn't import the capsule, it also doesn't include the definition for its API table and
39 including the internal header would result in undefined symbols.
40 """
41 module = self.name.split(".")[-1]
42 return HeaderDep(f"{module}/librt_{module}.h", include_dirs=[module], internal=False)
43
44
45class SourceDep:

Callers 2

deserializeMethod · 0.90
deps.pyFile · 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…