Replies: 1 comment 2 replies
-
|
Pyright's type checking logic for custom metaclass
I don't recall why the code for case 2 skips positional parameters and keyword parameters with defaults. This is some of the older code in pyright. It's possible that I didn't have a good understanding of the runtime behavior at the time I wrote it. It's also possible that I attempted to implement a more complete check, but it produced too many false positives. I'll note that mypy doesn't appear to check any of these cases. If you'd like to see more complete type checking for case 2, you're welcome to file an enhancement request in the pyright issue tracker. Unless and until mypy also implements such functionality, I'll consider it a lower priority to support this in pyright. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Asking as a question because I'm not sure if this is by design. Previous history: #6403.
For context, we define
ModelMetaclass.__new__()in Pydantic, so even if we could rely on a customBaseModel.__init_subclass__()to provide type checking for class arguments (which we already do but doesn't seem to be required becauseModelMetaclass.__new__()takes priority), we can't lie to type checkers about the existence ofModelMetaclass.__new__(), and so we'd like to confirm support for the the metaclass extra keyword arguments which seems to be inconsistent right now:Code sample in pyright playground. Seems like mypy also doesn't catch most of these:
Beta Was this translation helpful? Give feedback.
All reactions