-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
No errors for keyword arguments in class statement #6403
Comments
This is currently by design. Pyright doesn't ever report extra keyword arguments passed in a class declaration. So this issue isn't specific to I'm going to change this from a bug to an enhancement request and consider it in that light. I think it's a reasonable feature to add, assuming it doesn't produce too many false positives in typical code bases. |
Thanks, I didn't know that. For normal classes, keyword arguments may be valid, depending on the metaclass and |
Currently, pyright does check |
The reason pyright is not flagging the error for a I propose that we fix this by modifying the definition of @type_check_only
class _TypedDictMeta(type):
def __new__(
__mcls: type[typing_extensions.Self],
__name: str,
__bases: tuple[type, ...],
__namespace: dict[str, Any],
*,
total: bool = False,
) -> typing_extensions.Self: ...
@type_check_only
class _TypedDict(Mapping[str, object], metaclass=_TypedDictMeta):
... This not only addresses the bug and more closely reflects the actual runtime class hierarchy, but it also has the benefit of providing better in-editor support for the Thoughts? |
Good catch, that sounds like a good idea! Type checkers may still need a special case to prohibit a custom |
…class` statement when the class has no custom metaclass or `__init_subclass__` in its hierarchy. In this case, the `object.__init_subclass__` method applies, and it accepts no additional keyword arguments. Also improved the error reporting for `__init_subclass__` in general. This addresses #6403.
…class` statement when the class has no custom metaclass or `__init_subclass__` in its hierarchy. In this case, the `object.__init_subclass__` method applies, and it accepts no additional keyword arguments. Also improved the error reporting for `__init_subclass__` in general. This addresses #6403. (#6405)
I've improved pyright's handling of |
This is addressed in pyright 1.1.336, which I just published. It will also be included in a future release of pylance. |
Example:
https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAqiApgCYAiSAxjAFC1UA2AhgM6uHkAURCZlNADRRmAXgDMASgBctKPJHTMKGEA
This fails at runtime, and type checkers should reject it too. (cf. python/mypy#16438)
The text was updated successfully, but these errors were encountered: