Python Browser Tech, Decorator Shortcuts, and Code Modernization

·32m 58s
Shared point

Web Development in Python

PyScript Updates

  • PyScript is undergoing significant changes with new semantic versioning and structural updates.
  • The py-env section is officially deprecated in favor of pyconfig.
  • New features include event handling directly in Python (e.g., py-click), better HTML escaping, and the ability to manage multiple execution runtimes.
  • The project is improving its infrastructure, including better integration with Playwright for testing and refined support for async workflows.

Interactive Dashboards with Panel

  • Panel (from the HoloViz ecosystem) now offers comprehensive support for WebAssembly via Pyodide and PyScript integration.
  • This allows users to run complex, interactive data dashboards entirely client-side without needing a dedicated backend server.
  • New CLI commands like panel convert enable seamless generation of JavaScript workers and Progressive Web Apps (PWA), offering an offline-capable, native-like experience.

Testing and Modernizing Python Code

Decorator Shortcuts

  • A clever technique involves assigning long, complex decorator chains (such as conditional PyTest skips or x-fails) to a simple variable.
  • "You would never write the same code 10 times in a real part of your app. Why should you write it 10 times duplicate in a test?"

  • This promotes DRY (Don't Repeat Yourself) principles and improves maintainability across large test suites.

Automating Code Upgrades

  • Auto-Walrus: A tool that automatically scans your codebase and refactors standard assignments into the walrus operator (:=), which is ideal for Python 3.8+ codebases.
  • PyUpgrade: A powerful tool for modernizing legacy code by updating syntax to match newer Python features, such as set literals, type union operators, and cleaner LRU cache implementations.
  • Maintaining modern code styles ensures better performance and clarity.

Topics

Chapters

5 chapters
Python Bytes
AI chat — answers grounded in episodes