Skip to content

Fix Python 3.9 support (?) #74

@dlqqq

Description

@dlqqq

Description

It seems our typing annotations may be breaking Python 3.9 support. This is what happens when I attempt jlpm dev:install on a Python 3.9 env:

/Users/dlq/micromamba/envs/rtccore/lib/python3.9/site-packages/jupyterlab/debuglog.py:54: UserWarning: An error occurred.
  warnings.warn("An error occurred.")
/Users/dlq/micromamba/envs/rtccore/lib/python3.9/site-packages/jupyterlab/debuglog.py:55: UserWarning: ModuleNotFoundError: There is no labextension at .. Errors encountered: [TypeError("the 'package' argument is required to perform a relative import for '.'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), TypeError("unsupported operand type(s) for |: 'type' and 'NoneType'"), ModuleNotFoundError("No module named 'gyp'"), ModuleNotFoundError("No module named 'gyp'")]
  warnings.warn(msg[-1].strip())
/Users/dlq/micromamba/envs/rtccore/lib/python3.9/site-packages/jupyterlab/debuglog.py:56: UserWarning: See the log file for details: /var/folders/7m/7mx2jygx4h36_p53dtc7gxwr0000gq/T/jupyterlab-debug-e17fzfd_.log
  warnings.warn(f"See the log file for details: {log_path!s}")

The error log implies that type annotations that use the | operator (e.g. _contents_manager: AsyncContentsManager | ContentsManager) are causing Python 3.9 incompatibility. However, this should be fixed by making sure every module has a from __future__ import annotations import at the top level: https://stackoverflow.com/questions/76579085/python-3-9-use-or-operator-for-union-types

Proposed solution

  • Figure out if from __future__ import annotations really allows the | operator to be used in types in Python 3.9.
  • If so: Make sure every module has that import.
  • If not: Replace | operators with Union[type1, type2, ...].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions