Module pyracmon.graph.protocol

Expand source code
from typing import TypeVar, Generic, Protocol, Optional
from typing_extensions import Self
from collections.abc import Iterable, Mapping


KEY = TypeVar('KEY')


class NodeType(Protocol):
    @property
    def name(self) -> str: ...

    @property
    def parents(self) -> Iterable[Self]: ...


N = TypeVar('N', bound=NodeType, covariant=True)


class NodePropType(NodeType, Protocol, Generic[N]):
    @property
    def children(self) -> Iterable[N]: ...


class MapNodeType(NodeType, Protocol, Generic[N, KEY]):
    @property
    def children(self) -> Mapping[KEY, Iterable[N]]: ...

    def __contains__(self, key: KEY) -> bool: ...


MN = TypeVar('MN', bound=MapNodeType, covariant=True)

Classes

class MapNodeType (*args, **kwargs)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
Expand source code
class MapNodeType(NodeType, Protocol, Generic[N, KEY]):
    @property
    def children(self) -> Mapping[KEY, Iterable[N]]: ...

    def __contains__(self, key: KEY) -> bool: ...

Ancestors

  • NodeType
  • typing.Protocol
  • typing.Generic

Instance variables

var children : collections.abc.Mapping[~KEY, collections.abc.Iterable[+N]]
Expand source code
@property
def children(self) -> Mapping[KEY, Iterable[N]]: ...
class NodePropType (*args, **kwargs)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
Expand source code
class NodePropType(NodeType, Protocol, Generic[N]):
    @property
    def children(self) -> Iterable[N]: ...

Ancestors

  • NodeType
  • typing.Protocol
  • typing.Generic

Instance variables

var children : collections.abc.Iterable[+N]
Expand source code
@property
def children(self) -> Iterable[N]: ...
class NodeType (*args, **kwargs)

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
Expand source code
class NodeType(Protocol):
    @property
    def name(self) -> str: ...

    @property
    def parents(self) -> Iterable[Self]: ...

Ancestors

  • typing.Protocol
  • typing.Generic

Subclasses

Instance variables

var name : str
Expand source code
@property
def name(self) -> str: ...
var parents : collections.abc.Iterable[typing_extensions.Self]
Expand source code
@property
def parents(self) -> Iterable[Self]: ...