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 more comprehensive typing and check with mypy #144

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

terencehonles
Copy link
Contributor

Sorry I've been pretty busy focused on other things. The branch had already been updated to include at least some typing and all that needed to be clicked is the "reopen" button. Since that may not have been clear I'm reopening #137 as a new PR.

@terencehonles terencehonles changed the title drop support for EOL Python 3.5 drop support for EOL Python 3.5 and add typing Apr 30, 2021
@terencehonles terencehonles force-pushed the drop-eol-python-3.5 branch 2 times, most recently from 8e1812e to db5c90d Compare April 30, 2021 02:33
watchtower/__init__.py Outdated Show resolved Hide resolved
@terencehonles
Copy link
Contributor Author

Ok, that should be back in a state that the CI can run against it

watchtower/__init__.py Outdated Show resolved Hide resolved
watchtower/__init__.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@terencehonles terencehonles left a comment

Choose a reason for hiding this comment

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

Updated to remove the boto3 protocols.

super().__init__(*args, **kwargs)
self.log_group = log_group
self.stream_name = stream_name
self.use_queues = use_queues
self.send_interval = send_interval
if isinstance(send_interval, timedelta):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was updated to match the text, but the :type: was previously just int

@terencehonles terencehonles changed the title drop support for EOL Python 3.5 and add typing add more comprehensive typing and check with mypy Nov 14, 2021
@terencehonles
Copy link
Contributor Author

I'll need to double check everything, but I've resolved the conflicts and that should be closer to what I was trying to merge. I didn't type new functions that were added in #158, but this at least gets this PR into a state where it's more easily comparable to develop

docs/conf.py Outdated
@@ -11,6 +11,8 @@
source_suffix = [".rst", ".md"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
pygments_style = "sphinx"
autoclass_content = "both"
#autodoc_typehints = "description"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was for sphinx.ext.autodoc.typehints I assume sphinx_autodoc_typehints doesn't need this, but not sure why the other project was chosen and it looks like they are looking for a new maintainer and it may make sense to go with the main Sphinx project

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the pointer. I've addressed this separately in ed0d3cc.

Choose a reason for hiding this comment

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

A new maintainer has been found 😊

warnings.warn("Log message size exceeds CWL max payload size, truncated", WatchtowerWarning)
_msg2["message"] = _msg2["message"][:max_message_body_size]
return _msg2

# See https://boto3.readthedocs.io/en/latest/reference/services/logs.html#CloudWatchLogs.Client.put_log_events
while msg != self.END:
cur_batch = [] if msg is None or msg == self.FLUSH else [msg]
cur_batch: List[dict] = [] if msg is None or msg == self.FLUSH else [cast(dict, msg)]
Copy link
Owner

Choose a reason for hiding this comment

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

This looks almost all good to go, except let's please remove all of the casts and asserts. The typing information should decorate the function signatures, not be part of the execution. If mypy fails to check this method without calls to cast and asserts, then we should disable mypy checking for those lines, or possibly split up the method into multiple methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll look at the PR to see what makes sense. In case you aren't familiar, cast is just a noop at runtime so while it's calling more code it shouldn't be that big of a deal. It does enrich mypy with more information and I'm not sure if mypy treats a type: ignore equally, but I can double check. For the asserts I believe I have generally used them to narrow optional variables, but I will review the PR since it's been awhile since I looked at this code.

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