diff --git a/conformance/results/mypy/namedtuples_define_functional.toml b/conformance/results/mypy/namedtuples_define_functional.toml
index 6356dc8c5..2b813418e 100644
--- a/conformance/results/mypy/namedtuples_define_functional.toml
+++ b/conformance/results/mypy/namedtuples_define_functional.toml
@@ -12,7 +12,7 @@ namedtuples_define_functional.py:52: error: "namedtuple()" has duplicate field n
namedtuples_define_functional.py:53: error: "namedtuple()" field name "def" is a keyword [misc]
namedtuples_define_functional.py:54: error: "namedtuple()" field name "def" is a keyword [misc]
namedtuples_define_functional.py:55: error: "namedtuple()" field name "_d" starts with an underscore [misc]
-namedtuples_define_functional.py:69: error: Missing positional argument "a" in call to "NT7" [call-arg]
+namedtuples_define_functional.py:97: error: Missing positional argument "a" in call to "NT15" [call-arg]
"""
conformance_automated = "Pass"
errors_diff = """
diff --git a/conformance/results/pycroscope/namedtuples_define_functional.toml b/conformance/results/pycroscope/namedtuples_define_functional.toml
index eaa0de901..a163b5583 100644
--- a/conformance/results/pycroscope/namedtuples_define_functional.toml
+++ b/conformance/results/pycroscope/namedtuples_define_functional.toml
@@ -14,5 +14,5 @@ output = """
./namedtuples_define_functional.py:53:6: Error calling (typename: str, field_names: str | collections.abc.Iterable[str], *, rename: bool = Literal[False], module: str | None = None, defaults: collections.abc.Iterable[Any[explicit]] | None = None) -> type[tuple[Any[explicit], ...]]: Type names and field names cannot be a keyword: 'def' [incompatible_call]
./namedtuples_define_functional.py:54:6: Error calling (typename: str, field_names: str | collections.abc.Iterable[str], *, rename: bool = Literal[False], module: str | None = None, defaults: collections.abc.Iterable[Any[explicit]] | None = None) -> type[tuple[Any[explicit], ...]]: Type names and field names cannot be a keyword: 'def' [incompatible_call]
./namedtuples_define_functional.py:55:6: Error calling (typename: str, field_names: str | collections.abc.Iterable[str], *, rename: bool = Literal[False], module: str | None = None, defaults: collections.abc.Iterable[Any[explicit]] | None = None) -> type[tuple[Any[explicit], ...]]: Field names cannot start with an underscore: '_d' [incompatible_call]
-./namedtuples_define_functional.py:69:0: In call to pycroscope.signature.NT7: Missing required argument 'a' [incompatible_call]
+./namedtuples_define_functional.py:97:0: In call to pycroscope.signature.NT15: Missing required argument 'a' [incompatible_call]
"""
diff --git a/conformance/results/pyrefly/namedtuples_define_functional.toml b/conformance/results/pyrefly/namedtuples_define_functional.toml
index 40c47f739..2bd3805e1 100644
--- a/conformance/results/pyrefly/namedtuples_define_functional.toml
+++ b/conformance/results/pyrefly/namedtuples_define_functional.toml
@@ -17,5 +17,5 @@ ERROR namedtuples_define_functional.py:52:31-34: Duplicate field `a` [bad-class-
ERROR namedtuples_define_functional.py:53:33-38: `def` is not a valid identifier [bad-class-definition]
ERROR namedtuples_define_functional.py:54:33-38: `def` is not a valid identifier [bad-class-definition]
ERROR namedtuples_define_functional.py:55:33-37: NamedTuple field name may not start with an underscore: `_d` [bad-class-definition]
-ERROR namedtuples_define_functional.py:69:4-6: Missing argument `a` in function `NT7.__new__` [missing-argument]
+ERROR namedtuples_define_functional.py:97:5-7: Missing argument `a` in function `NT15.__new__` [missing-argument]
"""
diff --git a/conformance/results/pyright/namedtuples_define_functional.toml b/conformance/results/pyright/namedtuples_define_functional.toml
index 2c9738f7b..e6630682f 100644
--- a/conformance/results/pyright/namedtuples_define_functional.toml
+++ b/conformance/results/pyright/namedtuples_define_functional.toml
@@ -15,7 +15,7 @@ namedtuples_define_functional.py:52:31 - error: Names within a named tuple must
namedtuples_define_functional.py:53:33 - error: Field names cannot be a keyword (reportGeneralTypeIssues)
namedtuples_define_functional.py:54:33 - error: Field names cannot be a keyword (reportGeneralTypeIssues)
namedtuples_define_functional.py:55:33 - error: Named tuple field names cannot start with an underscore (reportGeneralTypeIssues)
-namedtuples_define_functional.py:69:1 - error: Argument missing for parameter "a" (reportCallIssue)
+namedtuples_define_functional.py:97:1 - error: Argument missing for parameter "a" (reportCallIssue)
"""
conformance_automated = "Pass"
errors_diff = """
diff --git a/conformance/results/results.html b/conformance/results/results.html
index d740570e1..02884088c 100644
--- a/conformance/results/results.html
+++ b/conformance/results/results.html
@@ -2144,7 +2144,12 @@
Python Type System Conformance Test Results
Pass |
Pass |
Pass |
- Pass |
+
+ Partial
+
+ - Incorrectly rejects "match", "case" and "type" as field names for collections.namedtuple().
+
+ |
| namedtuples_type_compat |
@@ -2176,7 +2181,7 @@ Python Type System Conformance Test Results
4 / 4 • 100.0% |
4 / 4 • 100.0% |
4 / 4 • 100.0% |
- 4 / 4 • 100.0% |
+ 3.5 / 4 • 87.5% |
@@ -2491,7 +2496,7 @@ Python Type System Conformance Test Results
146 / 146 • 100.0% |
140.5 / 146 • 96.2% |
142 / 146 • 97.3% |
- 146 / 146 • 100.0% |
+ 145.5 / 146 • 99.7% |
diff --git a/conformance/results/ty/namedtuples_define_functional.toml b/conformance/results/ty/namedtuples_define_functional.toml
index 037fdf685..142b55d5f 100644
--- a/conformance/results/ty/namedtuples_define_functional.toml
+++ b/conformance/results/ty/namedtuples_define_functional.toml
@@ -15,5 +15,5 @@ namedtuples_define_functional.py:52:25: error[invalid-named-tuple] Duplicate fie
namedtuples_define_functional.py:53:25: error[invalid-named-tuple] Field name `def` in `namedtuple()` cannot be a Python keyword: Will raise `ValueError` at runtime
namedtuples_define_functional.py:54:25: error[invalid-named-tuple] Field name `def` in `namedtuple()` cannot be a Python keyword: Will raise `ValueError` at runtime
namedtuples_define_functional.py:55:25: error[invalid-named-tuple] Field name `_d` in `namedtuple()` cannot start with an underscore: Will raise `ValueError` at runtime
-namedtuples_define_functional.py:69:1: error[missing-argument] No argument provided for required parameter `a`
+namedtuples_define_functional.py:97:1: error[missing-argument] No argument provided for required parameter `a`
"""
diff --git a/conformance/results/zuban/namedtuples_define_functional.toml b/conformance/results/zuban/namedtuples_define_functional.toml
index 98ee2d2fd..16acd4c5c 100644
--- a/conformance/results/zuban/namedtuples_define_functional.toml
+++ b/conformance/results/zuban/namedtuples_define_functional.toml
@@ -1,5 +1,27 @@
-conformance_automated = "Pass"
+conformant = "Partial"
+notes = """
+Incorrectly rejects "match", "case" and "type" as field names for collections.namedtuple().
+"""
+conformance_automated = "Fail"
errors_diff = """
+Line 62: Unexpected errors ['namedtuples_define_functional.py:62: error: "namedtuple()" field name "match" is a keyword [misc]']
+Line 63: Unexpected errors ['namedtuples_define_functional.py:63: error: "NamedTuple()" field name "match" is a keyword [misc]']
+Line 64: Unexpected errors ['namedtuples_define_functional.py:64: error: Unexpected keyword argument "match" for "NT7" [call-arg]']
+Line 65: Unexpected errors ['namedtuples_define_functional.py:65: error: Unexpected keyword argument "match" for "NT8" [call-arg]']
+Line 66: Unexpected errors ['namedtuples_define_functional.py:66: error: "NT7" has no attribute "match" [attr-defined]']
+Line 67: Unexpected errors ['namedtuples_define_functional.py:67: error: "NT8" has no attribute "match" [attr-defined]']
+Line 69: Unexpected errors ['namedtuples_define_functional.py:69: error: "namedtuple()" field name "case" is a keyword [misc]']
+Line 70: Unexpected errors ['namedtuples_define_functional.py:70: error: "NamedTuple()" field name "case" is a keyword [misc]']
+Line 71: Unexpected errors ['namedtuples_define_functional.py:71: error: Unexpected keyword argument "case" for "NT9" [call-arg]']
+Line 72: Unexpected errors ['namedtuples_define_functional.py:72: error: Unexpected keyword argument "case" for "NT10" [call-arg]']
+Line 73: Unexpected errors ['namedtuples_define_functional.py:73: error: "NT9" has no attribute "case" [attr-defined]']
+Line 74: Unexpected errors ['namedtuples_define_functional.py:74: error: "NT10" has no attribute "case" [attr-defined]']
+Line 76: Unexpected errors ['namedtuples_define_functional.py:76: error: "namedtuple()" field name "type" is a keyword [misc]']
+Line 77: Unexpected errors ['namedtuples_define_functional.py:77: error: "NamedTuple()" field name "type" is a keyword [misc]']
+Line 78: Unexpected errors ['namedtuples_define_functional.py:78: error: Unexpected keyword argument "type" for "NT11" [call-arg]']
+Line 79: Unexpected errors ['namedtuples_define_functional.py:79: error: Unexpected keyword argument "type" for "NT12" [call-arg]']
+Line 80: Unexpected errors ['namedtuples_define_functional.py:80: error: "NT11" has no attribute "type" [attr-defined]']
+Line 81: Unexpected errors ['namedtuples_define_functional.py:81: error: "NT12" has no attribute "type" [attr-defined]']
"""
output = """
namedtuples_define_functional.py:16: error: Missing positional argument "y" in call to "Point1" [call-arg]
@@ -14,5 +36,23 @@ namedtuples_define_functional.py:52: error: "namedtuple()" has duplicate field n
namedtuples_define_functional.py:53: error: "namedtuple()" field name "def" is a keyword [misc]
namedtuples_define_functional.py:54: error: "namedtuple()" field name "def" is a keyword [misc]
namedtuples_define_functional.py:55: error: "namedtuple()" field name "_d" starts with an underscore [misc]
-namedtuples_define_functional.py:69: error: Missing positional argument "a" in call to "NT7" [call-arg]
+namedtuples_define_functional.py:62: error: "namedtuple()" field name "match" is a keyword [misc]
+namedtuples_define_functional.py:63: error: "NamedTuple()" field name "match" is a keyword [misc]
+namedtuples_define_functional.py:64: error: Unexpected keyword argument "match" for "NT7" [call-arg]
+namedtuples_define_functional.py:65: error: Unexpected keyword argument "match" for "NT8" [call-arg]
+namedtuples_define_functional.py:66: error: "NT7" has no attribute "match" [attr-defined]
+namedtuples_define_functional.py:67: error: "NT8" has no attribute "match" [attr-defined]
+namedtuples_define_functional.py:69: error: "namedtuple()" field name "case" is a keyword [misc]
+namedtuples_define_functional.py:70: error: "NamedTuple()" field name "case" is a keyword [misc]
+namedtuples_define_functional.py:71: error: Unexpected keyword argument "case" for "NT9" [call-arg]
+namedtuples_define_functional.py:72: error: Unexpected keyword argument "case" for "NT10" [call-arg]
+namedtuples_define_functional.py:73: error: "NT9" has no attribute "case" [attr-defined]
+namedtuples_define_functional.py:74: error: "NT10" has no attribute "case" [attr-defined]
+namedtuples_define_functional.py:76: error: "namedtuple()" field name "type" is a keyword [misc]
+namedtuples_define_functional.py:77: error: "NamedTuple()" field name "type" is a keyword [misc]
+namedtuples_define_functional.py:78: error: Unexpected keyword argument "type" for "NT11" [call-arg]
+namedtuples_define_functional.py:79: error: Unexpected keyword argument "type" for "NT12" [call-arg]
+namedtuples_define_functional.py:80: error: "NT11" has no attribute "type" [attr-defined]
+namedtuples_define_functional.py:81: error: "NT12" has no attribute "type" [attr-defined]
+namedtuples_define_functional.py:97: error: Missing positional argument "a" in call to "NT15" [call-arg]
"""
diff --git a/conformance/tests/namedtuples_define_class.py b/conformance/tests/namedtuples_define_class.py
index 03a631bfc..0bf832830 100644
--- a/conformance/tests/namedtuples_define_class.py
+++ b/conformance/tests/namedtuples_define_class.py
@@ -146,3 +146,23 @@ class Property(NamedTuple, Generic[T]):
class Unit(NamedTuple, object): # E
name: str
+
+
+# > At runtime, the ``namedtuple`` function disallows field names that begin with
+# > an underscore or are illegal Python identifiers, and either raises an exception
+# > or replaces these fields with a parameter name of the form ``_N``. The behavior
+# > depends on the value of the ``rename`` argument. Type checkers may replicate
+# > this behavior statically.
+
+class SoftKeywords(NamedTuple):
+ match: int # OK
+ case: int # OK
+ type: int # OK
+ lazy: int # OK
+
+
+softkw = SoftKeywords(match=1, case=2, type=3, lazy=4)
+softkw.match # OK
+softkw.case # OK
+softkw.type # OK
+softkw.lazy # OK
diff --git a/conformance/tests/namedtuples_define_functional.py b/conformance/tests/namedtuples_define_functional.py
index 49f7c1b0c..189a2c875 100644
--- a/conformance/tests/namedtuples_define_functional.py
+++ b/conformance/tests/namedtuples_define_functional.py
@@ -59,11 +59,39 @@
NT6 = namedtuple("NT6", ["abc", "_d"], rename=True) # OK
NT6(abc="", _1="") # OK
+NT7 = namedtuple("NT7", ["match"]) # OK
+NT8 = NamedTuple("NT8", [("match", int)]) # OK
+nt7 = NT7(match=1) # OK
+nt8 = NT8(match=1) # OK
+nt7.match # OK
+nt8.match # OK
+
+NT9 = namedtuple("NT9", ["case"]) # OK
+NT10 = NamedTuple("NT10", [("case", int)]) # OK
+nt9 = NT9(case=1) # OK
+nt10 = NT10(case=1) # OK
+nt9.case # OK
+nt10.case # OK
+
+NT11 = namedtuple("NT11", ["type"]) # OK
+NT12 = NamedTuple("NT12", [("type", int)]) # OK
+nt11 = NT11(type=1) # OK
+nt12 = NT12(type=1) # OK
+nt11.type # OK
+nt12.type # OK
+
+NT13 = namedtuple("NT13", ["lazy"]) # OK
+NT14 = NamedTuple("NT14", [("lazy", int)]) # OK
+nt13 = NT13(lazy=1) # OK
+nt14 = NT14(lazy=1) # OK
+nt13.lazy # OK
+nt14.lazy # OK
+
# > The ``namedtuple`` function also supports a ``defaults`` keyword argument that
# > specifies default values for the fields. Type checkers may support this.
-NT7 = namedtuple("NT7", "a b c", defaults=(1, 2))
-NT7(1) # OK
-NT7(1, 2, 3) # OK
-NT7() # E: too few arguments
+NT15 = namedtuple("NT15", "a b c", defaults=(1, 2))
+NT15(1) # OK
+NT15(1, 2, 3) # OK
+NT15() # E: too few arguments