Top 12 Python Decorator Projects
-
httpretty
Intercept HTTP requests at the Python socket level. Fakes the whole socket module (by gabrielfalcao)
-
Project mention: Python’s “Type Hints” are a bit of a disappointment to me | news.ycombinator.com | 2022-04-21
Every point in this blog post strikes me as either (1) unaware of the tooling around python typing other than mypy, or (2) a criticism of static-typing-bolted-on-to-a-dynamically-typed-language, rather than Python's hints. Regarding (1), my advise to OP is to try out Pyright, Pydantic, and Typeguard. Pyright, especailly, is amazing and makes the process of working with type hints 2 or 3 times smoother IMO. And, I don't think points that fall under (2) are fair criticisms of type *hints*. They are called hints for a reason.
Otherwise, here's a point-by-point response, either recommending OP checks out tooling, or showing that the point being made is not specific to Python.
> type hints are not binding.
There are projects [0][1] that allow you to enforce type hints at runtime if you so choose.
It's worth mentioning that this is very analogous to how Typescript does it, in that type info is erased completely at runtime.
> Type checking is your job after all, ...[and that] requires maintenance.
There are LSPs like Pyright[2] (pyright specifically is the absolute best, IMO) that report type errors as you code. Again, this is very very similar to typescript.
> There is an Any type and it renders everything useless
I have never seen a static-typing tool that was bolted on to a dynamically typed language, without an `Any` type, including typescript.
> Duck type compatibility of int and float
The author admits that they cannot state why this behavior is problematic, except for saying that it's "ambiguous".
> Most projects need third-party type hints
Again, this is a criticism of all cases where static types are bolted on dynamically typed languages, not Python's implementation specifically.
> Sadly, dataclasses ignore type hints as well
Pydantic[3] is an amazing data parsing library that takes advantage of type hints, and it's interface is a superset of that of dataclasses. What's more, it underpins FastAPI[4], an amazing API-backend framework (with 44K Github stars).
> Type inference and lazy programmers
The argument of this section boils down to using `Any` as a generic argument not being an error by default. This is configurable to be an error both in Pyright[5], and mypy[6].
> Exceptions are not covered [like Java]
I can't find the interview/presentation, but Guido Van Rossum specifically calls out Java's implementation of "exception annotations" as a demonstration of why that is a bad idea, and that it would never happen in Python. I'm not saying Guido's opinion is the absolute truth, but just letting you know that this is an explicit decision, not an unwanted shortcoming.
[0] https://github.com/RussBaz/enforce
[1] https://github.com/agronholm/typeguard
[2] https://github.com/microsoft/pyright
[3] https://pydantic-docs.helpmanual.io
[4] https://github.com/tiangolo/fastapi
[5] https://github.com/microsoft/pyright/blob/main/docs/configur...
[6] https://mypy.readthedocs.io/en/stable/config_file.html#confv...
-
SonarQube
Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.
-
-
Deal
Design by contract for Python. Write bug-free code. Add a few decorators, get static analysis and tests for free.
Project mention: deal: Design by contract for Python. Write bug-free code. Add a few decorators, get static analysis and tests for free. | reddit.com/r/pythoncoding | 2022-05-26 -
If you’re a Pythonista, Daniel Schep has made a nice lambda-decorators library with the same goals as Middy—replacing Lambda boilerplate.
-
-
-
Scout APM
Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.
-
Project mention: Generate Class & Decorators for your FastAPI project ✨ | reddit.com/r/FastAPI | 2021-10-10
You could now check the package source here: https://github.com/yezz123/fastapi-class
-
-
DecoRouter brings back the decorator functionality to starlette which was deprecated since 1.13.0. This makes migrating from frameworks like FastAPI and Flask easier and code cleaner.
-
Project mention: Micro framework for bots around python-telegram-bot (early development) | reddit.com/r/TelegramBots | 2021-08-26
-
Project mention: decfunc - a library to create decorators in a simple way, using classes | reddit.com/r/Python | 2022-01-16
u/Rawing7 Hey, thanks to your comment, I inspected my code and found some other major problems.I was able to fix them by some refactoring. And I also realized & understood your point on writing decorators via functions. Also, If it is OK with you, I could insert your name into the contributors file.
Python Decorators related posts
Index
What are some of the best open-source Decorator projects in Python? This list will help you:
Project | Stars | |
---|---|---|
1 | httpretty | 1,956 |
2 | enforce | 531 |
3 | Cachier | 404 |
4 | Deal | 402 |
5 | lambda-decorators | 226 |
6 | stupid-python-tricks | 112 |
7 | paprika | 47 |
8 | fastapi-class | 34 |
9 | pyeventbus | 16 |
10 | DecoRouter | 14 |
11 | telegrask | 10 |
12 | decfunc | 3 |
Are you hiring? Post a new remote job listing for free.