-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
**kwargs checked against wrong type with defaults or *args #1969
Comments
Can you try again with the latest revision from the repo? I fixed some things in this area recently. |
Never mind. I can still repro this. |
The logic the code might be implementing here, at least in the call to That logic doesn't seem to apply in the second case, though, which would make that a bug. In the |
And thanks, Karl, for the report! |
In particular, calling |
This can be fixed by adding at checkexpr.py#L1980 (right below the comment referring to that situation)
However, it raises another error for the following file. I wonder whether this is the expected behavior:
Result:
Perhaps that's intentional, but I don't see why the empty If the suggested solution seems valid, I can open a PR. |
(This appeared two more times so raise priority to normal) |
#5834 has another example of this with some details. |
Raised priority to high, since this keeps coming. As noticed in #6092 this bug only appears when the type of |
I think that I know how to fix this since I just recently worked on the relevant code. |
Actually the suggested fix by @elazarg above seems to be the correct one. I'll prepare a PR. |
@dataclass
class ContextData:
"""Hi."""
account: Optional[Dict[str, str]] = None
module: Optional[str] = None
data: Optional[MutableMapping[str, Any]] = None
class Context(ContextData, ABC):
"""Hello."""
@classmethod
def create(
cls,
data: MutableMapping[str, Any],
module: str,
attribs: Optional[MutableMapping[str, Any]] = None
):
to_save = {
"account": data.pop("account"),
"module": module,
"data": data,
}
if attribs:
to_save.update(attribs)
return cls(**to_save)
Could it be related to dataclasses? |
@snejus this doesn't look like the original problem. You might have to just declare I'm kind of curious where the |
Yup - you're right. Figured that out this morning and had to facepalm myself. :) It was related to the way the arguments are ordered. |
Seems like there's still a challenge here, in that, mypy seems to me to be giving a misleading error message. Is there are any way to report the specific kwarg dictionary item that is mistyped rather than reporting on the |
(based on python/mypy#1969 (comment))
Maybe a related example:
|
@ClementWalter In your example there is no guarantee that the argument names and types match the called function. For example, you have |
actually
|
results, with 0.4.3:
The text was updated successfully, but these errors were encountered: