Skip to content
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

Strip type objects when constructing TypeType #2832

Merged
merged 4 commits into from
Mar 29, 2017

Conversation

elazarg
Copy link
Contributor

@elazarg elazarg commented Feb 8, 2017

Fix #2826,

I am not entirely sure this is the right fix, but removing a level of indirection seems reasonable. (I think the right thing, in the long run, is to remove TypeType completely from the system)

There are changes in testtypegen, which I do not completely understand but without which it kept adding IntExpr(1) in the output - presumably from Any.

@gvanrossum
Copy link
Member

The title is somewhat misleading, it doesn't really strip all occurrences CallableType, only those used to represent class objects.

The need to check for builtins.Any is because there's a definition of Any in test-data/unit/lib-stub/builtins.pyi which some tests presumably still rely on. But IMO those tests should be fixed (probably in a separate PR that should go in first).

@elazarg elazarg changed the title Strip CallableExpr when constructing TypeType Strip type objects when constructing TypeType Feb 8, 2017
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

LGTM. Will merge after you rebase and tests pass.

@@ -736,7 +736,7 @@ MypyFile:1(
f
Args(
Var(a))
def (a: builtins.Any) -> builtins.Any
def (a: Any) -> Any
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is new. I'm not comfortable with both the original and the new version.

@gvanrossum
Copy link
Member

I'm guessing those were from #3025, which has since been reverted. Can you do another rebase? Maybe things are simpler then.

@elazarg
Copy link
Contributor Author

elazarg commented Mar 29, 2017

Only the last commit (not shown after the new rebase) was relevant.

@gvanrossum
Copy link
Member

So are you now happy, or do you want to investigate why that test output had to be changed? I have no idea myself.

@elazarg
Copy link
Contributor Author

elazarg commented Mar 29, 2017

This part of the test was added in #2603 two days ago, so I guess it's OK.

@gvanrossum gvanrossum merged commit 3e8a55f into python:master Mar 29, 2017
@gvanrossum
Copy link
Member

Thanks!

@@ -384,6 +384,7 @@ class Instance(Type):

def __init__(self, typ: Optional[mypy.nodes.TypeInfo], args: List[Type],
line: int = -1, column: int = -1, erased: bool = False) -> None:
assert(typ is None or typ.fullname() not in ["builtins.Any", "typing.Any"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is not right -- typ should never be None. What's the purpose of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is None in incremental mode

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I figured that out myself, but my comment was lost somehow. What about builtins.Any and typing.Any? Why are we creating an Instance type that corresponds to Any, and why is there a builtins.Any in addition to typing.Any? Shouldn't we use AnyType?

Copy link
Contributor Author

@elazarg elazarg Mar 30, 2017

Choose a reason for hiding this comment

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

Yes we should, but these somehow got created in the tests. I have avoided this ( or fullname() == 'builtins' above), and added the assertions here to verify this is indeed the case. Perhaps we can remove the tests now.

As Guido said above - or at least as I understand his comment - it will be better not to define Any in builtins fixture at all.

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.

Update the behaviour of the type function for metaclasses
3 participants