mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Use cached_property instead of a custom decorator
This commit is contained in:
parent
1c1a5e3266
commit
f197e68589
4 changed files with 15 additions and 28 deletions
|
@ -17,12 +17,12 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
import typing as T
|
|
||||||
from collections import ChainMap, defaultdict
|
from collections import ChainMap, defaultdict
|
||||||
|
from functools import cached_property
|
||||||
|
import typing as T
|
||||||
|
|
||||||
from .errors import *
|
from .errors import *
|
||||||
from .lsp_utils import SemanticToken
|
from .lsp_utils import SemanticToken
|
||||||
from .utils import lazy_prop
|
|
||||||
from .xml_emitter import XmlEmitter
|
from .xml_emitter import XmlEmitter
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class AstNode:
|
||||||
else:
|
else:
|
||||||
return self.parent.parent_by_type(type)
|
return self.parent.parent_by_type(type)
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def errors(self):
|
def errors(self):
|
||||||
return list(self._get_errors())
|
return list(self._get_errors())
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
from functools import cached_property
|
||||||
import typing as T
|
import typing as T
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
from .errors import CompileError, CompilerBugError
|
from .errors import CompileError, CompilerBugError
|
||||||
from .utils import lazy_prop
|
|
||||||
from . import xml_reader
|
from . import xml_reader
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,30 +127,30 @@ class GirNode:
|
||||||
else:
|
else:
|
||||||
return self.container.get_containing(container_type)
|
return self.container.get_containing(container_type)
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def glib_type_name(self):
|
def glib_type_name(self):
|
||||||
return self.xml["glib:type-name"]
|
return self.xml["glib:type-name"]
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
if self.container is None:
|
if self.container is None:
|
||||||
return self.name
|
return self.name
|
||||||
else:
|
else:
|
||||||
return f"{self.container.name}.{self.name}"
|
return f"{self.container.name}.{self.name}"
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
return self.xml["name"]
|
return self.xml["name"]
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def cname(self) -> str:
|
def cname(self) -> str:
|
||||||
return self.xml["c:type"]
|
return self.xml["c:type"]
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def available_in(self) -> str:
|
def available_in(self) -> str:
|
||||||
return self.xml.get("version")
|
return self.xml.get("version")
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def doc(self) -> T.Optional[str]:
|
def doc(self) -> T.Optional[str]:
|
||||||
sections = []
|
sections = []
|
||||||
|
|
||||||
|
@ -237,15 +237,15 @@ class Class(GirNode, GirType):
|
||||||
result += " implements " + ", ".join(self.implements)
|
result += " implements " + ", ".join(self.implements)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def properties(self):
|
def properties(self):
|
||||||
return { p.name: p for p in self._enum_properties() }
|
return { p.name: p for p in self._enum_properties() }
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def signals(self):
|
def signals(self):
|
||||||
return { s.name: s for s in self._enum_signals() }
|
return { s.name: s for s in self._enum_signals() }
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
if self._parent is None:
|
if self._parent is None:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -32,18 +32,6 @@ class Colors:
|
||||||
CLEAR = '\033[0m'
|
CLEAR = '\033[0m'
|
||||||
|
|
||||||
|
|
||||||
def lazy_prop(func):
|
|
||||||
key = "_lazy_prop_" + func.__name__
|
|
||||||
|
|
||||||
@property
|
|
||||||
def real_func(self):
|
|
||||||
if key not in self.__dict__:
|
|
||||||
self.__dict__[key] = func(self)
|
|
||||||
return self.__dict__[key]
|
|
||||||
|
|
||||||
return real_func
|
|
||||||
|
|
||||||
|
|
||||||
def did_you_mean(word: str, options: T.List[str]) -> T.Optional[str]:
|
def did_you_mean(word: str, options: T.List[str]) -> T.Optional[str]:
|
||||||
if len(options) == 0:
|
if len(options) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -19,11 +19,10 @@
|
||||||
|
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from functools import cached_property
|
||||||
import typing as T
|
import typing as T
|
||||||
from xml import sax
|
from xml import sax
|
||||||
|
|
||||||
from .utils import lazy_prop
|
|
||||||
|
|
||||||
|
|
||||||
# To speed up parsing, we ignore all tags except these
|
# To speed up parsing, we ignore all tags except these
|
||||||
PARSE_GIR = set([
|
PARSE_GIR = set([
|
||||||
|
@ -40,7 +39,7 @@ class Element:
|
||||||
self.children: T.Dict[str, T.List["Element"]] = defaultdict(list)
|
self.children: T.Dict[str, T.List["Element"]] = defaultdict(list)
|
||||||
self.cdata_chunks: T.List[str] = []
|
self.cdata_chunks: T.List[str] = []
|
||||||
|
|
||||||
@lazy_prop
|
@cached_property
|
||||||
def cdata(self):
|
def cdata(self):
|
||||||
return ''.join(self.cdata_chunks)
|
return ''.join(self.cdata_chunks)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue