From c885781858ade2f660818e983915a6dae5672241 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 23 Apr 2021 12:22:12 +0200 Subject: improvement: teach mypy that Object.type is not always supposed to be None --- git/objects/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/objects') diff --git a/git/objects/base.py b/git/objects/base.py index cccb5ec6..59f0e836 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -7,6 +7,7 @@ from git.util import LazyMixin, join_path_native, stream_copy, bin_to_hex import gitdb.typ as dbtyp import os.path as osp +from typing import Optional # noqa: F401 unused import from .util import get_object_type_by_name @@ -24,7 +25,7 @@ class Object(LazyMixin): TYPES = (dbtyp.str_blob_type, dbtyp.str_tree_type, dbtyp.str_commit_type, dbtyp.str_tag_type) __slots__ = ("repo", "binsha", "size") - type = None # to be set by subclass + type = None # type: Optional[str] # to be set by subclass def __init__(self, repo, binsha): """Initialize an object by identifying it by its binary sha. -- cgit v1.2.1 From 8470777b44bed4da87aad9474f88e7f0774252a6 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Fri, 23 Apr 2021 12:24:07 +0200 Subject: improvement: teach mypy how to deal with wildcard-imported objects By telling it where it's imported from in one case and telling it to ignore it in another. --- git/objects/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/objects') diff --git a/git/objects/__init__.py b/git/objects/__init__.py index 23b2416a..897eb98f 100644 --- a/git/objects/__init__.py +++ b/git/objects/__init__.py @@ -16,8 +16,8 @@ from .tag import * from .tree import * # Fix import dependency - add IndexObject to the util module, so that it can be # imported by the submodule.base -smutil.IndexObject = IndexObject -smutil.Object = Object +smutil.IndexObject = IndexObject # type: ignore[attr-defined] +smutil.Object = Object # type: ignore[attr-defined] del(smutil) # must come after submodule was made available -- cgit v1.2.1