Skip to content

repo.index.commit fails on python 3.10.0-rc2 (but not 3.10.0-rc1) #1341

Closed
@muggenhor

Description

@muggenhor

This is an excerpt of Hopic's pytest run in the python:3.10.0rc2-slim docker image. With python:3.10.0rc1-slim this same error does not occur.

I don't have the time right now to fully analyze this. But it looks suspiciously similar to a problem that I observed in Hopic itself and fixed with tomtom-international/hopic@a0f5a93. That one was triggered by this Python change: https://bugs.python.org/issue44806 / python/cpython@2cc19a5.

This if failing in a different location in the same function. But given the CPython commit message it seems to me that it's somehow achieving the opposite of its intent: it looks like non-protocol classes do call the __init__ method (via super) of the protocol class they inherit from.

>           repo.index.commit(message='Initial commit', **_commitargs)                                                                                             [2921/9962]
                                                                                                                                                                              
hopic/test/test_version_bump.py:173:                                                                                                                                          
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/py310/lib/python3.10/site-packages/git/index/base.py:1002: in commit                                                                                                     
    rval = Commit.create_from_tree(self.repo, tree, message, parent_commits,                                                                                                  
.tox/py310/lib/python3.10/site-packages/git/objects/commit.py:459: in create_from_tree                                                                                        
    new_commit = cls(repo, cls.NULL_BIN_SHA, tree,                                                                                                                            
.tox/py310/lib/python3.10/site-packages/git/objects/commit.py:130: in __init__                                                                                                
    super(Commit, self).__init__(repo, binsha)                                                                                                                                
.tox/py310/lib/python3.10/site-packages/git/objects/base.py:57: in __init__                                                                                                       super(Object, self).__init__()                                                                                                                                            
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <[AttributeError("'Commit' object has no attribute 'binsha'") raised in repr()] Commit object at 0x7f669cbdc8b0>, args = (), kwargs = {}
cls = <class 'git.objects.commit.Commit'>, base = <class 'git.objects.commit.Commit'>, init = <function Commit.__init__ at 0x7f669d820af0>

    def _no_init_or_replace_init(self, *args, **kwargs):
        cls = type(self)
     
        if cls._is_protocol:
            raise TypeError('Protocols cannot be instantiated')
     
        # Initially, `__init__` of a protocol subclass is set to `_no_init_or_replace_init`.
        # The first instantiation of the subclass will call `_no_init_or_replace_init` which
        # searches for a proper new `__init__` in the MRO. The new `__init__`
        # replaces the subclass' old `__init__` (ie `_no_init_or_replace_init`). Subsequent
        # instantiation of the protocol subclass will thus use the new
        # `__init__` and no longer call `_no_init_or_replace_init`.
        for base in cls.__mro__:
            init = base.__dict__.get('__init__', _no_init_or_replace_init)
            if init is not _no_init_or_replace_init:
                cls.__init__ = init
                break
        else:
            # should not happen
            cls.__init__ = object.__init__
     
>       cls.__init__(self, *args, **kwargs) 
E       TypeError: Commit.__init__() missing 2 required positional arguments: 'repo' and 'binsha'

/usr/local/lib/python3.10/typing.py:1422: TypeError

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions