• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18from typing import Any, Optional
19
20import rich.repr
21
22from .primitive import PrimitiveMeta
23from .type_cache import type_cache
24
25
26class EmptyBase(metaclass=PrimitiveMeta):
27    """Base class for ArkTS mirror primitives."""
28
29    __slots__ = ()
30
31    def __eq__(self, other: Any) -> bool:
32        return type(self) is type(other) or type(self).__name__ == type(other).__name__
33
34    # CC-OFFNXT(G.NAM.05) Standard function from rich package
35    # CC-OFFNXT(G.CLS.07) followed required interface
36    def __rich_repr__(self):
37        return []
38
39    # CC-OFFNXT(G.NAM.05) internal function name
40    def __arkts_str__(self, *, depth: Optional[int] = None) -> str:
41        return type(self).__name__
42
43
44@type_cache(scope="session")
45def mirror_empty_type(cls_name: str):
46    return rich.repr.auto(PrimitiveMeta(cls_name, (EmptyBase,), {}, module=__package__))
47
48
49def mirror_undefined():
50    return mirror_empty_type("undefined")()
51