Skip to content

Commit 0f1549c

Browse files
fg-cfhnashif
authored andcommitted
scripts: dts: edtlib: simplification
Small refactorings to simplify code and improve method encapsulation. Signed-off-by: Florian Grandel <[email protected]>
1 parent 4bd584c commit 0f1549c

File tree

1 file changed

+30
-34
lines changed
  • scripts/dts/python-devicetree/src/devicetree

1 file changed

+30
-34
lines changed

scripts/dts/python-devicetree/src/devicetree/edtlib.py

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,6 @@ def _init_props(self, default_prop_types: bool = False,
14161416

14171417
self.props = {}
14181418

1419-
node = self._node
14201419
if self._binding:
14211420
prop2specs = self._binding.prop2specs
14221421
else:
@@ -1428,12 +1427,11 @@ def _init_props(self, default_prop_types: bool = False,
14281427
self._init_prop(prop_spec, err_on_deprecated)
14291428
self._check_undeclared_props()
14301429
elif default_prop_types:
1431-
for name in node.props:
1430+
for name in self._node.props:
14321431
if name not in _DEFAULT_PROP_SPECS:
14331432
continue
14341433
prop_spec = _DEFAULT_PROP_SPECS[name]
1435-
val = self._prop_val(name, prop_spec.type, False, False, None,
1436-
None, err_on_deprecated)
1434+
val = self._prop_val(name, prop_spec, err_on_deprecated)
14371435
self.props[name] = Property(prop_spec, val, self)
14381436

14391437
def _init_prop(self, prop_spec: PropertySpec,
@@ -1446,9 +1444,7 @@ def _init_prop(self, prop_spec: PropertySpec,
14461444
if not prop_type:
14471445
_err(f"'{name}' in {self.binding_path} lacks 'type'")
14481446

1449-
val = self._prop_val(name, prop_type, prop_spec.deprecated,
1450-
prop_spec.required, prop_spec.default,
1451-
prop_spec.specifier_space, err_on_deprecated)
1447+
val = self._prop_val(name, prop_spec, err_on_deprecated)
14521448

14531449
if val is None:
14541450
# 'required: false' property that wasn't there, or a property type
@@ -1476,50 +1472,48 @@ def _init_prop(self, prop_spec: PropertySpec,
14761472

14771473
self.props[name] = Property(prop_spec, val, self)
14781474

1479-
def _prop_val(self, name: str, prop_type: str,
1480-
deprecated: bool, required: bool,
1481-
default: PropertyValType,
1482-
specifier_space: Optional[str],
1483-
err_on_deprecated: bool) -> PropertyValType:
1475+
def _prop_val(
1476+
self,
1477+
name: str,
1478+
prop_spec: PropertySpec,
1479+
err_on_deprecated: bool,
1480+
) -> PropertyValType:
14841481
# _init_prop() helper for getting the property's value
14851482
#
14861483
# name:
14871484
# Property name from binding
14881485
#
1489-
# prop_type:
1490-
# Property type from binding (a string like "int")
1491-
#
1492-
# deprecated:
1493-
# True if the property is deprecated
1494-
#
1495-
# required:
1496-
# True if the property is required to exist
1497-
#
1498-
# default:
1499-
# Default value to use when the property doesn't exist, or None if
1500-
# the binding doesn't give a default value
1501-
#
1502-
# specifier_space:
1503-
# Property specifier-space from binding (if prop_type is "phandle-array")
1486+
# prop_spec:
1487+
# PropertySpec from binding
15041488
#
15051489
# err_on_deprecated:
15061490
# If True, a deprecated property is an error instead of warning.
15071491

15081492
node = self._node
15091493
prop = node.props.get(name)
1494+
binding_path = prop_spec.binding.path
1495+
prop_type = prop_spec.type
1496+
deprecated = prop_spec.deprecated
1497+
required = prop_spec.required
1498+
default = prop_spec.default
1499+
specifier_space = prop_spec.specifier_space
15101500

15111501
if prop and deprecated:
1512-
msg = (f"'{name}' is marked as deprecated in 'properties:' "
1513-
f"in {self.binding_path} for node {node.path}.")
1502+
msg = (
1503+
f"'{name}' is marked as deprecated in 'properties:' "
1504+
f"in {binding_path} for node {node.path}."
1505+
)
15141506
if err_on_deprecated:
15151507
_err(msg)
15161508
else:
15171509
_LOG.warning(msg)
15181510

15191511
if not prop:
15201512
if required and self.status == "okay":
1521-
_err(f"'{name}' is marked as required in 'properties:' in "
1522-
f"{self.binding_path}, but does not appear in {node!r}")
1513+
_err(
1514+
f"'{name}' is marked as required in 'properties:' in "
1515+
f"{binding_path}, but does not appear in {node!r}"
1516+
)
15231517

15241518
if default is not None:
15251519
# YAML doesn't have a native format for byte arrays. We need to
@@ -1534,9 +1528,11 @@ def _prop_val(self, name: str, prop_type: str,
15341528

15351529
if prop_type == "boolean":
15361530
if prop.type != Type.EMPTY:
1537-
_err("'{0}' in {1!r} is defined with 'type: boolean' in {2}, "
1538-
"but is assigned a value ('{3}') instead of being empty "
1539-
"('{0};')".format(name, node, self.binding_path, prop))
1531+
_err(
1532+
"'{0}' in {1!r} is defined with 'type: boolean' in {2}, "
1533+
"but is assigned a value ('{3}') instead of being empty "
1534+
"('{0};')".format(name, node, binding_path, prop)
1535+
)
15401536
return True
15411537

15421538
if prop_type == "int":

0 commit comments

Comments
 (0)