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

[BUG] Improve Type Hints on Python Model V2 #1161

Closed
baluyotraf opened this issue Jan 6, 2023 · 7 comments
Closed

[BUG] Improve Type Hints on Python Model V2 #1161

baluyotraf opened this issue Jan 6, 2023 · 7 comments
Assignees

Comments

@baluyotraf
Copy link

baluyotraf commented Jan 6, 2023

Hello! We are playing around with the Python Model V2. We think it looks great, however the decorators fail when we apply our type checker (pyright on strict settings). Looks like the culprit is the type hint definitions on the decorators. The Callable type hint are not defined completely. For example:

# https://github.com/Azure/azure-functions-python-library/blob/dev/azure/functions/decorators/function_app.py#L285

def function_name(self, name: str) -> Callable:
    ...

These can use the recommendation from pyright or using the newer ParamSpec for typing.

I can work on this if needed since it's pretty simple yet pretty impactful for us.

@bhagyshricompany
Copy link

Hi @baluyotraf thanks for update will update you soon

@bhagyshricompany
Copy link

It sounds like you're encountering an issue where your type checker (pyright) is failing when applied to the decorators in the Azure Functions Python Library (azure-functions-python-library). The problem seems to be with the type hint definitions on the decorators, specifically the use of the Callable type hint. The Callable type hint is not defined completely, which is causing issues with your type checker.

One solution to this issue would be to update the type hint definitions on the decorators to be more specific. For example, instead of using Callable, you could use a more specific type hint such as Callable[[Arg1Type, Arg2Type], ReturnType]. This will give the type checker more information about the types of arguments and return values that the decorated function should have. Another way could be using new typing module introduced in python 3.10 called ParamSpec which is more specific, allowing more detailed function type hints.

Another solution would be to configuring your type checker to be less strict. This may allow it to process the decorators as they are currently defined, but it may also make it less effective at catching type-related errors in your code.

@baluyotraf
Copy link
Author

Yes. It looks like we're on the same page on the problem.

AFAIK there's no way to override the azure-functions-python-library type definitions without copying the entire stubs in our repository. Maintaining the entire stubs of typing for the decorators seems a bit too much.

To allow the type checking to pass through our pipelines, we just put # type: ignore on every Azure functions decorator that we use in Python. While not ideal, we would like to keep the strict settings on our typings.

I guess on our side, we would like to know if there's a nicer workaround on the issue, or if there are plans to update the typing in the python library. For now we are fine to just get by with the # type: ignore.

@bhagyshricompany
Copy link

@vrdmr please comment on this

@YunchuWang
Copy link
Member

@baluyotraf Hi baluyotraf, i submitted an PR addressing this issue, can you please take a look and let me know if you have any questions

@YunchuWang
Copy link
Member

pr merged, changes will go in next release in Feb

@baluyotraf
Copy link
Author

Yup no complains here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants