It’s like a off-by-one error on your wedding day.
>>> from plusonedecorator import plus_one >>> @plus_one ... def cost(quantity: int, marginal_cost: float) -> float: ... """Compute the cost of production.""" ... return quantity * marginal_cost ... >>> cost(1000, 0.25) 251.0 >>> @plus_one ... def invite(name: str, pronoun: str) -> str: ... """Decide to invite someone to your wedding.""" ... return f"Let's be sure to invite {name} and {pronoun}." ... >>> invite("Emilia", "her") "Let's be sure to invite Emilia and her plus one.
I’m like a pâtissier, except I decorate functions instead of cakes, and I decorate with U+1F4A9 instead of frosting.
>>> from aholedecorator import a_hole >>> @a_hole ... def hello(name: str = "friend") -> str: ... return f"Hello {name}, I hope you are well." ... >>> hello() 'Hello friend, I hope you are well.' >>> hello() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/chris/Documents/projects/gists/a_hole_decorator/aholedecorator.py", line 70, in new_func raise AHoleError(choice(_MESSAGES)) aholedecorator.
Recently, I’ve been exploring the type hints functionality in Python. The other day, I ran across what I think is a bug (already known) in mypy.
Here is a minimal working example of the issue I came across:
1 2 3 4 from fractions import Fraction my_value = 1 + sum([Fraction(k + 1, 5 ** k) for k in range(5)]) print(f"The result is {my_value}.") This program runs as you would expect.
Here’s another fun thing I made.
GitHub repo
I spent way too much time working on this. Enjoy!
I’ve created a GitHub repository based on the New York Times’ COVID-19 database.
The New York Times has been compiling COVID-19 data from various state health departments. They have published the data as a GitHub repository. There are two files of interest in their repository: us-states.csv and us-counties.csv.
In these CSV files, each row represents the number of (confirmed) cases and deaths in a particular geographical area as of a particular date.