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

Use typing.overload to improve type hints of pypika.terms #19

Closed
wants to merge 3 commits into from

Conversation

waketzheng
Copy link
Contributor

Does not change any logic, only type hints improve

@@ -66,10 +67,31 @@ def tables_(self) -> set["Table"]:
def fields_(self) -> set["Field"]:
return set(self.find_(Field))

if TYPE_CHECKING: # pragma: nocoverage

@typing.overload
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like we are masking the bad typing problem instead of solving 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.

After there typing lines added, there are about 40 markers of type:ignore removed!

def wrap_constant(val: tuple, wrapper_cls: Type[Term] | None = None) -> "Tuple": ...
@typing.overload
@staticmethod
def wrap_constant(val: Any, wrapper_cls: None = None) -> "ValueWrapper": ...
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is not like the others.

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 really don't like such two functions(wrap_constant/wrap_json), they looks strange. It will be very great if you can refactor them...

@henadzit
Copy link
Contributor

henadzit commented Dec 4, 2024

Hey, please have a look at my PR that removes these warnings without adding overloading.

@waketzheng waketzheng closed this Dec 5, 2024
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