Skip to content

Add type hints to strconv.py, and propagate implications #2162

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 1 commit into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def accept(self, visitor: NodeVisitor[T]) -> T:
class ImportFrom(ImportBase):
"""from m import x [as y], ..."""

id = None # type: str
relative = None # type: int
names = None # type: List[Tuple[str, Optional[str]]] # Tuples (name, as name)

def __init__(self, id: str, relative: int, names: List[Tuple[str, Optional[str]]]) -> None:
Expand All @@ -270,6 +272,8 @@ def accept(self, visitor: NodeVisitor[T]) -> T:

class ImportAll(ImportBase):
"""from m import *"""
id = None # type: str
relative = None # type: int

def __init__(self, id: str, relative: int) -> None:
super().__init__()
Expand Down Expand Up @@ -1727,11 +1731,14 @@ def accept(self, visitor: NodeVisitor[T]) -> T:

class NewTypeExpr(Expression):
"""NewType expression NewType(...)."""
name = None # type: str
old_type = None # type: mypy.types.Type

info = None # type: Optional[TypeInfo]

def __init__(self, info: Optional['TypeInfo']) -> None:
self.info = info
def __init__(self, name: str, old_type: 'mypy.types.Type', line: int) -> None:
self.name = name
self.old_type = old_type

def accept(self, visitor: NodeVisitor[T]) -> T:
return visitor.visit_newtype_expr(self)
Expand Down
5 changes: 2 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ def process_newtype_declaration(self, s: AssignmentStmt) -> None:
return

old_type = self.check_newtype_args(name, call, s)
call.analyzed = NewTypeExpr(name, old_type, line=call.line)
if old_type is None:
return

Expand All @@ -1360,8 +1361,7 @@ def process_newtype_declaration(self, s: AssignmentStmt) -> None:
return
# TODO: why does NewType work in local scopes despite always being of kind GDEF?
node.kind = GDEF
node.node = newtype_class_info
call.analyzed = NewTypeExpr(newtype_class_info).set_line(call.line)
call.analyzed.info = node.node = newtype_class_info

def analyze_newtype_declaration(self,
s: AssignmentStmt) -> Tuple[Optional[str], Optional[CallExpr]]:
Expand All @@ -1384,7 +1384,6 @@ def analyze_newtype_declaration(self,
# overwritten later with a fully complete NewTypeExpr if there are no other
# errors with the NewType() call.
call = s.rvalue
call.analyzed = NewTypeExpr(None).set_line(call.line)

return name, call

Expand Down
Loading