惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
T
The Exploit Database - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
月光博客
月光博客
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
NISL@THU
NISL@THU
爱范儿
爱范儿
S
Securelist
博客园 - 叶小钗
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
G
GRAHAM CLULEY
P
Proofpoint News Feed
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
博客园 - 【当耐特】
H
Help Net Security
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss

Stonecharioteer on Tech

I Traced My Traffic Through a Home Tailscale Exit Node What Was I Reading Last? In Three Not-So-Easy Pieces Dogfooding Is Hard Code blocks in your books, finally GoForGo v0.9.0 Merrilin - We built an app to read books I use a Macbook now Data Structures & Algorithms - Preparing for Interviews Using a local DNS namespace for local service discovery Direction KOllector - Publishing KOReader Highlights gbt: branches touched in the last 24 hours A Soiree into Symbols in Ruby Some Smalltalk about Ruby Loops Ruby Blocks Returning from Ruby Blocks, Procs and Lambdas My Linux Laptop Finally Works: How Claude Helped Me Fix Years of Annoyances TIL: Watchexec - Modern File Watching for Development Workflows A Less Busy Mind GoForGo - Learn Go through live examples Migrating My Old Blog to Hugo with Claude The Qtile Window Manager: A Python-Powered Tiling Experience Read the RFCs that Built the Internet Py-x-Protobuf - Or How I Learned to Stop Worrying and Love Protocol Buffers Python Reverse a List New Beginnings Leaving ChainSafe Systems Screen Lock for Cinnamon Desktop using Zenity and Terminal Commands Crews Not Teams A System for Getting Better at LeetCode So Far So Rust Retrying HTTP Requests with Rust A Primer on Control Charts Learning Rust Explicit is Better than Implicit: Rust for Pythonistas Using Custom Delimiters in Jinja Templates TIL: Creating Fixed Length Iterables in Python Documentation Without Assumption Vagrant Python - A Reflection in 2022 Learning Golang No, A Virtual Machine Is Not Enough: Why Developers Need Native Linux Empathy in Tech For Those Who Came in Late A Weekend With PostgreSQL TIL: Gooey and Python Fire for Quick GUIs and CLIs TIL: 2ality - Dr. Axel Rauschmayer's JavaScript Blog TIL: MassDNS - High-Performance Bulk DNS Lookups TIL: Matomo Analytics, Google Tech Writing, Memory Programming, and NES TV Signals TIL: MontyDB - MongoDB Implemented in Python Returning to the Craft of Programming TIL: CPUFetch, OneFetch, and Learn CSS TIL: DNS Performance Testing and Pi-hole with Unbound TIL: Eli Bendersky's Blog, Awesome By Example, NoCoDB, and Martin Kleppmann TIL: CRDTs, Extreme HTTP Performance, and BYTEPATH Game TIL: AutoInvent, ASGI, Python Packaging, RAPIDS GPU Computing, and FlaskCon TIL: MangaDesk - Terminal Client for MangaDex TIL: McFly - Smart Shell History Search TIL: Siege Load Testing and Awesome FastAPI Resources TIL: Ventoy Bootable USB and Justniffer Network Analysis TIL: CLI Code Review, Git Split Diffs, and Internal Combustion Engine TIL: Benford's Law, Web Security Headers, Event Sourcing, and Mozilla Security Guidelines How to Write Documentation - The README.md File The Importance of Documentation TIL: NNgroup UX Research, SponsorBlock, and Labella Python Library TIL: The Little Book of Rust Macros and Rust Performance Book TIL: Git-Bug Distributed Issue Tracker and Omni Kubernetes Monitoring TIL: Zellij - Modern Terminal Multiplexer TIL: How Discord Handles 2.5 Million Concurrent Voice Users TIL: Volumio - The Audiophile Music Player TIL: Areopagitica - Milton's Defense of Free Speech TIL: Fast Node Manager, Zoxide Smart CD, Technical Writing, PyO3, and Qubes OS TIL: Slurm Workload Manager for HPC Clusters TIL: Data Visualization Guide and Oso Authorization Academy TIL: CORS Deep Dive, Piku Tiny PaaS, Rust Strings, and Deno Standard Library TIL: Raspberry Pi OS Development, Vim Beginner Guide, Password Management, and QueryBook TIL: uBlock Origin Performance Optimization on Firefox TIL: Breaking PostgreSQL at Scale and LeetCode Problem Patterns TIL: Awesome Tmux Resources for Terminal Multiplexing TIL: Grit - A Multitree-Based Personal Task Manager TIL: Lens 4.2 Kubernetes IDE, Shell Scripting Guide, and Dark HTTP Server Do The Job You Hate So You Won't Hate The Job You Love TIL: Innernet VPN Solution and NoteCalc Calculator App TIL: Argo CD for GitOps and Lens Kubernetes IDE TIL: Modern Rust CLI Tools - System Monitoring, HTTP Requests, and DNS TIL: tz - A Time Zone Helper Tool TIL: Distributed Systems Education, Fallacies, and Self-Hosted Internet Archiving TIL: Real-Time Voice Cloning Technology TIL: ChartMuseum for Helm, AMD's Corporate Journey, and Kubernetes Pod Scaling TIL: Docker and Kubernetes Tools - Whaler, Descheduler, and Dive TIL: Post-Mortem Collection, Terminal Plotting, and Technical Twitter TIL: Dark Mode Toggle Web Component by Google Chrome Labs TIL: Python eval(), exec(), and compile() Functions TIL: Camelot PDF Tables, PostgreSQL Row Level Security, Zerodha Varsity, and Write Yourself a Git TIL: fuser Command for Process and File Investigation TIL: i Hate Regex - The Ultimate Regex Cheat Sheet TIL: Dolt - Git for Data and Database Version Control TIL: x86 Assembly Programming and SafeEyes Break Reminder TIL: Comprehensive Distributed Systems Reading List TIL: Cosmopolitan C Library, Distributed Systems Book, High Performance Browser Networking, and Rust Roguelike Tutorial
TIL: Python Code Quality and Development Tools Deep Dive
Python Code Quality Authority (PyCQA)# · 2020-07-18 · via Stonecharioteer on Tech

