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

Compiled nested functions don't retain their __name__ attribute #884

Open
ichard26 opened this issue Aug 5, 2021 · 3 comments
Open

Compiled nested functions don't retain their __name__ attribute #884

ichard26 opened this issue Aug 5, 2021 · 3 comments
Assignees
Labels
area-functions bug priority-0-high python compat Mypyc doesn't match CPython or documented semantics.

Comments

@ichard26
Copy link
Collaborator

ichard26 commented Aug 5, 2021

from typing import Callable

def outer() -> Callable:
    def inner() -> None:
        pass

    return inner

print(f"outer.__name__: {outer.__name__}")
print(f"inner.__name__: {outer().__name__}")
python nested.py
outer.__name__: outer
inner.__name__: innermypyc nested.py > /dev/null && python -c "import nested"
outer.__name__: outer
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "nested.py", line 10, in <module>
    print(f"inner.__name__: {outer().__name__}")
AttributeError: 'inner_outer_obj' object has no attribute '__name__'mypy --version ; python --version ; lsb_release -d
mypy 0.910
Python 3.8.5
Description:	Ubuntu 20.04.2 LTS

I suppose this is because nested functions are implemented as an instance of a special class as I've so heard?

edit: I confirmed this also fails using mypyc from master (commit: python/mypy@68a67ae)

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 6, 2021

This may be related to #718.

@ichard26
Copy link
Collaborator Author

ichard26 commented Nov 5, 2021

Are you sure? I can still reproduce the issuelocally with current master of python/mypy@7640664.

@97littleleaf11
Copy link
Collaborator

@ichard26 Sorry I made a mistake when testing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-functions bug priority-0-high python compat Mypyc doesn't match CPython or documented semantics.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants