Esempio n. 1
0
        __slots__ = ()

        def __instancecheck__(self, obj):
            raise TypeError("Unknown cannot be used with isinstance().")

        def __subclasscheck__(self, cls):
            raise TypeError("Unknown cannot be used with issubclass().")

    Unknown = _Unknown(_root=True)
else:
    from typing import _SpecialForm, _Final, _Immutable, _GenericAlias

    Unknown = _SpecialForm(
        'Unknown', doc="""
        Special type indicating an unknown type.

        - Unknown is compatible with every type.
        - Unknown is less informative than all types.
        """
    )

    class Unknown(_Final, _Immutable, _root=True):
        """Special type indicating an unknown type.

        - Unknown is compatible with every type.
        - Unknown is less informative than all types.
        """

        __slots__ = ()

        def __instancecheck__(self, obj):
            raise TypeError("Unknown cannot be used with isinstance().")
Esempio n. 2
0
    def __call__(cls):
        raise TypeError(f"Type {cls!r} cannot be instantiated.")


class Constant(typing.Generic[_T], metaclass=_GenericMeta):
    pass


class DateTime(typing.Generic[_T], metaclass=_GenericMeta):
    pass


class NaiveDateTime(typing.Generic[_T], metaclass=_GenericMeta):
    pass


class AwareDateTime(typing.Generic[_T], metaclass=_GenericMeta):
    pass


class Pluck(typing.Generic[_T], metaclass=_GenericMeta):
    pass


Number = typing._SpecialForm("Number", doc="")
Url = typing._SpecialForm("Url", doc="")
Email = typing._SpecialForm("Email", doc="")

# Not implemented:
# marshmallow.Method
Esempio n. 3
0
class Form(_Body):
    __apix_param_type__ = "Form"
    __special_form__ = _SpecialForm("Form", "")
Esempio n. 4
0
        raise TypeError(f"{self} is not subscriptable")


    _SpecialForm.__getitem__ = __getitem__

    Literal = _SpecialForm('Literal', doc=
    """Special typing form to define literal types (a.k.a. value types).

    This form can be used to indicate to type checkers that the corresponding
    variable or function parameter has a value equivalent to the provided
    literal (or one of several literals):

      def validate_simple(data: Any) -> Literal[True]:  # always returns True
          ...

      MODE = Literal['r', 'rb', 'w', 'wb']
      def open_helper(file: str, mode: MODE) -> str:
          ...

      open_helper('/some/path', 'r')  # Passes type check
      open_helper('/other/path', 'typo')  # Error in type checker

   Literal[...] cannot be subclassed. At runtime, an arbitrary value
   is allowed as type argument to Literal[...], but type checkers may
   impose restrictions.
    """)


    def get_origin(tp):
        """Get the unsubscripted version of a type.
Esempio n. 5
0
class Body(_Body):
    __apix_param_type__ = "Body"
    __special_form__ = _SpecialForm("Body", "")
Esempio n. 6
0
class Cookie(_Param):
    __apix_param_type__ = "Cookie"
    __special_form__ = _SpecialForm("Cookie", "")
Esempio n. 7
0
class Path(_Param):
    __apix_param_type__ = "Path"
    __special_form__ = _SpecialForm("Path", "")
Esempio n. 8
0
class Header(_Param):
    __apix_param_type__ = "Header"
    __special_form__ = _SpecialForm("Header", "")
Esempio n. 9
0
class Query(_Param):
    __apix_param_type__ = "Query"
    __special_form__ = _SpecialForm("Query", "")