Code: Select all
class S(object):
__slots__ = ['val']
def __init__(self, v):
self.val = v
x = S(42)
print(x.val)
x.new = "not possible"
Code: Select all
class S(object):
__slots__ = ['val']
def __init__(self, v):
self.val = v
x = S(42)
print(x.val)
x.new = "not possible"
If using __slots__ doesn't prevent __dict__ from being created for an instance of a class, is there any benefit to using them?pythoncoder wrote: ↑Sat Aug 03, 2019 6:19 amThis has been discussed here. As far as I can see it hasn't been implemented in the official build (unfortunately).
Maybe the "slots" being referred to isn't the same as "__slots__"?MicroPython doesn’t maintain symbolic local environment, it is optimized to an array of slots
It's actually the exact same concept, but applied to a different feature (variables in local scope, compared to class attributes).manseekingknowledge wrote: ↑Wed Aug 21, 2019 2:42 pmMaybe the "slots" being referred to isn't the same as "__slots__"?
Code: Select all
x = 3
y = 7
print(x + y)
Code: Select all
locals = {}
locals['x'] = 3
locals['y'] = 7
print(locals['x'] + locals['y'])
Code: Select all
locals = [None, None]
locals[0] = 3
locals[1] = 7
print(locals[0] + locals[1])
On the PR you would see a notification to indicate that it had been merged. e.g. compare to https://github.com/micropython/micropython/pull/5016 If you look at some other projects, if the merge is done by the maintainer via the Github UI will actually mark a PR as "merged". However, Damien manually pulls the commits in (not using the Github interface) so this doesn't happen for MicroPython PRs.manseekingknowledge wrote: ↑Wed Aug 21, 2019 2:42 pmSecond, I incorrectly assumed the change @pfalcon made that you linked to was pulled in and was just a partial implementation of slots that offered some benefit that I wasn't understanding, but I now see the changes were never pulled in because when I grep for some of the changes I come up empty handed.