Skip to content

Pyright: custom scalar yields "Type of scalar is partially unknown" #3579

Open

Description

In our project, we want to introduce an "alias" for a string, which is called CodeInput. Creating a custom scalar as described in the docs yields a pyright error.

Describe the Bug

Creating a custom scalar

CodeInput = strawberry.scalar(
    NewType("CodeInput", str),
    serialize=lambda v: v,
    parse_value=lambda v: v,
)

and checking it via pyright <file> yields:

/home/tobias/repos/demo/backend/demo/graphql/types/codes.py
  /home/tobias/repos/demobackend/demo/graphql/types/codes.py:53:13 - error: Type of "scalar" is partially unknown
    Type of "scalar" is "Overload[(*, name: str | None = None, description: str | None = None, specified_by_url: str | None = None, serialize: (...) -> Unknown = identity, parse_value: ((...) -> Unknown) | None = None, parse_literal: ((...) -> Unknown) | None = None, directives: Iterable[object] = ()) -> ((_T@scalar) -> _T@scalar), (cls: _T@scalar, *, name: str | None = None, description: str | None = None, specified_by_url: str | None = None, serialize: (...) -> Unknown = identity, parse_value: ((...) -> Unknown) | None = None, parse_literal: ((...) -> Unknown) | None = None, directives: Iterable[object] = ()) -> _T@scalar]" (reportUnknownMemberType)
  /home/tobias/repos/demo/backend/demo/graphql/types/codes.py:55:22 - error: Type of parameter "v" is unknown (reportUnknownLambdaType)
  /home/tobias/repos/demo/backend/demo/graphql/types/codes.py:55:25 - error: Return type of lambda is unknown (reportUnknownLambdaType)
  /home/tobias/repos/demo/backend/demo/graphql/types/codes.py:56:24 - error: Type of parameter "v" is unknown (reportUnknownLambdaType)
  /home/tobias/repos/demo/backend/demo/graphql/types/codes.py:56:27 - error: Return type of lambda is unknown (reportUnknownLambdaType)
5 errors, 0 warnings, 0 informations 

System Information

  • Strawberry version (if applicable): 0.235.1

Additional Context

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions