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

Make Python less selfish #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Make Python less selfish #70

wants to merge 1 commit into from

Conversation

ssanderson
Copy link
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

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