Refactor ColumnType: register classes, return instances with config

- register_column_types() now returns classes instead of instances
- ColumnType.__init__ takes optional config=, baking it into the instance
- get_column_type() returns a ColumnType instance (or None) instead of a
  (name, config) tuple
- get_column_types() returns {col: ColumnType instance} instead of tuples
- Remove get_column_type_class() - no longer needed
- render_cell/validate/transform_value methods no longer take config arg;
  use self.config instead
- render_cell hook takes column_type (ColumnType or None) instead of
  column_type + column_type_config

https://claude.ai/code/session_01SvPEPqHgURTWESRp28pTC3
This commit is contained in:
Claude 2026-03-17 05:18:14 +00:00
commit dd9b83301c
No known key found for this signature in database
11 changed files with 227 additions and 243 deletions

View file

@ -1955,7 +1955,7 @@ async def test_hook_register_column_types():
ds = Datasette()
await ds.invoke_startup()
# Built-in column types should be registered
assert ds.get_column_type_class("url") is not None
assert ds.get_column_type_class("email") is not None
assert ds.get_column_type_class("json") is not None
assert ds.get_column_type_class("nonexistent") is None
assert "url" in ds._column_types
assert "email" in ds._column_types
assert "json" in ds._column_types
assert "nonexistent" not in ds._column_types