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

Signature.return_annotation somehow turns into string when the function is ran under a marimo cell #3312

Open
Retorikal opened this issue Dec 30, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Retorikal
Copy link

Retorikal commented Dec 30, 2024

Describe the bug

Running code snippet

from inspect import signature

def wololo(i: int, ii: int) -> tuple[str, int]:
    a = i+ii
    b = ii-i
    c = f"{a} {b}"
    return c, b

print(signature(wololo).return_annotation, type(signature(wololo).return_annotation))

on python console it prints tuple[str, int] <class 'types.GenericAlias'> according to expectation, but on a marimo cell it prints tuple[str, int] <class 'str'>, so somehow the return annotation type is a string instead of an actual type object.

Also occurs on functions with primitive return type annotations like def wololo(i: int, ii: int) -> int

Could be a inspect.signature bug too but I haven't seen any clue pointing that way yet

Environment

{
  "marimo": "0.9.34",
  "OS": "Linux",
  "OS Version": "6.8.12-4-pve",
  "Processor": "",
  "Python Version": "3.11.2",
  "Binaries": {
    "Browser": "--",
    "Node": "--"
  },
  "Dependencies": {
    "click": "8.1.7",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.7",
    "narwhals": "1.17.0",
    "packaging": "24.2",
    "psutil": "6.1.0",
    "pygments": "2.18.0",
    "pymdown-extensions": "10.12",
    "pyyaml": "6.0.2",
    "ruff": "0.8.2",
    "starlette": "0.41.3",
    "tomlkit": "0.13.2",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.32.1",
    "websockets": "14.1"
  },
  "Optional Dependencies": {
    "pandas": "2.2.3"
  }
}

Code to reproduce

No response

@Retorikal Retorikal added the bug Something isn't working label Dec 30, 2024
@Retorikal Retorikal changed the title Signature. return_annotation somehow turns into string when the function is ran under a marimo cell Signature.return_annotation somehow turns into string when the function is ran under a marimo cell Dec 30, 2024
@akshayka
Copy link
Contributor

It looks like a from __future__ import annotations import affects the cell runner. Is this a big issue for you, or just a curiosity?

Image

@Retorikal
Copy link
Author

For my own uses i can make a workaround.

Thank you for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants