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

Type signature for AvroSerializer.__init__()'s to_dict parameter is incorrect #1896

Open
jonbuffington opened this issue Jan 8, 2025 · 1 comment

Comments

@jonbuffington
Copy link

Description

In release 2.7.0, the type signature for AvroSerializer.__init__()'s to_dict parameter is incorrect. The type signature does not allow None as a value but the implementation defaults to and supports None as a value.

The type signature for the to_dict parameter should be modified to support being optional (example for Python 3.12):

to_dict: Callable[[object, SerializationContext], dict] | None = None,

How to reproduce

Use pyright to check a module that calls AvroSerializer(…):

…
avro_deserializer = AvroDeserializer(schema_registry_client)
…

and you will get the following error:

error: Argument of type "None" cannot be assigned to parameter "from_dict" of type "(dict[Unknown, Unknown], SerializationContext) -> object" in function "__init__"
    Type "None" is not assignable to type "(dict[Unknown, Unknown], SerializationContext) -> object" (reportArgumentType)
@jonbuffington
Copy link
Author

The incorrect type signature also applies to AvroDeserializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants