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

Missing loads and load definitions in __init__.pyi #103

Closed
hikariyo opened this issue Jan 7, 2023 · 8 comments
Closed

Missing loads and load definitions in __init__.pyi #103

hikariyo opened this issue Jan 7, 2023 · 8 comments

Comments

@hikariyo
Copy link

hikariyo commented Jan 7, 2023

I know it is defined in __init__.py, but it seems that PyCharm only analyzes __init__.pyi, where loads is not defined.

Maybe I could create a PR to fix this tiny problem if you appreciate it.

image

@hikariyo hikariyo changed the title Missing loads definition in __init__.pyi Missing loads and load definitions in __init__.pyi Jan 7, 2023
@hikariyo
Copy link
Author

hikariyo commented Jan 7, 2023

The same as load function.

@lemire
Copy link
Contributor

lemire commented Jan 11, 2023

@kifuan Would you prepare a pull request? I am sure it would be considered.

@hikariyo
Copy link
Author

Sure, there are two ways.

  1. Copy the declarations in __init__.py, like the code below:
def loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None,
          parse_constant=None, object_pairs_hook=None, **kwargs):
  ...
  1. Use json.load, json.loads.
loads = json.loads
load = json.load

As __init__.pyi is only an interface that will not be executed, it works properly.

image

@hikariyo
Copy link
Author

But I prefer the first way, which will not confuse users.

@lemire
Copy link
Contributor

lemire commented Jan 11, 2023

Can't this be done automatically...

https://www.mypy-lang.org

@TkTech
Copy link
Owner

TkTech commented Jan 11, 2023

Can't this be done automatically...

https://www.mypy-lang.org

Automatic generation doesn't work terribly well with native extensions.

@TkTech
Copy link
Owner

TkTech commented Jan 11, 2023

Use json.load, json.loads.

We don't have a 1:1 interface with json.load/s, so this would result in incorrect signatures.

@hikariyo
Copy link
Author

Is __init__.pyi generated or written manually? It doesn't look like a generated file.

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

3 participants