pyangbind icon indicating copy to clipboard operation
pyangbind copied to clipboard

Update `reserved_name` list to be a comprehensive list for py2 + py3

Open unsignedint opened this issue 7 years ago • 7 comments

Updates the reserved_name list.

WARNING. This has the potential to break a lot of existing code if there is code using existing members with reserved names, e.g. see the tests that were modified using input and type.

Not sure what to do about it...

unsignedint avatar Jun 07 '18 23:06 unsignedint

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to go/cla#troubleshoot (Public version).
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

googlebot avatar Jun 07 '18 23:06 googlebot

Codecov Report

Merging #208 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #208   +/-   ##
======================================
  Coverage    70.2%   70.2%           
======================================
  Files           7       7           
  Lines        1658    1658           
  Branches      457     457           
======================================
  Hits         1164    1164           
  Misses        369     369           
  Partials      125     125
Impacted Files Coverage Δ
pyangbind/lib/yangtypes.py 83.33% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bcb1d86...ad7fa36. Read the comment docs.

codecov[bot] avatar Jun 08 '18 00:06 codecov[bot]

To be fair, I think the reserved names really only matter for top-level (e.g. when you are importing a yang module that happens to be called input or long) so perhaps we could be more permissive by changing the implementation. However, I thought I'd create this patch anyway as a talking point as I encountered this issue with a yang I was working with.

unsignedint avatar Jun 08 '18 00:06 unsignedint

Thanks for the contribution!

I don't think all the entries in this are equally syntactically problematic. For example:

class test(object):
  as  = 1

will always throw an error, as is reserved. import falls into the same category.

However, a number of other entries all, abs, basestring etc, don't throw the same error, i.e.:

class test(object):
    abs = ""
    all = ""
    any = ""
    apply = ""
    ascii = ""
    bin = ""
    basestring  = ""

works just fine. Equally, I can call a module abs and not have an issue (yes, there is a name collision, but it is not a interpreter error).

To your second comment, I think that there is an issue if we have a module called import, but not an issue if we have one called long. Can you provide a bit more colour on what the problem is here before we make a change that is going to affect multiple consumers please?

Thanks! r.

robshakir avatar Jun 12 '18 15:06 robshakir

An example of long causing an issue:

if six.PY3:
  long = int

from . import long

class timeout(PybindBase):
  def __init__(self, *args, **kwargs):
    self.__long = YANGDynClass(base=long.long, is_container='container', yang_name="long", ..., is_config=True)

Here the base=long.long throws an error because we have long as a built-in type.

This yang is from a vendor for some timeout (LACP perhaps?).. this is literally the first yang I have tried :D lucky.. but I wonder how many more potential conflicts I'll find.. (hence I've created this issue)

unsignedint avatar Jun 13 '18 05:06 unsignedint

CLAs look good, thanks!

googlebot avatar Jun 13 '18 05:06 googlebot

Ah, I see.

I think the key thing to deal with here would be where it might become a module name -- this means any container or list, and probably only impacts split-class-dir output. The reserved_name is generically used everywhere right now, so I think we would want to split that function out and have these used in different contexts.

Thoughts?

robshakir avatar Jun 16 '18 01:06 robshakir

Hi,

Could you please rebase to a recent versions of pyangbind ?

So far, pyangbind has been running the current list of reserved words... I think the discussion about splitting the reserved-words check must be in an issue and not a PR.

JoseIgnacioTamayo avatar Oct 13 '23 07:10 JoseIgnacioTamayo

Closing old issue.

JoseIgnacioTamayo avatar Dec 11 '23 19:12 JoseIgnacioTamayo