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

Non-standard type-hinting thoughout the library. #208

Open
thisismygitrepo opened this issue Apr 14, 2024 · 3 comments
Open

Non-standard type-hinting thoughout the library. #208

thisismygitrepo opened this issue Apr 14, 2024 · 3 comments

Comments

@thisismygitrepo
Copy link

thisismygitrepo commented Apr 14, 2024

My linters and type checkers are failing to provide any help due to non-standard way of type hinting used in the library,
For instance, in the file: unified_trading:

    def kline_stream(self, interval: int, symbol: (str, list), callback):
        """Subscribe to the klines stream."""

        ...

The proper way of enshrining the logic that symbol can be either str OR list[str] is:

from typing import Union, Callable
def kline_stream(self, interval: int, symbol: Union[str, list[str]], callaback: Callable[[str], None]):
    ...

Once fixed, type checker will be able to statically check all the code (including the library itself) for any inconsistency.
Can you guys please use the standards?

Thank you,

@thisismygitrepo thisismygitrepo changed the title Non-standard type-checking. Non-standard type-hinting thoughout the library. Apr 14, 2024
@dextertd
Copy link
Collaborator

Are you referring to GUI hints in an IDE? I tried making this change but it doesn't make any difference in pycharm. Can you give me a way to test this?

@thisismygitrepo
Copy link
Author

thisismygitrepo commented Apr 16, 2024

Yes, I am referring to IDE.

It is weird that Pycharm makes no difference.

image

I use VS-Code with official pylance, mypy linter and type checker and I set them on hashest mode, so they yell at me for all tiny mistakes.

As can be seen in the image, becaues of non-standard type hinting, they fail to parse it and they think the type is Unknown, therefore they are unable to yell at me no matter what I pass as argument, because they don't know what should be passed to begin with.

You mentioned that it makes no diffrence, but you should get squiggly underline hiting from the editor saying you violated the types. At the moment, the callable argument is not even type-hintend, so, no matter what function you pass, the IDE is happy, until you run the code and you get error, but we want to get all the errors while we type, not at runtime (too late, too slow). In my example, the type-hint declares what signature the callable should have, so if you passed anything else, the IDE will underline it and declares it as error (in a static way before you run the code).

@dextertd
Copy link
Collaborator

Ah, I can see a similar prompt when hovering over the function name and it is more detailed when using typing. Will investigate implementing this

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

No branches or pull requests

2 participants