Diving deep into my learning archive, I discovered a treasure trove of Python development tools and resources that every serious Python developer should know about. These discoveries span from code quality enforcement to CPython internals understanding.

The Python Code Quality Authority is an organization that maintains several essential Python code quality tools:

PyCQA Tools Ecosystem

  • pylint - Comprehensive static analysis
  • flake8 - Style guide enforcement
  • mccabe - Cyclomatic complexity analysis
  • prospector - Meta-tool combining multiple analyzers
  • bandit - Security-focused static analysis

McCabe Complexity Analysis

Cyclomatic Complexity, also known as McCabe Complexity, measures the number of linearly independent paths through a program’s source code. The mccabe module helps identify overly complex functions:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Example of measuring complexity
from mccabe import get_code_complexity

def complex_function(x):
    if x > 10:
        if x > 20:
            if x > 30:
                return "very high"
            return "high"
        return "medium"
    return "low"

# This function would have high cyclomatic complexity

Complexity Guidelines

  • 1-10: Simple, low risk
  • 11-20: Moderate complexity
  • 21-50: High complexity, consider refactoring
  • >50: Very high risk, definitely refactor

Advanced Code Quality with Prospector

Prospector is a meta-tool that runs multiple Python code analysis tools and presents the results in a unified format:

1
2
3
# Install and run prospector
pip install prospector
prospector myproject/

It combines:

  • pylint for comprehensive analysis
  • pep8/pycodestyle for style checking
  • pep257/pydocstyle for docstring conventions
  • pyflakes for logical errors
  • mccabe for complexity analysis

CPython Internals Resources

Understanding Python’s internals makes you a better Python developer. Here are the essential resources I discovered:

Core Learning Materials

  1. CPython Internals Book by Anthony Shaw - Comprehensive guide to Python’s implementation
  2. CPython Source Code Guide - RealPython’s detailed walkthrough
  3. Advanced Internals of CPython by Prashanth Raghu - Deep technical PDF resource

Video Resources

Must-Watch CPython Content

Modern Python Development Practices

Import Sorting with isort

isort automatically sorts Python imports according to PEP 8 guidelines:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Before isort
import sys
from myproject import settings
import os
from django.conf import settings as django_settings

# After isort
import os
import sys

from django.conf import settings as django_settings

from myproject import settings

Configuration in pyproject.toml:

1
2
3
4
[tool.isort]
profile = "black"
multi_line_output = 3
line_length = 88

