-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Enum
and NamedTuple
should not allow extra keywords
#16521
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
Comments
Do you happen to know why subclasses of class Foo(NamedTuple):
x: int
print(type(Foo)) # <class 'type'> As for class EnumMeta(type):
if sys.version_info >= (3, 11):
def __new__(
metacls: type[_typeshed.Self],
cls: str,
bases: tuple[type, ...],
classdict: _EnumDict,
*,
boundary: FlagBoundary | None = None,
_simple: bool = False,
**kwds: Any,
) -> _typeshed.Self: ...
elif sys.version_info >= (3, 9):
def __new__(
metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any
) -> _typeshed.Self: ...
else:
def __new__(metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> _typeshed.Self: ... The |
That's incorrect; it does: https://github.com/python/cpython/blob/1a969b4f55f92a17bec82ce0366021a53afdb2c3/Lib/typing.py#L2715 |
Ah, that explains it. Then I'd argue that the typeshed definition of the @type_check_only
class _NamedTupleMeta(type): ...
class NamedTuple(tuple[Any, ...], metaclass=_NamedTupleMeta):
... This would more correctly reflect the runtime behavior, and then type checkers wouldn't need to hardcode that knowledge. Their normal metaclass conflict rules would apply. |
That sounds reasonable to me — though the full semantics of NamedTuple are inexpressible in typeshed's stubs. (At runtime, |
This issue has some mypy internal specifics, because we have |
This code produces no error:
It is much easier with the
NamedTuple
, but, I think thatenum
might allow some keywords likeboundary=STRICT
.So, I think that I will split the PRs for these two problems.
Refs #16432
The text was updated successfully, but these errors were encountered: