Gently
2023-08-25   dejbug.github.io

Gently

For
a dream
lies here
I'm rewriting known.py, the URI rewriter. It should be a bit slower by design but cleaner and a bit more powerful. I've started using type annotations. The first type-checker I'm trying is mypy and already I've run into one or two of its bugs gh gh. I'm getting:
archive.py:58: error: "object" has no attribute "time"  [attr-defined]
with:
...
    @property # type: ignore
    def time(self):
        return self.year * 100000 + self.month * 100 + self.day

...
key = cmp_to_key(lambda a, b: a.time - b.time)
return sorted(seq, key = key, reverse = reverse)
I've even added the test: ignore comment as Guido suggested gh which does nothing. It doesn't look like they are going to do anything about it soon gh. So I probably need to move to another checker or, given that Guido himself seems to endorse this tool twitter.com, I stop using @property altogether. Decisions. It's like having an ingrown toenail and thinking it'll take care of itself. A couple months of living like that and your entire gait will change; the way you navigate around potential obstacles, the way you move through your environment. My wishful-thinking had transformed the most inoccuous things into potential sources of pain that are best to be avoided. Mypy looks like that, given what grander vision it had started with slideshare.net. Wishful-thinking-wise it was powerful enough to even stop another, earlier effort in that same direction alorelang.org. Damn it. I just realized the problem with mypy. The ArchLinux package is outdated (1.3.0 < 1.5.1) and was flagged arch. Ok so the PKGBUILD didn't need any changing at all apart from the obvious version and checksum. The problem with gratuitous build-time deps gh is still being handled well by the maintainer's sed scripts. But when it runs through all its self-checks (which takes forever) mypy quits with 5 fails out of 1117.
=================================================== short test summary info ====================================================
FAILED mypy/test/meta/test_parse_data.py::ParseTestDataSuite::test_bad_eq_version_check - AssertionError: assert 'version==3.7 always false since minimum runtime version is (3, 8)' in ''
FAILED mypy/test/meta/test_parse_data.py::ParseTestDataSuite::test_bad_ge_version_check - AssertionError: assert 'version>=3.8 always true since minimum runtime version is (3, 8)' in ''
FAILED mypy/test/meta/test_parse_data.py::ParseTestDataSuite::test_parse_invalid_case - assert "Invalid testcase id 'foo-XFAIL'" in ''
FAILED mypy/test/meta/test_parse_data.py::ParseTestDataSuite::test_parse_invalid_section - assert ".test:3: Invalid section header [unknownsection] in case 'abc'" in ''
FAILED mypy/test/meta/test_update_data.py::UpdateDataSuite::test_update_data - assert '[case testCorrect]\ns: str = 42  # E: Incompatible types in assignment (expression has type "int", variable has typ...
=============================== 5 failed, 1117 passed, 1 skipped, 2 xfailed in 775.86s (0:12:55) ===============================
test_bad_eq_version_check is the culprit gh. According to the comments it is a meta test, a test that tests the testers. I don't really need this. So:
$ diff PKGBUILD-1.3.0 PKGBUILD
6c6
< pkgver=1.3.0
---
> pkgver=1.5.1
21c21
< sha256sums=('e1f4d16e296f5135624b34e8fb741eb0eadedca90862405b1f1fde2040b9bd11')
---
> sha256sums=('b031b9601f1060bf1281feab89697324726ba0c0bae9d7cd7ab4b690940f0b92')
36,39c36,39
< check() {
<     cd "$pkgname-$pkgver"
<     pytest -vv -c /dev/null
< }
---
> # check() {
>     # cd "$pkgname-$pkgver"
>     # pytest -vv -c /dev/null
> # }
$ makepkg -s
$ pacman -R mypy
$ pacman -U mypy-1.5.1-1-any.pkg.tar.zst
Now let's see about those, ahem, other error, yes?
def parseLine(line) -> list[tuple[str | None, str, str | None]]:
    ...
    return [m.groups() for m in mm]
Causes known.py:60: error: List comprehension has incompatible type ...
#version-1.3.0 List[Tuple[Union[str, Any], ...]]; expected List[Tuple[Optional[str], str, Optional[str]]]  [misc]
#version-1.5.1 List[tuple[str | Any, ...]]; expected List[tuple[str | None, str, str | None]]  [misc]