Profiling with Line Profiler

line_profiler provides line-by-line timing information:

1
2
3
4
5
6
7
8
@profile
def slow_function():
    # Your code here
    time.sleep(0.1)
    result = sum(range(1000000))
    return result

# Run with: kernprof -l -v script.py

Memory Profiling with Guppy/Heapy

Guppy3/Heapy helps identify memory leaks and understand memory usage:

1
2
3
4
5
from guppy import hpy
h = hpy()
print(h.heap())

# Shows detailed memory usage by object type

File Watching and Automation

The entr Command

entr runs commands when files change - perfect for development workflows:

1
2
3
4
5
6
7
8
# Run tests when Python files change
find . -name "*.py" | entr python -m pytest

# Restart server on code changes
find . -name "*.py" | entr -r python app.py

# Run linting on save
find . -name "*.py" | entr pylint

Development Workflow

entr is incredibly useful for continuous testing, linting, or building during development. It’s more reliable than many IDE file watchers and works across all platforms.

Advanced Python Features and PEPs

PEP 618: Optional Length-Checking to zip

PEP 618 introduced strict parameter to zip():

1
2
3
4
5
6
7
# Before PEP 618 - silent truncation
list1 = [1, 2, 3]
list2 = [4, 5]
result = list(zip(list1, list2))  # [(1, 4), (2, 5)]

# After PEP 618 - explicit error
result = list(zip(list1, list2, strict=True))  # ValueError!

PEP 622: Structural Pattern Matching

PEP 622 brought pattern matching to Python 3.10+:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def handle_data(data):
    match data:
        case {"type": "user", "name": str(name)}:
            return f"User: {name}"
        case {"type": "product", "id": int(product_id)}:
            return f"Product ID: {product_id}"
        case list() if len(data) > 10:
            return "Large list"
        case _:
            return "Unknown data"

Try it in the Pattern Matching Playground.

Flask Extensions for Code Quality

1
2
# Flask-specific linting
pip install pylint-flask pylint-flask-sqlalchemy

These plugins understand Flask patterns and reduce false positives:

1
2
3
4
5
6
7
8
# Without pylint-flask: "Instance of 'Flask' has no 'route' member"
# With pylint-flask: Correctly understands Flask patterns
from flask import Flask
app = Flask(__name__)

@app.route('/')  # No longer flagged as error
def home():
    return "Hello World"

Profiling Flask Applications

Use Werkzeug’s profiler middleware for detailed performance analysis:

1
2
3
4
5
6
from werkzeug.contrib.profiler import ProfilerMiddleware
from flask import Flask

app = Flask(__name__)
app.wsgi_app = ProfilerMiddleware(app.wsgi_app,
                                 restrictions=[30])  # Top 30 calls

Python Packaging Evolution

Modern Python Packaging

The landscape is evolving rapidly:

  • Poetry - Modern dependency management
  • Flit - Simple publishing workflow
  • pyproject.toml - New standard for project metadata

PEP 508: Dependency Specification

PEP 508 defines the format for dependency specifications:

1
2
3
4
5
6
7
8
9
# Basic dependency
requests >= 2.25.0

# Environment markers
dataclasses; python_version < "3.7"
pywin32; sys_platform == "win32"

# Complex conditions
scipy >= 1.0.0; (python_version >= "3.7" and platform_machine != "aarch64")

Quality of Life Improvements

Useful Development Tools

Key Takeaways

  1. Code Quality is Multi-Dimensional: Use multiple tools (pylint, flake8, prospector) for comprehensive analysis
  2. Understanding Internals Matters: CPython knowledge helps write better, more efficient code
  3. Automation is Essential: Tools like entr and proper CI/CD make development smoother
  4. Modern Python is Evolving: Stay updated with new PEPs and packaging standards
  5. Profiling Before Optimizing: Use proper tools to identify actual bottlenecks

Development Philosophy

The best developers don’t just write code that works - they write code that’s maintainable, efficient, and follows established patterns. These tools help achieve that goal systematically.

This exploration of Python development tools reinforces that professional Python development requires a comprehensive toolkit beyond just knowing the language syntax.


These discoveries came from my learning archive spanning 2020, showing how Python tooling and best practices continue to evolve while maintaining backward compatibility and developer productivity.