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

Unexpected keyword argument "reject_bytes" for "dumps" #563

Open
aspacca opened this issue Aug 11, 2022 · 4 comments
Open

Unexpected keyword argument "reject_bytes" for "dumps" #563

aspacca opened this issue Aug 11, 2022 · 4 comments

Comments

@aspacca
Copy link

aspacca commented Aug 11, 2022

What did you do?

  • added this function in my source:
def json_dumper(json_object: Any) -> str:
    return ujson.dumps(json_object, ensure_ascii=False, reject_bytes=False)
  • run mypy

What did you expect to happen?

mypy to not complain about the new function

What actually happened?

mypy returned the following error:
Unexpected keyword argument "reject_bytes" for "dumps"

What versions are you using?

  • OS: 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64 x86_64
  • Python: Python 3.9.13
  • UltraJSON: 5.4.0

Please include code that reproduces the issue.

The best reproductions are self-contained scripts with minimal dependencies.

def json_dumper(json_object: Any) -> str:
    return ujson.dumps(json_object, ensure_ascii=False, reject_bytes=False)
@bwoodsend
Copy link
Collaborator

We don't provide stubs so wherever mypy gathers its information about which arguments each function takes, it's not here.

@bwoodsend
Copy link
Collaborator

Digging around, it's here you want to change. I suggest you make a pull request to typeshed.

@aspacca
Copy link
Author

aspacca commented Aug 11, 2022

@bwoodsend thanks for investigating into it even if it was not a problem of the codebase :)

I will look into opening a PR to typeshed

@JustAnotherArchivist
Copy link
Collaborator

I looked a bit into what it would take to ship stubs ourselves so we don't need to remember to send a PR to typeshed upon a release with API changes. To say it's a bit of a mess is probably an understatement. PEP 561 specifies how stubs should be shipped by packages, but it assumes (requires?) an actual Python package structure and isn't easily applied to a single-module extension. There's an open issue about this, too: python/typing#1061. The hack suggested there of having _ujson with a from _ujson import * Python package would probably be least likely to break, but I'm not sure we want to go down that route. The single-file approach suggested there sounds better, but given that it's not even specified to work, it's likely there are edge cases where it breaks. So it's probably best to just stay with typeshed at least until an acceptable solution exists.

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