What it wants me to write is this:
    # return [tuple(m.groups()) for m in mm]                  # Not this.
    # return [(*m.groups(), ) for m in mm]                    # Not this.
    return [(m.group(1), m.group(2), m.group(3)) for m in mm] # This!
Or:
def parseLine(line) -> list[tuple[str | None, ...]]:
    ...
    return [m.groups() for m in mm]
And this is probably where I give type annotations up mypy:rtd. Cython I actually love cython. But this is just not necessary mypy:rtd. This is really for tooling, for people to have auto-completions. I don't do auto-completion anyway. One could argue that if you can't remember the API you're using everyday you should be worrying about more much than toolingyou are not your tooling!. pypi mypy:rtd gh gh wiki:arch wiki:arch wiki:arch docs.pytest.org gh peps:py docs:py typing:rtd typing:rtd adamj.eu realpython.com

Git

This is so useful: So
... Colors may also be given as numbers between 0 and 255 ... git
color.diff.<slot> ... is one of context (or plain), meta (metainformation), frag (hunk header), func (function in hunk header), old (removed lines), new (added lines), commit ... whitespace (highlighting whitespace errors), oldMoved (deleted lines), newMoved (added lines) ... git

Awesome Linksman

gh 🚀

Art

A Blender script to procedurally generate 3D spaceships gh A lossless video/GIF/image upscaler achieved with waifu2x, Anime4K, SRMD and RealSR. Started in Hack the Valley 2, 2018. gh A Grammar of Graphics for Python gh

Cracking

Reverse engineering framework in Python gh Exploit Development and Reverse Engineering with GDB Made Easy gh A swiss army knife for pentesting networks gh Fast and powerful SSL/TLS scanning library. gh Shadowsocks - Wikipedia wiki

Crowd

The LBRY SDK for building decentralized, censorship resistant, monetized, digital content apps. gh Golem is creating a global market for computing power. gh Bittorrent software for cats gh

Dev

Data validation using Python type hints gh A static type analyzer for Python code gh Never use print() to debug again. gh Project documentation with Markdown. gh Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right stack everywhere. gh

Education

Simple PyTorch Tutorials Zero to ALL! gh Tensorflow tutorial from basic to hard gh Minimal and clean examples of machine learning algorithms implementations gh PEFT: State-of-the-art Parameter-Efficient Fine-Tuning. gh Learning to See in the Dark. CVPR 2018 gh A free, online learning platform to make quality education accessible for all. gh A tour in the wonderland of math with python. gh A Python module for learning all major algorithms gh A collection of design patterns/idioms in Python] gh Python Koans - Learn Python through TDD gh

Games

A retro game engine for Python gh Free (as in freedom) open source clone of the Age of Empires II engine gh

GUI

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS gh A little Python library for making simple Electron-like HTML/JS GUI apps gh

Linux

Python-powered, cross-platform, Unix-gazing shell. gh A full-featured, hackable tiling window manager written and configured in Python (X11 & Wayland) gh Cross-platform, fast, feature-rich, GPU based terminal gh

Lisp

A dialect of Lisp that's embedded in Python gh A functional standard library for Python. gh Simple, elegant, Pythonic functional programming. gh

ML

Computer Vision and Robotics Library for AI gh The OpenAI Python library provides convenient access to the OpenAI API from applications written in the Python language. gh

Web

Brython (Browser Python) is an implementation of Python 3 running in the browser gh Selenium-python but lighter: Helium is the best Python library for web automation. gh A very fast and expressive template engine. gh It's React, but in Python (6.7k stars) gh Swagger/OpenAPI First framework for Python on top of Flask with automatic endpoint validation & OAuth2 support gh Create web-based user interfaces with Python. The nice way. gh Low code web framework for real world applications, in Python and Javascript gh Python framework for building microservices gh A next generation HTTP client for Python. gh An ASGI web server, for Python. gh The little ASGI framework that shines. gh Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. gh The Web API toolkit. gh Every web site provides APIs. gh A fully tested, abstract interface to creating OAuth clients and servers. gh REST API framework designed for human beings gh Typed (sigh) interaction with the GitHub API gh

Gait

🦋 Here's an animated picture of an Elephant just walking wiki.