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

[Bootcamp Task] Implement static typing for thumbor/threadpool.py #6

Open
heynemann opened this issue Jan 30, 2022 · 0 comments
Open
Labels
L1 Level 1 Bootcamp Task mypy Tasks related to static typing using MyPy. task Bootcamp task. Feel free to grab it and work on it. For more information ping a bootcamp mentor. thumbor/threadpool.py label for fixing issues with the specified file

Comments

@heynemann
Copy link
Member

Areas of Expertise

MyPy, static typing

You will learn more about how to use statically typed python code. mypy is an optional static type checker for python. It provides compile-time type checking.

Summary

In this task you'll fix thumbor/threadpool.py to be typed.

Involved Modules

Task Relevance

Providing type safety is important both for thumbor and the projects that depend on it. This way we can eliminate type errors, like None where you don't expect None or an integer where you expect a string.

How to complete this task?

To complete this task, read mypy docs on how to get started and run mypy thumbor/threadpool.py from thumbor's virtualenv.

When creating this task, this was the output of running mypy thumbor/threadpool.py:

../thumbor/thumbor/threadpool.py:20: error: Function is missing a type annotation  [no-untyped-def]
../thumbor/thumbor/threadpool.py:26: error: "Type[ThreadPool]" has no attribute "_instance"  [attr-defined]
../thumbor/thumbor/threadpool.py:27: error: "Type[ThreadPool]" has no attribute "_instance"  [attr-defined]
../thumbor/thumbor/threadpool.py:28: error: "Type[ThreadPool]" has no attribute "_instance"  [attr-defined]
../thumbor/thumbor/threadpool.py:29: error: "Type[ThreadPool]" has no attribute "_instance"  [attr-defined]
../thumbor/thumbor/threadpool.py:32: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/threadpool.py:32: note: Use "-> None" if function does not return a value
../thumbor/thumbor/threadpool.py:33: error: "Type[ThreadPool]" has no attribute "_instance"  [attr-defined]
../thumbor/thumbor/threadpool.py:34: error: "Type[ThreadPool]" has no attribute "_instance"  [attr-defined]
../thumbor/thumbor/threadpool.py:36: error: "Type[ThreadPool]" has no attribute "_instance"  [attr-defined]
../thumbor/thumbor/threadpool.py:38: error: Function is missing a type annotation  [no-untyped-def]
../thumbor/thumbor/threadpool.py:42: error: Incompatible types in assignment (expression has type "None", variable has type "ThreadPoolExecutor")  [assignment]
../thumbor/thumbor/threadpool.py:44: error: Function is missing a type annotation  [no-untyped-def]
../thumbor/thumbor/threadpool.py:47: error: Function is missing a type annotation  [no-untyped-def]
../thumbor/thumbor/threadpool.py:51: error: Function is missing a type annotation  [no-untyped-def]
../thumbor/thumbor/threadpool.py:57: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/threadpool.py:57: note: Use "-> None" if function does not return a value
Found 15 errors in 1 file (checked 1 source file)

This gives you all errors in the file you will fix. Don't worry if there are types of other packages (other thumbor files or thumbor dependencies) failing. If that's the case we can ignore these for now using this kind of annotation:

import module_without_mypy  # type: ignore

For more details check this page.

Once you get to a point where running mypy thumbor/threadpool.py returns no errors, go ahead and submit a PR. The output should look like this:

Success: no issues found in 1 source file

Task Workflow

The workflow for completing tasks in thumbor goes like this:

  1. Fork the involved repositories
  2. In each repository there's a documentation on how to install dependencies and initialize your environment
  3. Hack, in no particular order:
    • Write code & tests
    • Write new tests
    • Write docs
    • Improve design
    • Check that all tests pass
    • Repeat until you're satisfied
  4. Submit a pull request.
@heynemann heynemann added L1 Level 1 Bootcamp Task mypy Tasks related to static typing using MyPy. task Bootcamp task. Feel free to grab it and work on it. For more information ping a bootcamp mentor. thumbor/threadpool.py label for fixing issues with the specified file labels Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L1 Level 1 Bootcamp Task mypy Tasks related to static typing using MyPy. task Bootcamp task. Feel free to grab it and work on it. For more information ping a bootcamp mentor. thumbor/threadpool.py label for fixing issues with the specified file
Projects
None yet
Development

No branches or pull requests

1 participant