Descriptors: secret weapon of frameworks
27/11/2024 , Auditório Dorneles Treméa
Idioma: English

The descriptor protocol is an obscure feature widely used by frameworks to link Python classes to database tables, JSON payloads, and dynamic forms. Understand this secret weapon and wield it wisely!


Most Python frameworks that use Python class syntax to specify structures with typed fields implement descriptor classes, which provide 'get', 'set' and 'delete' method to enforce rules and perform conversions when the fields are read, updated, or deleted. Standard Python classes themselves depend of the descriptor protocol: that's what makes a function acessed via a class or object behave as a method.

Luciano Ramalho wrote Fluent Python / Python Fluente, an international bestseller published in 9 languages.

Esta palestrante também aparece em: