Closed falzm closed 4 years ago
Wouldn't a single underscore mean the methods are protected rather than private ?
Wouldn't a single underscore mean the methods are protected rather than private ?
You're right, I didn't know there was different meanings depending on the number of _
s. I'll change to __
.
So, turns out that when I switch previously protected methods to private nothing works anymore:
>>> import exoscale
>>> exo = exoscale.Exoscale(trace=False)
>>> gva2 = exo.compute.get_zone("ch-gva-2")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/marc/Documents/Exoscale/git/python-exoscale/exoscale/api/compute.py", line 2266, in get_zone
zones = list(self.list_zones(id=id, name=name))
File "/Users/marc/Documents/Exoscale/git/python-exoscale/exoscale/api/compute.py", line 2246, in list_zones
yield Zone.__from_cs(i)
AttributeError: type object 'Zone' has no attribute '_ComputeAPI__from_cs'
I thought this was a matter of convention, but turns out it seems to be actually changing the behavior of the interpreter ¯\_(ツ)_/¯
So maybe Make API classmethods protected is fine given your original post ?
So maybe Make API classmethods protected is fine given your original post ?
Let's say it is ;)
@falzm you want double leading and trailing underscores
EDIT: I mean it's not a good idea but if you really want to hide them from most IDEs and auto completioners it's good enough.
Here is how double leading underscore work: https://docs.python.org/3/tutorial/classes.html#private-variables
@falzm you want double leading and trailing underscores
Yes you're right, after a bit of digging in this direction it would be the "right" thing to do but pragmatically the single leading underscore should be enough to signal the library users.
This article is very useful: https://dbader.org/blog/meaning-of-underscores-in-python
Don't forget to rename the commit :)
Yep, I'll fix the commit message at merge time ;)
Integration tests passed OK ✅
Hide API
classmethod
functions from the public API to avoid users being tempted to use them directly.