Skip to content

Type string issues in python 3.10+ #38

@mattprintz

Description

@mattprintz

When running beaker in Python3.10 with the latest version of archytas and the contexts from askem-beaker, there are errors in the newish utils.py/type_to_str() function.

Initially it fails due to the usage of a type of Union without a type argument.

│ /home/matt/tmp/type-string-error/lib/python3.10/site-packages/archytas/utils.py:59 in            │
│ type_to_str                                                                                      │
│                                                                                                  │
│   56 │   elif t is None:                                                                         │
│   57 │   │   return "None"                                                                       │
│   58 │   else:                                                                                   │
│ ❱ 59 │   │   raise ValueError(f"Unsupported type {t}")                                           │
│   60                                                                                             │
│                                                                                                  │
│ ╭───── locals ─────╮                                                                             │
│ │ t = typing.Union │                                    

If we fix that, either by fixing the project or surpressing the error in the function, we see the bigger issue.
New versions of Python are internally representing Optional[str] as str | None so any usage of Optional throws an error as the strings don't match.

The type string need to be normalized somehow before being compared.

Steps to reproduce:

  1. Download the attached askem-beaker wheel file
    askem_beaker-1.2.2.zip
  2. Create a virtualenv and install the specific versions we need to test:
    pip install archytas==1.2.1 beaker-kernel==1.7.2 ./askem_beaker-1.2.2-py3-none-any.whl
  3. Run beaker notebook in local mode in a terminal:
    beaker notebook
(type-string-error) matt@mavis:~/tmp$ beaker notebook
[I 2024-10-29 11:37:48.348 BeakerServerApp] beaker_kernel.server.main | extension was successfully linked.
...
[I 2024-10-29 11:37:48.527 BeakerServerApp] Serving notebooks from local directory: /home/matt/tmp
[I 2024-10-29 11:37:48.528 BeakerServerApp] Jupyter Server 2.14.2 is running at:
[I 2024-10-29 11:37:48.528 BeakerServerApp]     http://localhost:8888/
[I 2024-10-29 11:37:48.528 BeakerServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
  1. Open the page in the console output (probably http://localhost:8888/ but port may change if 8888 is in use)
  2. As soon as the page loads, you should start seeing the errors in the console. Press Ctrl-C in the console to exit.
I 2024-10-29 11:37:55.685 BeakerServerApp] Kernel started: 2b42ea86-9f74-4306-99c9-bc7f08bede80
Warning: The usage of the @toolset decorator is deprecated and the decorator will be removed in a future version.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/lib/python3.10/runpy.py:196 in _run_module_as_main                                          │
│                                                                                                  │
│   193 │   main_globals = sys.modules["__main__"].__dict__                                        │
...
  1. All contexts are checked for validity on each initial connection.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions