Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add initial types to repo/fun.py#1192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 1 commit intogitpython-developers:masterfromYobmod:main
Mar 12, 2021
Merged

Add initial types to repo/fun.py#1192

Byron merged 1 commit intogitpython-developers:masterfromYobmod:main
Mar 12, 2021

Conversation

Yobmod
Copy link
Contributor

@YobmodYobmod commentedMar 4, 2021
edited
Loading

Hi,
This adds types to base.py and fun.py.

  • All annotations are consistant according to both mypy and pyright (but will need refining once whole lib is typed).

  • I've used an alias (TBD, 'to be determined') for Any to show places where I was unsure of the type, but i'm sure it should be more specific than Any.

  • i've avoided changing any runtime code as much as possible, except:

    • i've used Union[str, os._pathlike] to annotate path arguments. Where this showed errors due to use of string-only methods, i've then wrapped the arg in str() within the function. Thisshould mean they are all compatible with pathlib.Paths and pathlib.Purepaths, but that will require tests writing before its official.

    • Adding typeguards: e.g. where git_dir is initialised as None, then assigned later to a string, mypy showed places that needed to be checked that it was actually a string and not still None. This could probably be improved by initializing as "" instead but it touched too much code.

    • changed Except (OSError, IOError) to just Except OSError, as typechecking says it was redundant for python 3.

    • Separate tuple unpacking to seperate lines to provide specific types (unpacked tuples cant be typed yet)

Byron reacted with heart emoji
@Yobmod
Copy link
ContributorAuthor

Yobmod commentedMar 4, 2021
edited
Loading

Finally fixed all automated issues!

All functions in base.py and fun.py now typed and passes mypy and pyright (and flake8)

@ByronByron added this to thev3.1.15 - Bugfixes milestoneMar 5, 2021
Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks a lot for this tremendous work!

Admittedly I only got to fly through about 2/3 of all changes and think there is a high likelihood of me having missed something.
I will see to finish the rest tomorrow but would hope that another maintainer could also have a look.


# Subclass configuration
# Subclasses may easily bring in their own custom types by placing a constructor or type here
GitCommandWrapperType = Git

def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=False, expand_vars=True):
def __init__(self, path: Optional[PathLike] = None, odbt: Type[GitCmdObjectDB] = GitCmdObjectDB,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There is an actual base class for object databases which is more general.
There are two implementations for it.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LooseObjectDB?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it's best to 'make up' a type and call itObjectDB, asLooseObjectDB is too specific and kind of wrong here, too. Honestly I don't really know what I was thinking and this clearly is an example of OOPbeing gone wrong.

Otherwise you could dig into GitDB and see how this DB is composed of various types which provide a bundle of methods which may or may not be that useful in practice.

I do recommend to not get into types of GitDB and instead make them up (inside of GitPython) based on what's common usage in GitPython instead.

"""Create a new head within the repository.
For more documentation, please see the Head.create method.

:return: newly created Head Reference"""
return Head.create(self, path, commit, force, logmsg)

def delete_head(self, *heads, **kwargs):
def delete_head(self, *heads: HEAD, **kwargs: Any) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I thinkHEAD is too specific - any symbolic reference can be created that way.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

amended in#1202

@@ -429,11 +468,16 @@ def _get_config_path(self, config_level):
elif config_level == "global":
return osp.normpath(osp.expanduser("~/.gitconfig"))
elif config_level == "repository":
return osp.normpath(osp.join(self._common_dir or self.git_dir, "config"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It's probably nicer to do it like this:

ifnot (self._common_dirorself.git_dir):raisereturnosp.normpath(osp.join(self._common_dirorself.git_dir,"config"))

That way there is no duplicate path transformation.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

amended in#1202

@Byron
Copy link
Member

As this PR touches a lot of files I am merging it nonetheless even without the requested changes. These can be contributed separately and in the meantime what's there should already be a considerable improvement.

Thanks again, and I am looking forward to your future contributions :).

Yobmod reacted with thumbs up emoji

@ByronByron merged commit63c31b6 intogitpython-developers:masterMar 12, 2021
@Yobmod
Copy link
ContributorAuthor

Sorry for slow reply, I was sent to work somewhere with no internet (shocking common in the UK!)

I'll make the suggested changes on next PR.
As types are added to more files, I'll have to review all the previous ones each time anyway, to check for new typing incompatibilities that arise.

Byron reacted with thumbs up emojiByron reacted with heart emoji

@YobmodYobmod mentioned this pull requestMar 16, 2021
@muggenhormuggenhor mentioned this pull requestApr 21, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron requested changes

Assignees
No one assigned
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
@Yobmod@Byron

[8]ページ先頭

©2009-2025 Movatter.jp