Skip to content

Enable mypy pre-commit hook #2674

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

Merged
merged 19 commits into from
Oct 10, 2022
Merged

Enable mypy pre-commit hook #2674

merged 19 commits into from
Oct 10, 2022

Conversation

VannTen
Copy link
Member

@VannTen VannTen commented Aug 8, 2022

see #2673

@sesheta sesheta added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 8, 2022
Copy link
Contributor

@mayaCostantini mayaCostantini left a comment

Choose a reason for hiding this comment

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

lgtm, thanks! :100

@sesheta
Copy link
Member

sesheta commented Aug 9, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mayaCostantini

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sesheta sesheta added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 9, 2022
@VannTen
Copy link
Member Author

VannTen commented Aug 9, 2022 via email

Having the config in pyproject.toml make it usable by other tools,
notably IDE.
@sesheta sesheta added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 17, 2022
@VannTen
Copy link
Member Author

VannTen commented Aug 18, 2022

Related to the errors in thoth/storages/graph/models_base.py:
https://docs.sqlalchemy.org/en/14/orm/extensions/mypy.html

TL;DR (from my understanding)typing support is not super practical in SQLAlchemy
declarative API in 1.3/1.4. Either needs a mypy plugin (which is alpha and
deprecated for sqlalchemy 2.0) or switching to 2.0 (in dev).

@VannTen
Copy link
Member Author

VannTen commented Aug 23, 2022

Note: in 2e5cd41 I explicited what I assumed to be the intent.

@VannTen
Copy link
Member Author

VannTen commented Sep 8, 2022

The graph/* errors are a bit hard to fix without restructuring quite intensely
the code, so I think we could benefits from merging this as is. (Finding a way
to exclude thoth.storages.graph module would be great, but for now I don't know
how (see python/mypy#10820))

For reviewers: I think most of the commits are reviewable individually. In fact
they can probably be cherry-picked individually as well.

Some are "breaking" changes to the API, (in the types) but in most cases the
underlying implementation was already breaking stuff (or the call sites used the
code correctly despite wrong types ! ^).

I will detail the commits changing the API in a later comment.

@VannTen VannTen force-pushed the fix_mypy branch 3 times, most recently from d1d1d0b to 525bb58 Compare September 14, 2022 09:08
@VannTen
Copy link
Member Author

VannTen commented Sep 14, 2022

Commits breaking API.

  • 6060262 Fix incompatible method overload for AnalysisByDigest
    Only call site has a pending PR
  • solvers:
    590a8ab Fix incompatible child class method override
    ab70c50 Use TypedDict for reifying "all or nothing" for solver infos
    -> Align the API + use types to states parameters requirements -> api change
  • c10b40b sync: More precise handlers types
    Not breaking (List are Iterable)
    3e6d529 sync: remove unused parameters and refactor
    Align interface with behavior (removed parameters were not used)
  • 6e7061b CephCache
    Correct return type
  • ec8b10b dependency_monkeys
    Correct return type
  • 33a6bca Trying to fix get_document_ on solvers
    This avoid the needs for override on get_document_count but kinda drop type safety for it.
    Best option would be to make it a static method / utils and feed it the result of get_document_listing instead of including it in the class (since we don't do anything more efficient like using list_objects or something like that)

Note that this raises the minimal python version to 3.8
We use random.shuffle, but the import masked the random module with the
random function.
This is a cleanup after 5d8b2bc, which
removed amun + inspection_only stuff from sync functions, but not from
the sync_documents "dispatcher" function.

We also refactor the sync function for clarity.
- List -> Iterable (typing)
  Iterable is more flexible + match more closely the internal of the sync
  functions.
- 4 ints tuples return instead of polymorphic
This is a breaking change of the API, but since it was broken (turning a
string into a dict).

fix thoth-station#2689
We need to rely on CI and the graph module is a bit wild for now.
This should be temporary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants