Skip to content

Commit

Permalink
♻️ Simpler Type type implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
boisgera committed Aug 23, 2024
1 parent 684e4c9 commit 05f421d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/pandoc/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import dataclasses
import re

from abc import ABCMeta
from abc import abstractmethod, ABCMeta
from collections import Counter
from collections.abc import Iterable, Sequence
from functools import partial
Expand Down Expand Up @@ -262,12 +262,6 @@ def docstring(decl, show_fields: bool = False, show_default_values: bool = False

# Haskell Type Constructs
# ------------------------------------------------------------------------------
def _fail_init(self, *args, **kwargs):
type_name = type(self).__name__
error = "Can't instantiate abstract class {type}"
raise TypeError(error.format(type=type_name))


class MetaType(ABCMeta):
def __repr__(cls):
doc = getattr(cls, "__doc__", None)
Expand All @@ -277,8 +271,10 @@ def __repr__(cls):
return type.__repr__(cls)


Type = MetaType("Type", (object,), {"__init__": _fail_init})

class Type(metaclass=MetaType):
@abstractmethod
def __init__(self, *args, **kwargs):
pass

class Data(Type):
pass
Expand Down Expand Up @@ -477,8 +473,8 @@ def make_types(
# This was intentional, because in pandoc-types < 1.21,
# it used to happens only when there is a single constructor.
# But, now we have ColWidth, which is either a ColWidth(Double)
# or a ColWidthDefault. So we need to adapt the model : we
# add a "_" to the end of the constructor and patch the decl
# or a ColWidthDefault. So we need to adapt the model:
# we add a "_" to the end of the constructor and patch the decl.
if len(constructors) > 1:
for constructor in constructors:
constructor_name = constructor[0]
Expand Down

0 comments on commit 05f421d

Please sign in to comment.