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

fix(type): make some decorator utility functions type-safe and add some type annotations #1785

Merged
merged 1 commit into from
Jul 28, 2021

Conversation

yetone
Copy link
Member

@yetone yetone commented Jul 28, 2021

Description

Some internal decorator utility functions are not type-safe now, for example:

before:

image

after:

image

image

I fixed the error above in this PR, but some decorators like cached_contextmanager and catch_exceptions are still not type-safe, this problem that relies on this issue: python/mypy#8645

Motivation and Context

How Has This Been Tested?

Checklist:

  • My code follows the bentoml code style, both ./dev/format.sh and
    ./dev/lint.sh script have passed
    (instructions).
  • My change reduces project test coverage and requires unit tests to be added
  • I have added unit tests covering my code change
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@pep8speaks
Copy link

Hello @yetone! Thanks for opening this PR.

Line 89:89: E501 line too long (142 > 88 characters)
Line 99:5: E704 multiple statements on one line (def)
Line 99:89: E501 line too long (90 > 88 characters)
Line 102:5: E704 multiple statements on one line (def)
Line 104:89: E501 line too long (139 > 88 characters)
Line 135:89: E501 line too long (103 > 88 characters)
Line 144:89: E501 line too long (102 > 88 characters)
Line 224:89: E501 line too long (134 > 88 characters)

Do see the Hitchhiker's guide to code style

@yetone yetone requested a review from aarnphm July 28, 2021 05:31
from urllib.parse import urlparse, uses_netloc, uses_params, uses_relative

from google.protobuf.message import Message
from mypy.typeshed.stdlib.contextlib import _GeneratorContextManager
Copy link
Contributor

Choose a reason for hiding this comment

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

This means adding mypy into our library dependency. I would rather to reserve all typeshed import under TYPE_CHECKING

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I forgot to add the relevant dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

no worries since its only a type call i just added to the files. I think we shouldn't add mypy to library dependency anw

Copy link
Member Author

Choose a reason for hiding this comment

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

Because mypy uses typeshed types to annotate the standard libraries types during static analysis, so that mypy can only recognize the types in typeshed.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I don't know if its a good practice to include mypy into library dependency. I don't see a lot of other library doing so.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how to do it, I'll research how other libraries are doing it.

Copy link
Contributor

@aarnphm aarnphm left a comment

Choose a reason for hiding this comment

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

LGTM

@aarnphm
Copy link
Contributor

aarnphm commented Jul 28, 2021

I will fix the CI related in a separate PR

@aarnphm aarnphm merged commit 4fbf65b into bentoml:bentoml-1.0 Jul 28, 2021
@aarnphm
Copy link
Contributor

aarnphm commented Aug 16, 2021

We should revisit sometimes once we decide whether to go to 3.10 or 3.9 as default

aarnphm pushed a commit to aarnphm/BentoML that referenced this pull request Jul 29, 2022
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.

3 participants