diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-06-05 21:32:28 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-06-06 12:47:19 +0000 |
commit | d8981871a2810c5837b410e20dd93b38e30bf711 (patch) | |
tree | a4a3c0142b2850c0c89312a0543437bd5af8842e | |
parent | cda6f0a6236f7afc55902a5e2e57b3b7ee818903 (diff) | |
download | buildstream-bschubert/optimize-loader-types.tar.gz |
_loader/types: type values wherever possiblebschubert/optimize-loader-types
That way, cython can make better inference on the code and does not
need to be too conservative.
-rw-r--r-- | src/buildstream/_loader/types.pyx | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/buildstream/_loader/types.pyx b/src/buildstream/_loader/types.pyx index de9d378e3..d3cd06253 100644 --- a/src/buildstream/_loader/types.pyx +++ b/src/buildstream/_loader/types.pyx @@ -64,24 +64,29 @@ cdef class Dependency: cdef public str dep_type cdef public str junction - def __init__(self, dep, provenance, default_dep_type=None): + def __init__(self, + object dep, + _yaml.ProvenanceInformation provenance, + str default_dep_type=None): + cdef str dep_type + self.provenance = provenance if type(dep) is str: - self.name = dep + self.name = <str> dep self.dep_type = default_dep_type self.junction = None elif type(dep) is _yaml.Node and type(dep.value) is dict: if default_dep_type: - _yaml.node_validate(dep, ['filename', 'junction']) + _yaml.node_validate(<_yaml.Node> dep, ['filename', 'junction']) dep_type = default_dep_type else: - _yaml.node_validate(dep, ['filename', 'type', 'junction']) + _yaml.node_validate(<_yaml.Node> dep, ['filename', 'type', 'junction']) # Make type optional, for this we set it to None - dep_type = _yaml.node_get(dep, str, Symbol.TYPE, None, None) - if dep_type is None or dep_type == Symbol.ALL: + dep_type = <str> _yaml.node_get(<_yaml.Node> dep, str, <str> Symbol.TYPE, None, None) + if dep_type is None or dep_type == <str> Symbol.ALL: dep_type = None elif dep_type not in [Symbol.BUILD, Symbol.RUNTIME]: provenance = _yaml.node_get_provenance(dep, key=Symbol.TYPE) @@ -89,9 +94,9 @@ cdef class Dependency: "{}: Dependency type '{}' is not 'build', 'runtime' or 'all'" .format(provenance, dep_type)) - self.name = _yaml.node_get(dep, str, Symbol.FILENAME) + self.name = <str> _yaml.node_get(<_yaml.Node> dep, str, <str> Symbol.FILENAME) self.dep_type = dep_type - self.junction = _yaml.node_get(dep, str, Symbol.JUNCTION, None, None) + self.junction = <str> _yaml.node_get(<_yaml.Node> dep, str, <str> Symbol.JUNCTION, None, None) else: raise LoadError(LoadErrorReason.INVALID_DATA, |