Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints #70

Merged
merged 5 commits into from
Oct 19, 2021
Merged

Add type hints #70

merged 5 commits into from
Oct 19, 2021

Conversation

antonagestam
Copy link
Contributor

@antonagestam antonagestam commented Oct 14, 2021

  • Add type hints to bananas.__init__
  • Add type hints to the show_urls command
  • Add type hints to the syncpermissions command
  • Add type hints to bananas.models

Remaining untyped after this PR is bananas.admin and bananas.query.

I started working on bananas.query too, but that it'll take some amount of work to finish and gets very involved (probably impossible to achieve an acceptable level of typing without importing types from django-stubs, guarded by if TYPE_CHECKING.

@github-actions
Copy link

github-actions bot commented Oct 14, 2021

File Coverage Lines Branches Missing
All files 92% 96% 87%
bananas/__init__.py 79% 83% 75% 19-20
bananas/models.py 97% 100% 95%
bananas/url.py 96% 100% 93%
bananas/admin/extension.py 93% 100% 86%
bananas/admin/api/i18n.py 90% 80% 100% 9
bananas/admin/api/mixins.py 68% 74% 63% 70, 78-84, 94, 110, 117-128
bananas/admin/api/serializers.py 75% 100% 50%
bananas/admin/api/versioning.py 91% 100% 83%
bananas/admin/api/views.py 99% 98% 100% 134
bananas/admin/api/schemas/base.py 87% 75% 100% 3
bananas/admin/api/schemas/yasg.py 88% 95% 82% 77, 86, 125-126
bananas/drf/fencing.py 87% 94% 80% 91-97, 136
bananas/management/commands/syncpermissions.py 87% 95% 80% 32

Minimum allowed coverage is 85%

Generated by 🐒 cobertura-action against 699ff12

@@ -1,25 +1,23 @@
VERSION = (2, 0, 0, "final", 0)


def get_version(version=None):
def get_version() -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Felt unnecessary to implement types for version: Union[VersionTuple, str, None] here instead of just dropping the version argument and always use VERSION.

Comment on lines 15 to 19
class Missing:
...

class ModelDict(dict):

_nested = None
MISSING: Final = Missing()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's impossible to narrow the type of MISSING: Final = object(), hence introducing a type here.

Copy link
Contributor

@hannseman hannseman left a comment

Choose a reason for hiding this comment

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

Nice!

@antonagestam antonagestam merged commit 8e832ca into master Oct 19, 2021
@antonagestam antonagestam deleted the fix/type-hint-progress branch October 19, 2021 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants