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

Mypy v0.910 crash in stdlib typeshed with file named typing.py under a websockets directory #10722

Closed
LefterisJP opened this issue Jun 26, 2021 · 2 comments
Labels

Comments

@LefterisJP
Copy link
Contributor

LefterisJP commented Jun 26, 2021

Crash Report

I am using v0.910 and suddenly for my local changes to our project mypy fails with a crash report.

Traceback

I followed the guide to run mypy from source after I saw the crash. So this traceback is with mypy-0.920+dev.3dcccf221ead4b3143208fc2a1631336d6186e4

/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeshed/stdlib/_typeshed/__init__.pyi:62: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https:/python/mypy/issues
version: 0.920+dev.3dcccf221ead4b3143208fc2a1631336d6186e45
Dropping into pdb
[14] > /home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py(4293)lookup_fully_qualified()
-> return n.names[parts[-1]]
(Pdb++) c
Traceback (most recent call last):
  File "/home/lefteris/.virtualenvs/rotkipy37/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/main.py", line 87, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/main.py", line 165, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/build.py", line 180, in build
    sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr, extra_plugins
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/build.py", line 254, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/build.py", line 2697, in dispatch
    process_graph(graph, manager)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/build.py", line 3021, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/build.py", line 3113, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal_main.py", line 78, in semantic_analysis_for_scc
    process_top_levels(graph, scc, patches)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal_main.py", line 203, in process_top_levels
    patches)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal_main.py", line 331, in semantic_analyze_target
    active_type=active_type)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py", line 398, in refresh_partial
    self.refresh_top_level(node)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py", line 409, in refresh_top_level
    self.accept(d)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py", line 4894, in accept
    node.accept(self)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/nodes.py", line 1075, in accept
    return visitor.visit_assignment_stmt(self)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py", line 1998, in visit_assignment_stmt
    if self.check_and_set_up_type_alias(s):
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py", line 2584, in check_and_set_up_type_alias
    self.analyze_alias(rvalue, allow_placeholder=True)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py", line 2504, in analyze_alias
    global_scope=global_scope)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 92, in analyze_type_alias
    res = type.accept(analyzer)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/types.py", line 503, in accept
    return visitor.visit_unbound_type(self)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 163, in visit_unbound_type
    typ = self.visit_unbound_type_nonoptional(t, defining_literal)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 227, in visit_unbound_type_nonoptional
    special = self.try_analyze_special_unbound_type(t, fullname)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 344, in try_analyze_special_unbound_type
    return self.analyze_literal_type(t)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 800, in analyze_literal_type
    analyzed_types = self.analyze_literal_param(i + 1, arg, t)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 860, in analyze_literal_param
    fallback = self.named_type_with_normalized_str(arg.base_type_name)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 995, in named_type_with_normalized_str
    return self.named_type(fully_qualified_name)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeanal.py", line 1001, in named_type
    node = self.lookup_fqn_func(fully_qualified_name)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/semanal.py", line 4293, in lookup_fully_qualified
    return n.names[parts[-1]]
KeyError: 'str'
/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/mypy/typeshed/stdlib/_typeshed/__init__.pyi:62: : note: use --pdb to drop into pdb

To Reproduce

I opened a PR with my changes that reproduced the problem here: rotki/rotki#3124. It's a work in progress as far as the actual change in our project is concerned but the crash is reproducible there. Commit with hash f088361 should be used.

This is how we run mypy in our project:

mypy rotkehlchen/ tools/data_faker --install-types --show-traceback --pdb

This will eventually lead to the crash.

But I find mypy fascinating and experimented a bit more to see if I could narrow it down, and I did narrow it down to this file:

mypy rotkehlchen/api/websockets/typing.py --install-types --show-traceback --pdb

The file is super simple.

from enum import Enum


class WSMessageType(Enum):
    LEGACY = 1

    def __str__(self) -> str:
        return self.name.lower()

I don't know much about the mypy core code but poking around with pdb it seems that the builtins do not contain str in a mapping while it contains a lot of other primitives.

This lead me to think that perhaps the name of the file typing.py could cause a problem since it's the same as the typing module and indeed voila. If I change the name to typorz.py the error is no longer happening. Also if I keep it typing.py and move it somewhere else and not under websockets directory then again the error is no longer happening.

I don't know exactly what this means for how it's handled in the code but hope this is enough of a hint to guide you guys in the right direction.

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: mypy rotkehlchen/api/websockets/typing.py --install-types --show-traceback --pdb
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
# Docs: https://mypy.readthedocs.io/en/latest/config_file.html
ignore_missing_imports = True
check_untyped_defs = True
disallow_untyped_defs = True
warn_unused_configs = True
warn_unused_ignores = True
warn_unreachable = True
warn_redundant_casts = True
disallow_untyped_decorators = True
disallow_untyped_calls = True
mypy_path=./stubs/

# -- These modules still need to have proper type definitions given --
[mypy-rotkehlchen.tests.*]
check_untyped_defs = False
disallow_untyped_defs = False
# Pytest's fixture decorators are not typed
disallow_untyped_decorators = False

# Data faker is a WIP so skip strict type checks
[mypy-data_faker.*]
check_untyped_defs = False
disallow_untyped_defs = False

# custom pylint checkers still need to be typed
[mypy-tools.pylint.*]
check_untyped_defs = False
disallow_untyped_defs = False
  • Python version used: 3.7.9
  • Operating system and version: Linux 5.12.13-arch1-1 SMP PREEMPT Wed, 23 Jun 2021 16:19:29 +0000 x86_64 GNU/Linux
@hauntsaninja
Copy link
Collaborator

Hmm, I think someone ran into this before, let me look... yeah, #1876 (comment)

@hauntsaninja
Copy link
Collaborator

Duplicate of #1876

@hauntsaninja hauntsaninja marked this as a duplicate of #1876 Jul 8, 2022
@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants