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/transformer.py #14

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/transformer.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/transformer.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/transformer.py from thumbor's virtualenv.

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

../thumbor/thumbor/transformer.py:19: error: Module "thumbor.ext.filters" has no attribute "_bounding_box"  [attr-defined]
../thumbor/thumbor/transformer.py:26: error: Function is missing a type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:33: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:33: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:40: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:40: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:72: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:72: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:101: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:110: error: Argument 1 to "int" has incompatible type "Optional[Any]"; expected "Union[str, bytes, SupportsInt, SupportsIndex, SupportsTrunc]"  [arg-type]
../thumbor/thumbor/transformer.py:112: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:112: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:148: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:151: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:151: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:178: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:178: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:205: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:205: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:216: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:216: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:238: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:238: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:241: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:244: error: Function is missing a type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:262: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:262: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:312: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:312: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:318: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:323: error: Item "None" of "Optional[Any]" has no attribute "__iter__" (not iterable)  [union-attr]
../thumbor/thumbor/transformer.py:334: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:334: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:342: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:342: note: Use "-> None" if function does not return a value
../thumbor/thumbor/transformer.py:348: error: Unsupported left operand type for > ("None")  [operator]
../thumbor/thumbor/transformer.py:348: note: Both left and right operands are unions
../thumbor/thumbor/transformer.py:349: error: Unsupported left operand type for < ("None")  [operator]
../thumbor/thumbor/transformer.py:349: note: Both left and right operands are unions
../thumbor/thumbor/transformer.py:379: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "int")  [assignment]
../thumbor/thumbor/transformer.py:402: error: Function is missing a return type annotation  [no-untyped-def]
../thumbor/thumbor/transformer.py:402: note: Use "-> None" if function does not return a value
Found 26 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/transformer.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/transformer.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/transformer.py label for fixing issues with the specified file
Projects
None yet
Development

No branches or pull requests

1 participant