Skip to content

Conversation

@autra
Copy link
Contributor

@autra autra commented Jul 23, 2025

Hi!

I noticed the project didn't pass mypy in strict mode, so I went ahead and fixed it.

I also added a github workflow that checks the typing on every pull request, if you're interested.

Thanks!

@sasha-tkachev
Copy link
Owner

Hi @autra,

Thank you for the updates and the workflow addition!
I will review the pull request in the next few days.

Thanks again!

@autra autra force-pushed the mypy_strict_mode branch from 4ea124b to adaa7a9 Compare July 23, 2025 16:38
_settings: CloudEventSettings = CloudEventSettings()
_json: Any
_body: Any
_body: bytes
Copy link
Owner

Choose a reason for hiding this comment

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

@autra doesn't it break backwards compatibility?

Copy link
Owner

Choose a reason for hiding this comment

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

@autra, I checked what happens if this is replaced by Any and # type: ignore at the end of the body function the strict mypy still passes.

What do you think?
I'm not sure if I'm missing something.

Would it be ok if we keep it Any, and just ignore away the other warnings caused by this?
I don't want to break anybody depending on it.

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 don't think this change (from Any to bytes) really breaks anything that wasn't broken before. If I understand correctly, Any basically means "don't bother checking" to the type checker. If we change it to bytes, we align ourselves with the reality (because the runtime type is bytes already, whether we type check or not).

For instance, with this snippet, the type checker is happy, but we still have a failure at runtime:

from typing import Any

body: Any = b'foo'

body.decode("UTF-8")
body.append("foo")

If we change the type of body to bytes, same error, but at type checking time. I don't think failing faster should be considered as a breaking change. Actually, people using type checking tool would arguably want that. What do you think?

Copy link
Owner

@sasha-tkachev sasha-tkachev Jul 25, 2025

Choose a reason for hiding this comment

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

I dont feel comfertable to chainging this type to bytes.
I think the slight upside is not worth the risk of messing some downstream dependencies for reasons I cannot forsee.

@autra Would you be open to changing it back to Any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well of course, it's your call after all.

That being said, what about releasing a major version then, if you're afraid about potential breakage? People won't automatically get it and it should be ok.

But again, we're just changing the type hint, the only thing we can ever break is mypy execution, not real execution.

If you still want me to revert that, no problem I'll do it.

Copy link
Owner

Choose a reason for hiding this comment

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

@autra Let's keep it Any.

We will change it to bytes on the next Major release

Thank you autra so much!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@sasha-tkachev
Copy link
Owner

@autra Also, don't worry about CI, I have checked it locally

@autra autra force-pushed the mypy_strict_mode branch from adaa7a9 to a7976bc Compare July 25, 2025 15:47
@sasha-tkachev sasha-tkachev merged commit f9e0de6 into sasha-tkachev:main Jul 26, 2025
@sasha-tkachev
Copy link
Owner

@autra Thank you so much for your contribution

Version will be released in the following days

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