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

Type alias problems with typeshed's bytes #2386

Closed
elazarg opened this issue Nov 1, 2016 · 3 comments
Closed

Type alias problems with typeshed's bytes #2386

elazarg opened this issue Nov 1, 2016 · 3 comments

Comments

@elazarg
Copy link
Contributor

elazarg commented Nov 1, 2016

Running mypy on typeshed's stdlib/2/builtins.pyi violates the assertion in semanal.py:931 - sym.node is a Var instead of a TypeInfo for builtins.bytes. This is related to the statement bytes = str and type promotion of str to bytes.

  ...
  File ".../mypy/mypy/build.py", line 1425, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options)
  File ".../mypy/mypy/semanal.py", line 246, in visit_file
    self.accept(d)
  File ".../mypy/mypy/semanal.py", line 2719, in accept
    node.accept(self)
  File ".../mypy/mypy/nodes.py", line 709, in accept
    return visitor.visit_class_def(self)
  File ".../mypy/mypy/semanal.py", line 579, in visit_class_def
    self.setup_type_promotion(defn)
  File ".../mypy/mypy/semanal.py", line 663, in setup_type_promotion
    promote_target = self.named_type_or_none(promotions[defn.fullname])
  File ".../mypy/mypy/semanal.py", line 931, in named_type_or_none
    assert isinstance(sym.node, TypeInfo)
@gvanrossum gvanrossum added this to the Future milestone Nov 1, 2016
@gvanrossum
Copy link
Member

For those trying to repro, the command line is mypy typeshed/stdlib/2/builtins.pyi. So that's using Python 3 mode for the Python 2 builtins stub. It may well conflict with the Python 3 builtins stub that it has already loaded. So I think this is low priority.

@gvanrossum
Copy link
Member

Also the error claims to be on line 370 in builtins.pyi. That line says

class bytearray(MutableSequence[int]):

@ethanhs
Copy link
Collaborator

ethanhs commented Aug 27, 2017

This seems to not cause a crash on 0.521 and master. On both I get

$ mypy typeshed/stdlib/2/builtins.pyi
typeshed\stdlib\2\builtins.pyi: error: Name '__builtins__.str' is not defined
typeshed\stdlib\2\builtins.pyi:1: error: Name '__builtin__' is not defined

This is the expected output as Python 3 has no __builtin__.

@ethanhs ethanhs closed this as completed Aug 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants