Skip to content

Make Python less selfish#70

Open
ssanderson wants to merge 1 commit into
masterfrom
selfless
Open

Make Python less selfish#70
ssanderson wants to merge 1 commit into
masterfrom
selfless

Conversation

@ssanderson
Copy link
Copy Markdown
Collaborator

@ssanderson ssanderson commented May 4, 2019

Making the Python world a little less selfish.

@ssanderson ssanderson changed the title ENH: Prototype of selfless transformer. Make Python less selfish May 4, 2019
@asottile
Copy link
Copy Markdown

asottile commented May 4, 2019

🤔

>>> @selfless
... def f(x):
...     x = x
...     def g():
...         return x + 2
...     def h(new_x):
...         x = new_x
... 
>>> 
>>> import dis
>>> dis.dis(f)
Disassembly of __init__:
  1           0 LOAD_FAST                1 (x)
              2 LOAD_FAST                0 (self)
              4 STORE_ATTR               0 (x)
              6 LOAD_CONST               0 (None)
              8 RETURN_VALUE

Disassembly of g:
  5           0 LOAD_FAST                0 (self)
              2 LOAD_ATTR                0 (x)
              4 LOAD_CONST               0 (2)
              6 BINARY_ADD
              8 RETURN_VALUE

Disassembly of h:
  7           0 LOAD_FAST                1 (new_x)
              2 LOAD_FAST                0 (self)
              4 STORE_ATTR               0 (x)
              6 LOAD_CONST               0 (None)
              8 RETURN_VALUE

>>> 

proposal: use notself instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants