Skip to main content

PyEnd

Python's significant indentation is a horrible thing that ruins the language for many people.

It's now fixed.

PyEnd introduces end to mark the end of blocks:

from pyend import end

if "tabs" > "spaces":
	print("∎")
end

Why is that useful?

Because it is also a formatter. You can convert indentation-based code (both the file you are working on and the clipboard) into keyword-delimited code. You can then paste away and afterwards reformat your file automatically instead of manually. It should also be quite helpful for refactoring, when the code structure changes and everything has to be re-indented.

Status

This project is still an experiment. Feel free to play around with it and give feedback but don't use it in production code. You may have noticed there are no unit tests yet. Formatting code (especially with significant indentation) is actually not so straight forward and can easily mess things up. That being said, the formatter does some validation in the end. The formatted code is tokenized again and compared to the tokenized original input.

Installation

pip install pyend

Hasn't this whole thing been done before?

In contrast to pindent, it works with Python3 and in contrast to pybrace and pybraces, the output is still valid Python.

Does it stop there?

It sure does not! It also uses tabs instead of spaces for indentation. Because using tabs instead of spaces is much better. However, if you want to be wrong, you can set the --convert-tabs-to-spaces-despite-tabs-being-objectively-better-than-spaces flag, which will convert indentation tabs into 11 spaces. Should you not like 11 spaces for indentation and you would rather enforce your personal taste onto everyone else, you can set the --use-this-many-spaces-per-tab-cuz-as-a-spacist-i-want-uniformity-but-i-dont-want-the-default parameter to whatever your heart desires.

Why are tabs better than spaces?

At the core of the spacecrafters' arguments lies the conviction that their pristine code must look the same everywhere. This idea is just doomed to failure. While a typical space users' code probably looks something like this on their 79 column console or on their printed handouts:

space user code

the exact same code will render like this on my monitor:

my code

so why even bother with indentation width consistency?

Furthermore, Developers Who Use Spaces Make More Money Than Those Who Use Tabs. This is because space invaders need higher monetary compensation to make up for the fact that developers who use tabs are happier in general because they make better life choices.

That should settle it.

Does PyEnd fix all the bad decisions in Python's language design?

Unfortunately not. Empty blocks will still need a pass:

if None:
	pass
end

Furthermore, myList[0:5] still absolutely counter-intuitively only goes up to myList[4] and there is also this atrocity. But hey, it's a start!

What about line breaks?

Line breaks are a Pandora's box that this project is not touching. You have to sprinkle the line breaks in manually (you're much better at this than any tool anyway), or you use another formatter on top of PyEnd.

But in my project I have a variable named end. Am I forced to live under van Rossum's dictatorship then?

PyEnd only recognizes an end on an otherwise empty line (except for comments) as block end mark. Using end otherwise is a bit ugly as every block-ending end then becomes a reference to your variable but it is possible.

This is a great project! You are very clever and handsome! Can you also do this for YAML?

Thanks but no. YAML is screwed up beyond repair, starting with its very funny name and not ending with its ambiguity. Use JSON. It has its problems as well but I feel they aren't really relevant in practice and I also just like it more 😌

Disclosure

If I didn't consider Python to be a great language, I wouldn't invest so much time in this project. But significant indentation has been an absolute PITA and the urge to do something about it has been bugging me with every paste. I finally gave in.

Metadata

Release files for pyend 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyend 0.0.2
File Size Uploaded
pyend-0.0.2.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyend 0.0.2
File Interpreter ABI Platform
pyend-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / pyend-0.0.2.tar.gz

Download URL pyend-0.0.2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d8863f12a784d1b8fd79d8b050d4029bab15dc80d08059a68037a56e268fa3bd
BLAKE2b-256 checksum
How to use checksums
2f21c22fe4f01d730e669bb38457bebdd190b75bc425751783a3694f81c12bfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / pyend-0.0.2-py3-none-any.whl

Download URL pyend-0.0.2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ba7f05b4376278700880f7daf7753d04235310f000164a8318df01f9a9f5315
BLAKE2b-256 checksum
How to use checksums
29d2a62ba191377e5636ecfe097828b651f023cf4a8c9ec3e2a98160e639b2e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

0.0.3

2 release files

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page