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

Typings #1163

Merged
merged 16 commits into from
Jan 29, 2024
Merged

Typings #1163

merged 16 commits into from
Jan 29, 2024

Conversation

olivakar
Copy link
Collaborator

@olivakar olivakar commented Jan 10, 2024

No description provided.

@olivakar olivakar changed the title one pass Typings Jan 11, 2024
@olivakar olivakar marked this pull request as ready for review January 18, 2024 19:30
# Will be implemented differently in child classes, but define here for static analysis
pass

@classmethod
def create_from_connection_string(cls, connection_string, **kwargs):
def create_from_connection_string(cls, connection_string: str, **kwargs: Dict[str, Any]) -> Self:
Copy link
Member

Choose a reason for hiding this comment

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

Don't annotate the kwargs. Here and everywhere.

"""
Read-only property to indicate if the transport is connected or not.
"""
return self._mqtt_pipeline.connected

@property
def on_connection_state_change(self):
def on_connection_state_change(self) -> Callable[[Any], Any]:
Copy link
Member

Choose a reason for hiding this comment

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

I'm somewhat surprised this passes static analysis, although I suppose that's due to only annotating the surface.

The issue is that this is too broad. It says you can set any callable that takes any number of arguments and returns any type of value. This is not true, and following this annotation would produce errors.

This should probably be FunctionOrCoroutine[[None], None], however, I'm not quite sure if that is valid for all versions of Python - it used to not be due to a bug, but I believe that has been fixed since I reported it? If it hasn't been, I can live with Callable[[Any], Any], but it's problematic.

Here and everywhere obviously (although the specific type annotations would change with handler definition)

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