mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
535 stars 344 forks source link

When is the i_config attribute set? #789

Closed wlupton closed 2 years ago

wlupton commented 2 years ago

I am writing a plugin that adds a validator:

statements.add_validation_fun('strict', ['must'], validator)

In the validator I want to check whether the parent node is configurable. From a brief look at the tree code I think I need to look at the i_config attribute, but it doesn't always exist, and I ended up doing this:

getattr(stmt.parent, 'i_config', None)

Is this correct, what governs whether i_config is set, and is there a best practice that I should follow? Thanks.

Note:

mbj4668 commented 2 years ago

Den fre 14 jan. 2022 kl 11:23 skrev William Lupton @.***

:

I am writing a plugin that adds a validator:

statements.add_validation_fun('strict', ['must'], validator)

In the validator I want to check whether the parent node is configurable. From a brief look at the tree code I think I need to look at the i_config attribute, but it doesn't always exist, and I ended up doing this:

getattr(stmt.parent, 'i_config', None)

Is this correct, what governs whether i_config is set, and is there a best practice that I should follow? Thanks.

It is set in the 'inherit_properties' phase so it should be ok check in 'strict'. As for which nodes has it, see v_inherit_properties. Using None if not set seems correct.

Note:

  • It seems that i_config is not set within rpc / action trees (which makes sense)
  • How does tree avoid getting an error when visiting a node without i_config?

Pure luck, perhaps ;-) It seems it checks other properties before it checks i_config.

/martin

— Reply to this email directly, view it on GitHub https://github.com/mbj4668/pyang/issues/789, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABJBUU6L7UXYIVL42ZR3D3UV72TJANCNFSM5L6NJAPQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

wlupton commented 2 years ago

Thanks!