Skip to content

Fix ignored mypy errors #144

Closed
Closed

Description

@kushagra189

Currently, for the sake of completing the pipeline, we have ignored certain mypy errors. We need to work on a solution in order to make our code implementation compatible with mypy standards without ignoring these lines.

Suggestion:
The majority errors are due to the class-based implementation of foca in order to access it as a property of the Flask Config class. Hence one recommendation is to make the Foca app somehow a parent of the Connexion app, in a similar way that the Connexion app is a parent of the Flask app. Or to extend the Flask app (inside the Connexion) in a way that it has a property foca of type Config.

Activity

  1. self-assigned this
    on Sep 29, 2022
  2. added
    status flag: discuss
    type: bug
    type: ci / cd
    type: maintenance
    workload: days
    on Sep 29, 2022
  3. moved this to Todo access control in FOCA releaseon Dec 2, 2023
  4. moved this from Todo access control to Todo other in FOCA releaseon Dec 2, 2023
  5. added
    priority: high
    and removed
    status flag: discuss
    type: bug
    type: ci / cd
    on Dec 2, 2023
  6. modified the milestones: v1.0.0, v0.13.0 on Dec 2, 2023
  7. self-assigned this
    on Dec 10, 2023
  8. modified the milestones: v0.13.0, v1.0.0 on May 20, 2024
  9. uniqueg commented on Oct 18, 2026

    @uniqueg
    Member

    Refined proposal

    Most of the remaining type: ignores (about 30 in foca/, 16 of them attr-defined) come from attaching the config as a dynamic attribute to Flask's Config and reading it via current_app.config.foca. This also fails under Connexion 3, where security and error handlers run outside a Flask context. Instead of subclassing Flask/Connexion, we would add typed, framework-agnostic access:

    • foca.get_config() -> Config: returns current_app.config.foca inside an app context, else the config of the most recently created FOCA app (module-level registry), else raises RuntimeError. app.app.config.foca stays for app code. Foca.conf is documented for use outside requests.
    • get_collection(db, collection) -> pymongo.collection.Collection replaces the repeated ...dbs[x].collections[y].client chains.
    • Replace all internal current_app.config.foca uses (auth, errors, enforcement, permissions controllers, Celery factory).
    • log_traffic reads method, path, protocol and remote address through one helper based on flask.request instead of connexion.request.environ, which no longer exists in Connexion 3 (C3 2.5).
    • One translation point _connexion_add_api_kwargs(spec) with a typed ConnexionOptions model (strict_validation, validate_responses, swagger_ui, serve_spec, swagger_ui_path, base_path, resolver, extra keys allowed) used by register_openapi and the permissions API, so only this function changes for Connexion 3 (C3 2.6).
    • Remaining ignores (PyJWT/cryptography typing) are fixed individually or justified with a comment.

    Acceptance criteria

    • No type: ignore[attr-defined] for config.foca left in foca/; mypy passes in CI; remaining ignores have a reason comment.
    • Tests: get_config() inside and outside an app context, and without any app (error).
    • Test: log_traffic inside a real app request (not a mocked environ).
    • Test: ConnexionOptions from today's connexion: {options: {...}} produces the same add_api kwargs.
    • README and template recommend get_config().

    Breaking changes
    None expected; current_app.config.foca keeps working. SpecConfig.connexion becomes a typed model that still accepts the current keys.

    Planned PR
    11 (refactor: typed config access, agnostic helpers).

  10. moved this from Todo other to Done in FOCA releaseon Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: hightype: maintenanceworkload: days

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions