8000 Add support for namedtuple methods (issue #1076) by elazarg · Pull Request #1810 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add support for namedtuple methods (issue #1076) #1810

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 85 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
ecca142
namedtuple: add (shaky) support for _replace, _asdict + naive test
elazarg Jul 6, 2016
8ef445f
namedtuple: add tests and refine types
elazarg Jul 6, 2016
5e429cd
minor cleanup
elazarg Jul 6, 2016
0214e3c
minor cleanup
elazarg Jul 6, 2016
fbb75c3
flake8-ing
elazarg Jul 6, 2016
17d7f8b
fix type errors
elazarg Jul 6, 2016
6dd370c
fix type errors
elazarg Jul 6, 2016
1370fbf
Merge branch 'namedtuple' of https://github.com/elazarg/mypy into nam…
elazarg Jul 6, 2016
560eb3e
_fields will not be supported
elazarg Jul 6, 2016
2627511
slight refactoring
elazarg Jul 6, 2016
46475d4
restore tests for _replace and _asdict
elazarg Jul 6, 2016
c1dc1c7
NamedTupleTypeInfo
elazarg Jul 9, 2016
763e0c0
run both Replace and AsTuple
elazarg Jul 10, 2016
4b10a35
fix most of the tests
elazarg Jul 10, 2016
ee047f8
complete support for _replace
elazarg Jul 10, 2016
725d53c
flake8-ing
elazarg Jul 10, 2016
044e640
Add partial support for calling '_replace' statically
elazarg Jul 12, 2016
eb6534e
fix method name
elazarg Aug 11, 2016
aa0d5da
namedtuple tests pass. list has problems
elazarg Aug 14, 2016
e12bd01
tests pass. OrderedDict unsupported. cleanup still required
elazarg Aug 14, 2016
dc9d8da
fix line endings
elazarg Aug 14, 2016
158b068
flake8-ing
elazarg Aug 14, 2016
90ffb08
s/self_type/with_fallback. Fix visitor type
elazarg Aug 14, 2016
9a6e6cd
uniform copy_with. typechecks.
elazarg Aug 14, 2016
76d709e
uniform copy_with. typechecks.
elazarg Aug 14, 2016
20bf222
rename tests to startwith NamedTuple
elazarg Aug 15, 2016
a2696c2
Read-only attributes. Can't set new attributes in subclasses yet
elazarg Aug 15, 2016
9e1b866
update semantic namedtuple repr name
elazarg Aug 15, 2016
f7b531f
support _fields
elazarg Aug 15, 2016
67bdafe
support _source. test for unit namedtuple
elazarg Aug 15, 2016
39bce74
support _asdict()->OrderedDict as an UnboundType
elazarg Aug 15, 2016
a2db6a0
minor cleanup
elazarg Aug 15, 2016
8784ce0
support _make and _field_types
elazarg Aug 16, 2016
191de7c
namedtuple: add (shaky) support for _replace, _asdict + naive test
elazarg Jul 6, 2016
6d2d6d1
namedtuple: add tests and refine types
elazarg Jul 6, 2016
8819af9
minor cleanup
elazarg Jul 6, 2016
9fb5137
flake8-ing
elazarg Jul 6, 2016
35c30a2
fix type errors
elazarg Jul 6, 2016
a642a7f
_fields will not be supported
elazarg Jul 6, 2016
c505cbc
slight refactoring
elazarg Jul 6, 2016
9f96ca7
restore tests for _replace and _asdict
elazarg Jul 6, 2016
5c2d3ac
NamedTupleTypeInfo
elazarg Jul 9, 2016
41ed075
run both Replace and AsTuple
elazarg Jul 10, 2016
6dd568f
fix most of the tests
elazarg Jul 10, 2016
b18fc25
complete support for _replace
elazarg Jul 10, 2016
d7dbd3f
flake8-ing
elazarg Jul 10, 2016
2b67380
Add partial support for calling '_replace' statically
elazarg Jul 12, 2016
525c081
fix method name
elazarg Aug 11, 2016
15acfe0
namedtuple tests pass. list has problems
elazarg Aug 14, 2016
fb9ba7f
tests pass. OrderedDict unsupported. cleanup still required
elazarg Aug 14, 2016
99635c5
fix line endings
elazarg Aug 14, 2016
8f61c13
flake8-ing
elazarg Aug 14, 2016
ff21b0c
s/self_type/with_fallback. Fix visitor type
elazarg Aug 14, 2016
4c1bfe4
uniform copy_with. typechecks.
elazarg Aug 14, 2016
b0d78ba
uniform copy_with. typechecks.
elazarg Aug 14, 2016
87c804c
rename tests to startwith NamedTuple
elazarg Aug 15, 2016
6adc2f9
Read-only attributes. Can't set new attributes in subclasses yet
elazarg Aug 15, 2016
7ed7b0e
update semantic namedtuple repr name
elazarg Aug 15, 2016
c7dc9a7
support _fields
elazarg Aug 15, 2016
b39925b
support _source. test for unit namedtuple
elazarg Aug 15, 2016
030307e
support _asdict()->OrderedDict as an UnboundType
elazarg Aug 15, 2016
12d3407
minor cleanup
elazarg Aug 15, 2016
1f944fc
support _make and _field_types
elazarg Aug 16, 2016
7825f79
Merge branch 'namedtuple'
elazarg Aug 16, 2016
8a0ce40
merge upstream
elazarg Aug 16, 2016
7978357
merge fix except Awaitable lookup
elazarg Aug 16, 2016
badc3f9
merge fix
elazarg Aug 16, 2016
c051f3f
Merge remote
elazarg Aug 17, 2016
44c124b
Merge branch 'master' into namedtuple
elazarg Aug 17, 2016
d067c9e
fix syntax error
elazarg Aug 17, 2016
42342de
Merge branch 'master' into namedtuple
elazarg Aug 18, 2016
a5ccc50
join/meet namedtuples as namedtuple only if attrs are equal
elazarg Aug 20, 2016
eaf4b99
join/meet namedtuples as namedtuple only if attrs are equal. add tests.
elazarg Aug 20, 2016
9829b25
Fix conflicts:
elazarg Aug 21, 2016
b1988f8
Merge branch 'master' into namedtuple
elazarg Aug 28, 2016
8ced59e
Merge remote-tracking branch 'upstream/master' into namedtuple
elazarg Aug 28, 2016
053ee56
remove NamedTupleType
elazarg Aug 30, 2016
94bb8d0
Merge remote-tracking branch 'upstream/master' into namedtuple
elazarg Aug 30, 2016
71f0d78
restore semanal test
elazarg Aug 30, 2016
66a77fb
fix signatures
elazarg Sep 1, 2016
922dd91
_asdict() -> Dict
elazarg Sep 1, 2016
6460839
_asdict() -> OrderedDict
elazarg Sep 1, 2016
cd5b933
use buitlins.dict; rearrange build_namedtuple_typeinfo
elazarg Sep 1, 2016
4b93761
Merge remote-tracking branch 'upstream/master' into namedtuple
elazarg Sep 1, 2016
500a847
remove unneeded 'class dict' from proprty.pyi
elazarg Sep 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge fix except Awaitable lookup
  • Loading branch information
elazarg committed Aug 16, 2016
commit 797835765b04796f2bf11ccbb48f60f55a4db34e
5 changes: 4 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
from mypy.errors import Errors, report_internal_error
from mypy.types import (
NoneTyp, CallableType, Overloaded, Instance, Type, TypeVarType, AnyType,
FunctionLike, UnboundType, TypeList, TypeVarDef, TypeVarDef, Void,
FunctionLike, UnboundType, TypeList, TypeVarDef, Void,
replace_leading_arg_type, TupleType, UnionType, StarType, EllipsisType,
NamedTupleType, TypeType
)
Expand Down Expand Up @@ -1728,6 +1728,9 @@ def add_namedtuple_method(self, symbols: SymbolTable, info: TypeInfo, this_type:
func.is_class = is_classmethod
symbols[funcname] = SymbolTableNode(MDEF, func)

def make_argument(self, name: str, type: Type) -> Argument:
return Argument(Var(name), type, None, ARG_POS)

def analyze_types(self, items: List[Node]) -> List[Type]:
result = [] # type: List[Type]
for node in items:
Expand Down
3 changes: 2 additions & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,8 @@ def visit_tuple_type(self, t: TupleType) -> str:
return 'Tuple[{}]'.format(s)

def visit_namedtuple_type(self, t: NamedTupleType) -> str:
s = self.list_str(zip(t.attrs, t.items))
s = ', '.join('({}, {})'.format(repr(attr), item.accept(self))
for attr, item in zip(t.attrs, t.items))
return '{}[{}]'.format(t.name, s)

def visit_star_type(self, t: StarType) -> str:
Expand Down
0