Problem description
A problem I often encounter with the Replit type checker (pyright-extended, I think) is that it seems to make many assumptions that other type checkers don’t make. For example, when I was using ChatGroq with Langchain the other day, I passed in my API key as such:
llm = ChatGroq(
temperature=0,
api_key=os.environ["GROQ_API_KEY"],
model="mixtral-8x7b-32768",
)
And then pyright-extended tells me this:
Argument of type "str" cannot be assigned to parameter "api_key" of type "SecretStr | None" in function "__init__"
Type "str" cannot be assigned to type "SecretStr | None"
"str" is incompatible with "SecretStr"
"str" is incompatible with "None"
If you go to the documentation for SecretStr, it is syntactic sugar designed to make it clear when you are dealing with a sensitive string, and the point of it is that you pass a string and it is converted to a SecretStr. This forces me to add #type:ignore
to the end of the line, which is almost always bad practice, or to come up with a way to convert a str to a SecretStr, or make an assert
statement, when the whole point is that it happens automatically.
I really benefit from type checking, but Replit type checking is causing problems by making me write a bunch of assert statements, #type:ignore
comments, and other things that add complexity to an otherwise simple task.
Thanks!
Expected behavior
Replit type checking should understand duck typing, and not show syntax errors in the editor when a class that is functionally equivalent to another class is used.
Actual behavior
Replit type checking relies very heavily on the type definition of a function, which is a problem in Python.
Steps to reproduce
- Make a new Repl
- Install
langchain
andlangchain_groq
- Type this code:
import os
from langchain_groq import ChatGroq
llm = ChatGroq(
temperature=0,
api_key=os.environ["GROQ_API_KEY"],
model="mixtral-8x7b-32768",
)
Browser
Chrome
OS
Windows 11
Device if mobile
N/A
Plan
Core membership