Skip to content

Require first argument of namedtuple to match with variable name #9577

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

Merged
merged 11 commits into from
Oct 18, 2020
Prev Previous commit
Next Next commit
Extract first argument only when namedtuple typechecked
  • Loading branch information
momohatt committed Oct 12, 2020
commit 2e8982e68e8db4f966a590ac0b9e9305b9e9453d
3 changes: 2 additions & 1 deletion mypy/semanal_namedtuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ def check_namedtuple(self,
is_typed = True
else:
return None, None
typename = cast(Union[StrExpr, BytesExpr, UnicodeExpr], call.args[0]).value
result = self.parse_namedtuple_args(call, fullname)
if result:
items, types, defaults, ok = result
else:
# This is a valid named tuple but some types are not ready.
typename = cast(Union[StrExpr, BytesExpr, UnicodeExpr], call.args[0]).value
return typename, None
if not ok:
# Error. Construct dummy return value.
Expand All @@ -182,6 +182,7 @@ def check_namedtuple(self,
self.store_namedtuple_info(info, name, call, is_typed)
return name, info

typename = cast(Union[StrExpr, BytesExpr, UnicodeExpr], call.args[0]).value
# We use the variable name as the class name if it exists. If
# it doesn't, we use the name passed as an argument. We prefer
# the variable name because it should be unique inside a
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy