Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-config-engine] openconfig_acl.py: Make compliant with Python 3 #5873

Merged
merged 1 commit into from
Nov 10, 2020
Merged

[sonic-config-engine] openconfig_acl.py: Make compliant with Python 3 #5873

merged 1 commit into from
Nov 10, 2020

Conversation

jleveque
Copy link
Contributor

@jleveque jleveque commented Nov 10, 2020

- Why I did it

Python 3 is more strict with __slots__. As per the documentation:

__slots__ are implemented at the class level by creating descriptors (Implementing Descriptors) for each variable name. As a result, class attributes cannot be used to set default values for instance variables defined by __slots__; otherwise, the class attribute would overwrite the descriptor assignment.

This was apparently missed when making sonic-config-engine compliant with Python 3, and errors like the following would be seen:

tests/acl_loader_test.py:10: in <module>
    from acl_loader.main import *
acl_loader/main.py:8: in <module>
    import openconfig_acl
/usr/local/lib/python3.7/dist-packages/openconfig_acl.py:24: in <module>
    class yc_state_openconfig_acl__acl_state(PybindBase):
E   ValueError: '_pybind_generated_by' in __slots__ conflicts with class variable

- How I did it

Set _yang_name and _pybind_generated_by members in the constructors rather than in the class bodies.

- How to verify it

Run tests in tests/acl_loader_test.py (sonic-utilities) and ensure no errors are seen.

- Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@jleveque jleveque added Bug 🐛 sonic-cfggen SONiC Configuration Generator Tool labels Nov 10, 2020
@jleveque jleveque self-assigned this Nov 10, 2020
def __init__(self, *args, **kwargs):

self._yang_name = 'state'
self._pybind_generated_by = 'container'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this generated use the command on line 13?

Copy link
Contributor Author

@jleveque jleveque Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I did not regenerate the file, I simply fixed Python 3 errors, since we currently need this file to be compatible with both Python 2 and 3. Regenerating the file with Python 3 might break backward-compatibility. Once we remove support for Python 2 completely, we can regenerate the file using Python 3.

@jleveque jleveque merged commit aee389e into sonic-net:master Nov 10, 2020
@jleveque jleveque deleted the openconfig_acl_py3 branch November 10, 2020 18:26
santhosh-kt pushed a commit to santhosh-kt/sonic-buildimage that referenced this pull request Feb 25, 2021
…sonic-net#5873)

Python 3 is more strict with `__slots__`. As per the [documentation](https://docs.python.org/3/reference/datamodel.html#notes-on-using-slots):

> \_\_slots\_\_ are implemented at the class level by creating descriptors (Implementing Descriptors) for each variable name. As a result, class attributes cannot be used to set default values for instance variables defined by \_\_slots\_\_; otherwise, the class attribute would overwrite the descriptor assignment.

This was apparently missed when making sonic-config-engine compliant with Python 3, and errors like the following would be seen:

```
tests/acl_loader_test.py:10: in <module>
    from acl_loader.main import *
acl_loader/main.py:8: in <module>
    import openconfig_acl
/usr/local/lib/python3.7/dist-packages/openconfig_acl.py:24: in <module>
    class yc_state_openconfig_acl__acl_state(PybindBase):
E   ValueError: '_pybind_generated_by' in __slots__ conflicts with class variable
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Python 3 sonic-cfggen SONiC Configuration Generator Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants