Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions scripts/generate_patches/wit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class DocsHaver:
Abstract.
"""

_me: Any
def __init__(self, me: Any):
"""Construct.

:arg me: The JSON representing the WIT-file entity I am
"""
self._me: dict[str, Any] = me

def docs(self) -> str:
"""Return the documentation of the type, "" if omitted."""
Expand Down Expand Up @@ -76,7 +81,7 @@ class Type(Thing):

In practice, many types, like variants and the unit type, are represented by
more-specific subclasses, leaving this one to stand in for ones we haven't
needed to specializze for yet.
needed to specialize for yet.
"""

@classmethod
Expand All @@ -97,7 +102,7 @@ def from_id(
# It's a primitive.
return cls(type_id, {"name": type_id}, wit_json)
elif isinstance(type_id, NoneType):
return NullType()
return NullType(wit_json)

# It's an int. Chase that down, including following type aliases.
current_type = wit_json["types"][type_id]
Expand All @@ -112,8 +117,8 @@ def from_id(

def __init__(self, id: int | str, type_: dict, wit_json: dict[str, list[dict]]):
"""Private constructor. Use from_id() instead."""
super().__init__(type_)
self._id: int | str = id
self._me: dict[str, Any] = type_
self._wit = wit_json

def __hash__(self):
Expand Down Expand Up @@ -174,9 +179,8 @@ def error_type(self) -> Type:


class NullType(Type):
def __init__(self):
self._id = "null"
self._me = {"name": "null"}
def __init__(self, wit_json):
super().__init__("null", {"name": "null"}, wit_json)


class Record(Type):
Expand Down Expand Up @@ -213,7 +217,7 @@ class Case(Thing):
"""Abstract arm of a WIT type that has alternative manifestations."""

def __init__(self, case_json: dict[str, Any], haver: CaseHaver):
self._me = case_json
super().__init__(case_json)
self._haver = haver


Expand Down Expand Up @@ -268,7 +272,7 @@ def __init__(
interface_json: dict[str, Any],
wit_json: dict[str, list[dict]],
):
self._me = function_json
super().__init__(function_json)
self._interface = interface_json
self._wit = wit_json

Expand Down
Loading