Skip to content

submodules.get() throws a ValueError exception rather than returning None as documented. #1405

@nrybowski

Description

@nrybowski

Documentation for the get() method for SubmoduleCollection indicates that the function returns None if the submodule is not found.
However, the following sample script throws <class 'ValueError'> submodule 'second' has not been added yet.

import tempfile

from pygit2 import init_repository

# This should print "Success"
with tempfile.TemporaryDirectory() as prefix:
    first_prefix = f'{prefix}/first'
    second_prefix = f'{first_prefix}/second'
    first = init_repository(first_prefix)
    second = init_repository(second_prefix)
    try:
        assert first.submodules.get('second') is None
        print('Success')
    except Exception as e:
        print(type(e), e)

By looking at the get() function code, it catches KeyError but not ValueError. Is that an expected but undocumented behavior? Or should the function also catch ValueErrors?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions