Skip to content

Turn on strict optional in CI #3646

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 9 commits into from
Jul 4, 2017

Conversation

ilevkivskyi
Copy link
Member

Now --strict-optional can be turned on/off per file.
This PR turns on strict optional self-test for most files (there are still 16 files that are skipped, I will clean-up them in subsequent PRs).

There is an observation:

class C:
    fullname = None  # type: str

is allowed even with --strict-optional. I understand this is because of limitations of the type comment syntax, but this leads to some hard to find bugs. It would be great to be able to catch this somehow.

@ilevkivskyi
Copy link
Member Author

Travis failure is just #3543

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for continuing to work towards making mypy strict-optional clean! Looks good, just a few minor things.

mypy/typeanal.py Outdated
@@ -522,8 +523,8 @@ def bind_function_type_variables(self,
self.fail("Type variable '{}' is bound by an outer class".format(name), defn)
self.tvar_scope.bind(name, tvar)
binding = self.tvar_scope.get_binding(tvar.fullname())
assert binding is not None
defs.append(binding)
if binding is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes semantics. Are you sure that the change is safe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry, this is a leftover from debugging the fullname problem, this change is not needed. Fixed.

@@ -252,7 +252,7 @@ MypyFile:1(
IntExpr(1))
AssignmentStmt:3(
NameExpr(y* [m])
NameExpr(x [m]))))
NameExpr(x [__main__.A.x]))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has the test output changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because of the mentioned change in semanal.py. Previously fullname was None in these examples, so that they were formatted in simplified manner, now they show their fullnames.

@@ -68,6 +68,7 @@ def bind(self, name: str, tvar_expr: TypeVarExpr) -> TypeVarDef:

def get_binding(self, item: Union[str, SymbolTableNode]) -> Optional[TypeVarDef]:
fullname = item.fullname if isinstance(item, SymbolTableNode) else item
assert fullname is not None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this might have been successful even if fullname or item is None, but apparently the original intention was that fullname should be defined here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have added a line in semanal.analyze_lvalue, so that class members (i.e. MDEF nodes) always get their fullname generated (I don't know why it was not like this before, maybe just an omission). Now this should never be None.

@ilevkivskyi
Copy link
Member Author

@JukkaL Thanks for review! I fixed the accidental change in the new commit.

@JukkaL JukkaL merged commit 28abad1 into python:master Jul 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants