Periodic reminder, I'm available for hire for #python or #dotnet work in the #govtech or #dctech scene. (NoVA or Remote)
https://github.com/matthewdeanmartin
#Python
Is uv the future? Is it in my future?
https://www.youtube.com/watch?v=8UuW8o4bHbw&ab_channel=HynekSchlawack
Anyone understand #ContextVars in #python ? I'm trying to add support to #svcs so that when there isn't a web framework with a context to glom onto, that you can use the thread/thread.local/ContextVars and an alternative to the Application/Request that a web framework would provide.
So far, I can only get it to "work" if the ContextVars are globals.
https://gist.github.com/matthewdeanmartin/4a4aaa799df7a454b7ddb7230a78a64f#file-thread-py-L21
Also, because there isn't a good event to hook into for the start of a python app, the start/stop events are decorators and/or context managers.
Also, atexit is braindamaged and only runs once per root process. I'm thinking of pulling in multiexit so that it works with multiple exists (say when using a process pool)
♡ 0 ↻ 0
You can hack python's codec's syntax to create preprocessors for #python so that it will do things like
`python some_code.md`
for some file like this.... But I'll have to extend the magic library first.
```markdown
# # coding: magic.markdown
"... image nested code block here ..."
```
ref: https://pydong.org/posts/PythonsPreprocessor/
- ♡ 0 ↻ 0
Slow down. If you're not patient, you're going to get a coroutine.
Drat, I can't find the time when I said "There should be a IDE plugin that should weep louder and louder as the number of type hinting and linting issues go up"
(quote retweet of report of a way to play sounds scaled to the python garbage collector activity)
https://elk.zone/mastodon.social/@dabeaz/112977921156694540
Pytest plugin tutorial. Go down this path and pretty soon you'll be using pytest as a general task runner.
And everyone should use pytest-randomly or the like. It exposed so many quirks in my test suites.
#cibuildwheel has #python313 (beta) support so it is time to rebuild your native #python libs
https://github.com/pypa/cibuildwheel/releases/tag/v2.20.0
and
https://iscinumpy.dev/post/cibuildwheel-2-19-0/
Here is an example of how I used #cibuildwheel with #mypyc (which in theory can compile to C anything that you can perfectly type annotate)
https://github.com/matthewdeanmartin/untruncate_json/blob/main/cibuildwheel.toml
♡ 1 ↻ 0
So if I have a Bag class, how do I add type hinting if it holds dicts
Oh my, this is deadpan humor or people just don't have a sense of humor
https://stackoverflow.com/questions/42858916/how-to-keep-a-unique-bag-of-dicts
Well that was weird. I offered to be maintainer to 2 libraries and the maintainer made me a collaborator on #pypi. Then without warning I'm removed as collaborator. His git repos are archived - https://github.com/Robpol86/terminaltables
https://github.com/Robpol86/colorclass
I was just doing the minimal maintenance: #python version updates, wheels.
Should I
Archived poll
- fork 'em with a new name3 votes
- forget about it. Make the world move on2 votes
- wait for/do a PEP 5411 votes
- look up at the stars & think: we are so small9 votes
15 voters
IDEA: Convert #python bytecode to emojis, get a tattoo of that, then use LLM vision to read and execute the bytecode, making the worst way to package code and slowest python interpreter ever.
Captures the zeitgeist of my feed right now.
Gotta catch up on mocking with #python at #pyconus
When I ask the bots to write unit tests, they use ALL the mocking libraries,
The theme at the talk is mocking using `unittest` the built in way.
What's a good unit test?
- One assertion at at time -- eh, maybe.
- Independent/isolated/controlled <-- mocking's role
- Relevant/Meaningful <--- hard
- Repeatable/deterministic <-- also mocking's role
- Automatic <- CI all the things
- Descriptive <-- long names♡ 1 ↻ 0Shadows on the wall parable ref! Mocks are the shadows on the wall.
What is I hear, is I should code in a cave.
♡ 0 ↻ 0Good practices
- minimize mocking
- use a library instead of your handrolled
- complex mocking means you should refactor♡ 0 ↻ 0MagicMock means dict, list, str behavior* is mocked automatically. (Confusing why we would ever not use MagicMock)
* dunder methods
♡ 0 ↻ 0@patch autospec helps avoid mocking methods that don't exist. I think.
♡ 0 ↻ 0@patch Code for the talk: https://github.com/liz-acosta/testing-strategies-for-python
♡ 2 ↻ 1@patch Audience question: why/when use doctest? Simple scenarios.
Agreed.
Audience question: can you mock `self`?
me: don't mock yourself, it is bad for self-esteem.
me serious: sounds like how you'd test metaprogramming - I've never seen ordinary tests mock the `self`♡ 0 ↻ 0@patch Audience question: Do mocks have use outside of unittesting?
speaker: maybe in an integration testing scenario with some bits mocked, e.g. a webserver with fake parts
me: Finding a mocking library outside of testing code would be astonishing. I'd want to see comments in such code to justify it.♡ 0 ↻ 0@patch Audience question: how do I encourage the team to do unit tests?
speaker: unit testing something you can do now or you can do emergency app support at 3am
audience question: how do you know if you are mocking too much?
speaker: 2+ maybe
me: 5+, or if it is easy to use the real thing (file system is best example)♡ 0 ↻ 0
You can use contextlib.contextmanager to write #python decorators without 1/2 a page of nested functions and mind-melting type decorators
Oh snap, take that #python 2 developers.
Why doesn't he get the girl?
- didn't format with black
- didn't use +=
- python 2
- could be refactored to print("AAAAAH!\n" * 13)
Phases of writing a #python library:
Here's an idea for a reusable thing. Did anyone write a library for that?
Nope. Fine, I'll write it.
Done!
Found a near dupe
Found a near dupe
Found a near dupe
Found a near dupe
.
.
.
My sparklines-in-server-logs idea has 2 almost exact dupes. Also 11 other generic sparkline libraries, some of which are very, very low effort.
https://github.com/matthewdeanmartin/sparkle_log?tab=readme-ov-file#prior-art
♡ 0 ↻ 0
Okay, memory/cpu sparkline graphs in your logs. Useful if you want to see if your AWS Lambda or ECS containers were under too much load when your Cloudwatch logs were written.
Could have other uses, who knows!
https://pypi.org/project/sparkle-log/
I'll add drive space next
And I should make it support async.
♡ 0 ↻ 0
Wish list:
- linter for pure #python to native library opportunities, e.g. json to orjson, toml to rtoml
- linter for sync to async library opportunities
What trick do y'all use when a function takes a Path as an argument and writes a file? Hypothesis will attempt to write to every location on the hard drive.
Got 5 ways to write a #python function with no body
def f():
"""docstring"""
def f():
...
def f():
pass
f =lambda:None
💻👻
Should I add the `async` keyword to my API methods that call opensearch, redis, postgres, & other microservices?
context:
#connexion + #starlette + #uvicorn + #gunicorn + supervisord, #python 3.12
Archived poll
- No! Stay in line3 votes
- Do, Yes! it!8 votes
- Nothing will change, because GIL, or something2 votes
- What?1 votes
14 voters
And yes, I understand I'd need to call the async version of opensearchpy, etc.
♡ 0 ↻ 0I don't let LLMs make my architectural decisions, I let underpowered Mastodon surveys do it.
♡ 3 ↻ 0
Reading some old news before I add the async keyword before my API controllers
**point**: #asyncio is slow
https://calpaterson.com/async-python-is-not-faster.html
**counterpoint**: well yeah, if you do it wrong.
https://blog.miguelgrinberg.com/post/ignore-all-web-performance-benchmarks-including-this-one
Ever run a bunch of unit tests that leaves files all over the file system like a bunch of mouse turds? You can't even see which of the 1000 unit tests you have wrote those files.
Bot wrote me some code to assert (in the code under test) that if a #pytest is running, assert it writing to tmp_path. To make this a 0 cost abstraction, it would need to intercept file IO like #pytest-network does for network calls. (AFAIK, no one has made that plugin)
https://chat.openai.com/share/95e8a898-ca24-4d50-9869-b791f6a17cff
What dependency injection tool exists for #python that
- isn't a nightmare to use (I'm glaring at you Unity of C# world)
- And is common enough that ChatGPT has seen it, knows how to use it
I'm getting bullied by my unit tests into adding every dependency to my app's entry point function and it getting cumbersome.
There should be more friction involved in #pip installing from something other than pypi.org
Poetry is moving in the right direction away from letting the installer just pick any non-standard repo
https://checkmarx.com/blog/over-170k-users-affected-by-attack-using-fake-python-infrastructure/
Trivia Pursuit double black diamond difficulty question:
Explain the difference between **any**, Any and ANY
We got THREE, common, distinct things named Any that vary only by case.
In #python is #setuptools special and assumed to be always installed even though it isn't part of the standard library? (sort of a phantom stdlib)
e.g. is this setup.py file from #bson wrong, in that it import setuptools but isn't in the list of dependencies?
https://github.com/py-bson/bson/blob/master/setup.py
anyhow, install blew up on my build
Found the source of the change: https://github.com/python/cpython/issues/95299
♡ 0 ↻ 0
Does tox support checking if my #python libraries support the tmux-command-runtime
video for dummies like me: https://willhbr.net/2024/03/15/making-a-compiler-to-prove-tmux-is-turing-complete/
blog post & source for people smarter than me
https://willhbr.net/2024/03/15/making-a-compiler-to-prove-tmux-is-turing-complete/
US. Remote. Not every single jurisdiction in the US, but a lot of them.
♡ 0 ↻ 0
#pypi #python - Did someone already write a tool to front run `safety` or `pip-audit` before anything is installed? I guess something like "poetry lock" and then audit the files for suspicious situations, like CVEs or the repo was created yesterday or the package was published yesterday.
Installing everything then running `safety` imho has always been !@#$!@$ stupid because the malicious code runs during install.
Keep continuously slamming that barn door after the cows left to improve your cybersecurity stance.
♡ 1 ↻ 0
**PEP 666: Enhancing Python's Memory Safety with Rust-Inspired Mechanisms**
Abstract
This PIP proposes to inflict #python with Rust-inspired memory management and safety mechanisms into Python. Sections on Ownership System, Borrowing and References, Lifetimes, Safe and Unsafe Blocks to follow.
This is a joke, okay.
♡ 0 ↻ 0
`import multiprocessing` is a blow from which your function and method signatures will never recover from.
IDEA: create a fork all your #python dependencies so when the maintainer dies or otherwise deletes the repo, you have a full copy and not just the sdist folder.
IDEA: postcard pypi. You distribute your app on the corkboard at the local library on a spool of DVDs. The user takes one and sends a postcard and SASE to each of the maintainers of each dependent library. If they like the postcard, they send you a floppy, DVD or USB keychain with the code. Once the user has everything, they copy all the files to site-packages.
(In the NPM version, each maintainer sends a postcard & SASE to each of their dependencies and so on.)
My prediction: #astral #ruff will soon compete directly with codeclimate, sonarqube, codacy and the like. As far as I can tell, these products take a variety of free tools, repackage them and sell them to corporate customers with a hosted SaaS, sometimes with free tiers (zero marginal costs, so why not, it is a sales pipeline). They do so quietly and so who knows if they contribute anything back, if they violate the social norms of opensource or hire or compensate maintainers.
If I got a point, it is that this is nothing new.
If I had to come up with a way to fund opensource, I'd say the federal government should fund it, but heck if I know how grant would be made & managed. The government already has a mixed record in software purchasing. If, say, the gov't decided to fund jquery maintenance, would it happen in a way that would be better than how MS is maintaining it? Who knows.
♡ 0 ↻ 0