|
43 | 43 | p6_4 = Point6(x=1.1, y=2) # E |
44 | 44 |
|
45 | 45 |
|
46 | | -# > At runtime, the ``namedtuple`` function disallows field names that are |
47 | | -# > illegal Python identifiers and either raises an exception or replaces these |
48 | | -# > fields with a parameter name of the form ``_N``. The behavior depends on |
49 | | -# > the value of the ``rename`` argument. Type checkers may replicate this |
50 | | -# > behavior statically. |
| 46 | +# > At runtime, the ``namedtuple`` function disallows field names that begin with |
| 47 | +# > an underscore or are illegal Python identifiers, and either raises an exception |
| 48 | +# > or replaces these fields with a parameter name of the form ``_N``. The behavior |
| 49 | +# > depends on the value of the ``rename`` argument. Type checkers may replicate |
| 50 | +# > this behavior statically. |
51 | 51 |
|
52 | 52 | NT1 = namedtuple("NT1", ["a", "a"]) # E?: duplicate field name |
53 | 53 | NT2 = namedtuple("NT2", ["abc", "def"]) # E?: illegal field name |
54 | 54 | NT3 = namedtuple("NT3", ["abc", "def"], rename=False) # E?: illegal field name |
| 55 | +NT4 = namedtuple("NT4", ["abc", "_d"], rename=False) # E?: illegal field name |
55 | 56 |
|
56 | | -NT4 = namedtuple("NT4", ["abc", "def"], rename=True) # OK |
57 | | -NT4(abc="", _1="") # OK |
| 57 | +NT5 = namedtuple("NT5", ["abc", "def"], rename=True) # OK |
| 58 | +NT5(abc="", _1="") # OK |
| 59 | +NT6 = namedtuple("NT6", ["abc", "_d"], rename=True) # OK |
| 60 | +NT6(abc="", _1="") # OK |
58 | 61 |
|
59 | 62 |
|
60 | 63 | # > The ``namedtuple`` function also supports a ``defaults`` keyword argument that |
|
0 commit comments