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

Fix typing issues with delete_head and Remote.add by rra · Pull Request #1346 · gitpython-developers/GitPython · GitHub

Repository navigation

Fix typing issues with delete_head and Remote.add - #1346

Merged
Yobmod merged 1 commit into
gitpython-developers:mainfrom
rra:type-fixes
Sep 24, 2021
Merged

Yobmod merged 1 commit into
gitpython-developers:mainfrom
rra:type-fixes

Conversation

rra commented Sep 20, 2021

Copy link
Copy Markdown
Contributor

delete_head and Head.delete historically accept either Head objects
or a str name of a head. Adjust the typing to match.

Using assignment to make add an alias for create unfortunately
confuses mypy, since it loses track of the fact that it's a
classmethod and starts treating it like a staticmethod. Replace
with a stub wrapper instead.

rra commented Sep 20, 2021

Copy link
Copy Markdown
Contributor Author

Ah, hm, I missed the impact on Remote.delete. Trying to think about the best way to handle that.

delete_head and Head.delete historically accept either Head objects
or a str name of a head.  Adjust the typing to match.  This
unfortunately requires suppressing type warnings in the signature of
RemoteReference.delete, since it inherits from Head but does not
accept str (since it needs access to the richer data of
RemoteReference).

Using assignment to make add an alias for create unfortunately
confuses mypy, since it loses track of the fact that it's a
classmethod and starts treating it like a staticmethod.  Replace
with a stub wrapper instead.

rra commented Sep 20, 2021

Copy link
Copy Markdown
Contributor Author

Amended with a possible fix. Alternately, perhaps the intent was not to allow strs for Head.delete and they only worked by accident (although in that case I wasn't sure how to create the necessary Head object to pass in).

rra commented Sep 20, 2021

Copy link
Copy Markdown
Contributor Author

FYI, for background, this fixes issues that I saw in https://github.com/lsst-sqre/neophile after updating GitPython, namely:

src/neophile/repository.py:58: error: Argument 1 to "delete_head" of "Repo" has incompatible type "str"; expected "Head"  [arg-type]
src/neophile/repository.py:76: error: Argument 1 to "delete_head" of "Repo" has incompatible type "str"; expected "Head"  [arg-type]
src/neophile/pr.py:312: error: Too few arguments  [call-arg]
src/neophile/pr.py:313: error: Argument 1 has incompatible type "Repo"; expected "Type[Remote]"  [arg-type]
src/neophile/pr.py:313: error: Argument 2 has incompatible type "str"; expected "Repo"  [arg-type]

The last three messages are from calling Remote.add with the code as it existed prior to this patch.

Byron requested a review from Yobmod September 21, 2021 00:27

Byron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks a lot for this contribution, it's much appreciated. Let's allow @Yobmod to also take a look in case I am missing something.

Byron added this to the v3.1.25 - Bugfixes milestone Sep 21, 2021
Yobmod merged commit 1746b97 into gitpython-developers:main Sep 24, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL