66import sys
77import textwrap
88from abc import ABCMeta
9+ from collections .abc import Mapping
910from copy import copy
1011from dataclasses import dataclass , field
1112from typing import TYPE_CHECKING , Any
@@ -116,12 +117,7 @@ def __new__(
116117 * args : Any ,
117118 ** kwargs : Any ,
118119 ) -> SchemaMeta :
119- result = Metadata ()
120- for base in bases :
121- result .update (mcs ._get_metadata_recursively (base ))
122- namespace_metadata = mcs ._get_metadata (namespace )
123- mcs ._remove_overridden_columns (result , namespace , bases )
124- result .update (namespace_metadata )
120+ result = mcs ._collect_metadata (bases , namespace )
125121 namespace [_COLUMN_ATTR ] = result .columns
126122 cls = super ().__new__ (mcs , name , bases , namespace , * args , ** kwargs )
127123
@@ -212,7 +208,7 @@ def __getattribute__(cls, name: str) -> Any:
212208 @staticmethod
213209 def _remove_overridden_columns (
214210 result : Metadata ,
215- namespace : dict [str , Any ],
211+ namespace : Mapping [str , Any ],
216212 bases : tuple [type [object ], ...],
217213 ) -> None :
218214 """Remove inherited columns that the child namespace explicitly overrides.
@@ -238,15 +234,23 @@ def _remove_overridden_columns(
238234 result .columns .pop (parent_key , None )
239235
240236 @staticmethod
241- def _get_metadata_recursively (kls : type [object ]) -> Metadata :
237+ def _collect_metadata (
238+ bases : tuple [type [object ], ...],
239+ namespace : Mapping [str , Any ],
240+ ) -> Metadata :
242241 result = Metadata ()
243- for base in kls . __bases__ :
242+ for base in bases :
244243 result .update (SchemaMeta ._get_metadata_recursively (base ))
245- result .update (SchemaMeta ._get_metadata (kls .__dict__ )) # type: ignore
244+ SchemaMeta ._remove_overridden_columns (result , namespace , bases )
245+ result .update (SchemaMeta ._get_metadata (namespace ))
246246 return result
247247
248248 @staticmethod
249- def _get_metadata (source : dict [str , Any ]) -> Metadata :
249+ def _get_metadata_recursively (kls : type [object ]) -> Metadata :
250+ return SchemaMeta ._collect_metadata (kls .__bases__ , kls .__dict__ )
251+
252+ @staticmethod
253+ def _get_metadata (source : Mapping [str , Any ]) -> Metadata :
250254 result = Metadata ()
251255 for attr , value in {
252256 k : v for k , v in source .items () if not k .startswith ("__" )
0 commit comments