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

Fix type annotation in Python < 3.8 #219

Merged

Conversation

Taragolis
Copy link
Contributor

During tests in Apache Airflow integration with 0.7.0rc2 (apache/airflow#36897) I've got an error

Traceback (most recent call last):
  File "/usr/local/bin/airflow", line 8, in <module>
    sys.exit(main())
  File "/opt/airflow/airflow/__main__.py", line 57, in main
    args.func(args)
  File "/opt/airflow/airflow/cli/cli_config.py", line 49, in command
    return func(*args, **kwargs)
  File "/opt/airflow/airflow/utils/providers_configuration_loader.py", line 55, in wrapped_function
    return func(*args, **kwargs)
  File "/opt/airflow/airflow/cli/commands/db_command.py", line 63, in resetdb
    db.resetdb(skip_init=args.skip_init)
  File "/opt/airflow/airflow/utils/session.py", line 79, in wrapper
    return func(*args, session=session, **kwargs)
  File "/opt/airflow/airflow/utils/db.py", line 1656, in resetdb
    drop_airflow_models(connection)
  File "/opt/airflow/airflow/utils/db.py", line 1728, in drop_airflow_models
    db = _get_flask_db(connection.engine.url)
  File "/opt/airflow/airflow/utils/db.py", line 714, in _get_flask_db
    from airflow.www.session import AirflowDatabaseSessionInterface
  File "/opt/airflow/airflow/www/session.py", line 23, in <module>
    from flask_session.sqlalchemy import SqlAlchemySessionInterface
  File "/usr/local/lib/python3.8/site-packages/flask_session/sqlalchemy/__init__.py", line 1, in <module>
    from .sqlalchemy import SqlAlchemySession, SqlAlchemySessionInterface  # noqa: F401
  File "/usr/local/lib/python3.8/site-packages/flask_session/sqlalchemy/sqlalchemy.py", line 12, in <module>
    from ..base import ServerSideSession, ServerSideSessionInterface
  File "/usr/local/lib/python3.8/site-packages/flask_session/base.py", line 26, in <module>
    class ServerSideSession(CallbackDict, SessionMixin):
  File "/usr/local/lib/python3.8/site-packages/flask_session/base.py", line 56, in ServerSideSession
    initial: Optional[dict[str, Any]] = None,
TypeError: 'type' object is not subscriptable

dict[str, Any] available only Python 3.9+, it could be enabled in lower version by add in top of the imports

from __future__ import annotations

However since in flask-session do not use future annotations (https://docs.python.org/3/library/__future__.html#module-contents) I just use Dict from typing instead

@Taragolis
Copy link
Contributor Author

cc: @Lxstr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change not relevant to this PR, it changes by the ruff.

@Lxstr Lxstr merged commit 916ee9d into pallets-eco:development Mar 12, 2024
3 checks passed
@Lxstr
Copy link
Contributor

Lxstr commented Mar 12, 2024

Let me know if you need another rc. Or anything else I can do

@Taragolis Taragolis deleted the fix-compat-py38-annotations branch March 12, 2024 15:06
@Taragolis
Copy link
Contributor Author

Thanks, it is not required yet. I consider to install from the branch, e.g. flask-session @ git+https://github.com/pallets-eco/flask-session.git@development that is might speed up to check SA session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants