FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Give all ModelMetaclass classes a `meta` attribute. · 7dracoder/python-spanner-orm@c9897d0 · GitHub

Commit c9897d0

Browse files
committed
Give all ModelMetaclass classes a meta attribute.
This fixes bugs where pytype got the type for `meta` wrong because it only existed on some classes. I'm not 100% sure adding a default (empty) metadata to classes that didn't previously have it makes sense, but tests pass and it seems likely to be safe to me. This change also has the side effect of parsing Model-specific attributes from the Model class itself (as opposed to just subclasses of Model), but it doesn't look like Model has any attributes that would be affected. Addresses google#93. Tested: Ran tests and pytype.
1 parent 60b334e commit c9897d0

2 files changed

Lines changed: 1 addition & 5 deletions

File tree

‎spanner_orm/model.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@
3535

3636
class ModelMetaclass(type):
3737
"""Populates ModelMetadata based on class attributes."""
38+
meta: metadata.ModelMetadata
3839

3940
def __new__(mcs, name: str, bases: Any, attrs: Dict[str, Any], **kwargs: Any):
4041
parents = [base for base in bases if isinstance(base, ModelMetaclass)]
41-
if not parents:
42-
return super().__new__(mcs, name, bases, attrs, **kwargs)
4342

4443
model_metadata = metadata.ModelMetadata()
4544
for parent in parents:

‎spanner_orm/tests/metadata_test.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# TODO(#93): Remove pytype disable below.
17-
# type: ignore
18-
1916
import logging
2017
import unittest
2118

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL