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

Pyright Default None #1778

Open
collindutter opened this issue Feb 27, 2025 · 1 comment · May be fixed by #1779
Open

Pyright Default None #1778

collindutter opened this issue Feb 27, 2025 · 1 comment · May be fixed by #1779
Assignees
Milestone

Comments

@collindutter
Copy link
Member

We make frequent use of this pattern to lazily initialize values:

_client: openai.OpenAI = field(default=None, kw_only=True, alias="client", metadata={"serializable": False})
@lazy_property()
def client(self) -> openai.OpenAI:
return openai.OpenAI(
base_url=self.base_url,
api_key=self.api_key,
organization=self.organization,
)

max_input_tokens: int = field(kw_only=True, default=None)
max_output_tokens: int = field(kw_only=True, default=None)
def __attrs_post_init__(self) -> None:
if hasattr(self, "model"):
if self.max_input_tokens is None:
self.max_input_tokens = self._default_max_input_tokens()
if self.max_output_tokens is None:
self.max_output_tokens = self._default_max_output_tokens()

We default the field with a value of None, and lazily initialize it later on if the user did not provide their own, non-None, value.

Pyright's latest release seems to have patched this out.

Now we get many of these:

  /Users/collindutter/Documents/griptape/griptape/docs/examples/src/talk_to_a_webpage_1.py:41:9 - error: Argument of type "None" cannot be assigned to parameter "prompt_driver" of type "BasePromptDriver" in function "__init__"
    "None" is not assignable to "BasePromptDriver" (reportArgumentType)

Presumably the change came from:

Fixed bug that leads to inconsistent behavior in certain cases involving the evaluation of a call whose target signature involves a parameter with a default argument value, notably where the type of the default value isn't assignable to the declared type of its parameter.

@collindutter collindutter added this to the 1.5 milestone Feb 27, 2025
@collindutter collindutter self-assigned this Feb 27, 2025
@collindutter
Copy link
Member Author

collindutter commented Feb 27, 2025

This is a mess, some of the errors are from 3p libraries:

return TextArtifact(numexpr.evaluate(expression))

Diagnostics:
1. Argument of type "None" cannot be assigned to parameter "out" of type "ndarray[Unknown, Unknown]" in function "evaluate"
     "None" is not assignable to "ndarray[Unknown, Unknown]" [reportArgumentType]

https://github.com/pydata/numexpr/blob/be928864031ede0bf466fca625881b7e50a210bc/numexpr/necompiler.py?#L896

output_tokens = len(self.tokenizer.tokenizer.encode(generated_text))

Diagnostics:
1. Argument of type "None" cannot be assigned to parameter "truncation" of type "bool | str | TruncationStrategy" in function "encode"
     Type "None" is not assignable to type "bool | str | TruncationStrategy"
       "None" is not assignable to "bool"
       "None" is not assignable to "str"
       "None" is not assignable to "TruncationStrategy" [reportArgumentType]

https://github.com/huggingface/transformers/blob/222505c7e4d08da9095d12ddb72fb653f4b6da33/src/transformers/tokenization_utils_base.py#L2622

Going to sit on this for a couple days, maybe pyright will revert. Appears to be a final decision.

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

Successfully merging a pull request may close this issue.

1 participant