coherent-oss / python-kustomize

Kustomize for Kubernetes, but in Python
MIT License
1 stars 0 forks source link

Refine the codebase #6

Open bswck opened 5 months ago

jaraco commented 5 months ago

I've been doing this lately with ruff --select UP --fix. See also https://github.com/jaraco/skeleton/issues/112, where we're looking to apply this constraint across all projects.

diogobaeder commented 5 months ago

I'm all for automating the process, as long as we can have human reviews on the changes (e.g. PRs or review-before-push or so)

bswck commented 5 months ago

I don't see much to do here when it comes to Python 3.8 modernization precisely. I'll then go ahead and say I'll generically improve the code quality.

diogobaeder commented 5 months ago

An idea would be to make use of things that were introduced in Python 3.8 but weren't available in earlier versions, where it makes sense. For example, in 3.6 dataclasses was an external library, and since 3.8 (IIRC) they became part of the stdlib. So we could cut out any reference to dataclasses as a library.

Type hinting also improved, so we could make use of that too I guess. What do you think?

bswck commented 5 months ago

I'll start from type hints.

bswck commented 5 months ago

For example, in 3.6 dataclasses was an external library, and since 3.8 (IIRC) they became part of the stdlib. So we could cut out any reference to dataclasses as a library.

Yeah, dataclasses was added to stdlib in 3.7. But I can see it between other stdlib imports here: https://github.com/coherent-oss/python-kustomize/blob/a0c5b3c22a5cecd2704a47df87e0aeb00a094607/kustomize/generators.py#L6-L8

And I don't see a place where dataclasses is referred to as if it was a third-party package.

diogobaeder commented 5 months ago

Here's a few ideas to look for:

Other than this, I would be happy if we can make sure the package is mypy-strict. For some years I've been trying hard to keep type hints as strict as possible, because they're immensely helpful.

bswck commented 5 months ago

Thanks for assistance. I've been doing such refactors from time to time (https://github.com/CERT-Polska/malduck/pull/111, https://github.com/python-poetry/cleo/pull/365), I'm sure we'll get as much as we can out of it. :)

bswck commented 5 months ago

docs.python.org/3/whatsnew/3.7.html#whatsnew37-pep563 - import future annotations and use where classes reference themselves

I'm very happy you don't oppose to PEP 563. Opinions tend to be pretty controversial.