Support NamedTuple created via kwargs #2627
Replies: 4 comments
-
Pylance supports two forms of NamedTuple: the class version (which is recommended if you are using types) and the list of tuples version. It doesn't currently support the form that you are using. If you switch to one of the following, it will work. class Result(NamedTuple):
a: int
one_over_a: float Result = NamedTuple("Result", [("a", int), ("one_over_a", float)]) |
Beta Was this translation helpful? Give feedback.
-
Got it, thanks. Any plans to support the form I used? Why is the class form recommended? |
Beta Was this translation helpful? Give feedback.
-
No plans to support this form at this time. I've never run across it before. If a sufficient number of users request it, we would consider adding support. The class form is easier to read (especially when types are specified), it's more like other class definitions, and it works better with tooling like pylance (e.g. with the "go to declaration" command) because the variable declarations use standard declaration syntax. |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
PyLance version 2021.7.2
Python extension version 2021.6.944021595
VSCode version 1.58.0
Python 3.8.10 (virtual environment)
Windows 10
I expect to get a suggestion for
s.a
ands.one_over_a
as I typed thatprint
statement; instead I getcount
,index
,__add__
, etc.Logs
Beta Was this translation helpful? Give feedback.
All reactions