black
The uncompromising Python code formatter (by psf)
mypy
Optional static typing for Python (by python)
Our great sponsors
black | mypy | |
---|---|---|
281 | 95 | |
31,748 | 15,051 | |
2.1% | 2.4% | |
9.6 | 9.9 | |
10 days ago | 7 days ago | |
Python | Python | |
MIT License | MIT License |
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
black
Posts with mentions or reviews of black.
We have used some of these posts to build our list of alternatives
and similar projects. The last one was on 2023-03-16.
-
The Ruff python linter is insanely good
The whole point of Black is that it's opinionated and that it knows better than you. I can always recommend you read the single quotes incident on GitHub to gain more insight about what Black really is: https://github.com/psf/black/issues/118
-
“Don’t listen to language designers”
Indentation is fine for a presentation layer and indeed prettifiers like black are a good thing. But once you start picking up fragments of code and moving them around, it's much easier to have that interaction when there are visible symbols demarcating the nesting structure.
-
Do I have to do this line by line…please say there is a quick way to do this
A good tool that i use to automatically indent my lines of code for python is 'Black'. https://github.com/psf/black
Even better, set pycharm to use Black and never spend time with formatting again.
Let black do it for you
Someone already did
-
Python projects with best practices on Github?
black is very well organized generic Python project example.
-
Ruff: A new, fast and correct Python checker/linter
Here are insights about flake8, black, and mypy and the amount of work that went into mypy seems … just massive?!
-
Free Code Analysis
black and mypy?
mypy
Posts with mentions or reviews of mypy.
We have used some of these posts to build our list of alternatives
and similar projects. The last one was on 2023-03-24.
-
CS176a and Research Advice
I'll try to address both of your replies, sorry for the wait. You should be comfortable with The Python Tutorial -- everything through Chapter 9 is really useful. Python is a good language to know for rapidly getting your ideas into the computer, for programming interviews and festive things like Advent of Code. I really recommend getting comfortable with Python's type annotations and a type checker like mypy. It will save you a lot of headache.
-
How do you code in a non-statically typed, imperative language after learning F#?
Use of optional types has been appearing in third party libraries more and more. The mypy type checker finally hit version 1, which I've been using for years. Flake8 for linting and black + isort for formatting are useful tools.
- Python-based compiler achieves orders-of-magnitude speedups
- What is the status of Python 3.11?
-
Pain when going back to other languages
there was an attempt to make mypy disallow boolean tests on non-boolean, but it was removed https://github.com/python/mypy/issues/3195 . https://mypy.readthedocs.io/en/stable/error_code_list2.html#check-that-expression-is-not-implicitly-true-in-boolean-context-truthy-bool . mypy can at best check that a boolean context is used on variables that can be none, or define __bool__ or __len__ https://github.com/python/mypy/pull/13686 . Not great but that's already something. I wish requests could deprecate the __bool__ feature with some mypy annotation - it probably cannot be done.
-
Why Type Hinting Sucks!
But MyPy on strict is complaining that slow_add is missing a type annotation, after reading this issue you realize that @overload is only useful for users of your function but the body of your function will not be tested using @overload. Fortunately in the discussion on that issue there is an alternative example of how to implement:
https://github.com/python/mypy same with typeshed https://github.com/python/typeshed
-
It is becoming difficult for me to be productive in Python
It's pretty common for codebases to use CI and CD to automatically package, run tests, upload, and/or deploy projects. If you add mypy to your CI test pipeline, then no code will pass tests that violates type annotations, and therefore, you can not deploy code that violates the stated types.
-
40x Faster! We rewrote our project with Rust!
I use pyright as my LSP in Neovim for Python code, so I just use mypy for static type checking within CI/CD and GitHub actions.
What are some alternatives?
When comparing black and mypy you can also consider the following projects:
autopep8 - A tool that automatically formats Python code to conform to the PEP 8 style guide.
pyright - Static Type Checker for Python
yapf - A formatter for Python files
prettier - Prettier is an opinionated code formatter.
Pylint - It's not just a linter that annoys you!
isort - A Python utility / library to sort imports.
pyre-check - Performant type-checking for python.
pycodestyle - Simple Python style checker in one Python file
autoflake - Removes unused imports and unused variables as reported by pyflakes
Flake8 - flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.
pytype - A static type analyzer for Python code