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

AssertionError on version 0.960 #12868

Closed
Apakottur opened this issue May 25, 2022 · 6 comments · Fixed by #12872
Closed

AssertionError on version 0.960 #12868

Apakottur opened this issue May 25, 2022 · 6 comments · Fixed by #12872
Assignees

Comments

@Apakottur
Copy link

Bug Report

We are using the ddtrace Python package.
Consider the following file:

# test.py
import ddtrace

Running mypy test.py passes without issues on version 0.950 but when run on version 0.960 the following is printed:

Traceback (most recent call last):
  File ".../bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File ".../python3.10/site-packages/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 96, in main
  File "mypy/main.py", line 173, in run_build
  File "mypy/build.py", line 154, in build
  File "mypy/build.py", line 230, in _build
  File "mypy/build.py", line 2729, in dispatch
  File "mypy/build.py", line 3087, in process_graph
  File "mypy/build.py", line 3179, in process_stale_scc
  File "mypy/semanal_main.py", line 88, in semantic_analysis_for_scc
  File "mypy/semanal_main.py", line 414, in apply_class_plugin_hooks
  File "mypy/semanal_main.py", line 434, in apply_hooks_to_class
  File "mypy/plugins/attrs.py", line 309, in attr_class_maker_callback
  File "mypy/plugins/attrs.py", line 372, in _analyze_class
  File "mypy/plugins/attrs.py", line 498, in _attributes_from_assignment
  File "mypy/plugins/attrs.py", line 594, in _attribute_from_attrib_maker
  File "mypy/semanal.py", line 5450, in anal_type
  File "mypy/types.py", line 765, in accept
  File "mypy/typeanal.py", line 172, in visit_unbound_type
  File "mypy/typeanal.py", line 263, in visit_unbound_type_nonoptional
  File "mypy/typeanal.py", line 1168, in anal_array
  File "mypy/typeanal.py", line 1177, in anal_type
  File "mypy/types.py", line 765, in accept
  File "mypy/typeanal.py", line 172, in visit_unbound_type
  File "mypy/typeanal.py", line 180, in visit_unbound_type_nonoptional
  File "mypy/semanal.py", line 4563, in lookup_qualified
  File "mypy/semanal.py", line 4458, in lookup
  File "mypy/semanal.py", line 4508, in is_active_symbol_in_class_body
AssertionError

I tried using the --pdb and --tb flags to get the traceback, or see which part of the library is causing this but was unable to do so.
I tried clearing the mypy cache, which didn't help as well.

Is this an issue with mypy, the library or both?

Your Environment

  • Mypy version used: 0.960
  • Python version used: 3.10
  • Operating system and version: Ubuntu 22.04
@Apakottur Apakottur added the bug mypy got something wrong label May 25, 2022
@AlexWaygood AlexWaygood added crash topic-attrs and removed bug mypy got something wrong labels May 25, 2022
@AlexWaygood
Copy link
Member

Thanks for the report! I can reproduce this on the master branch, if I create a new virtual environment with just mypy's dependencies and ddtrace installed, and then run mypy on a file that only has import ddtrace inside it.

The crash bisects to 50a653e (PR #12772). Cc. @JukkaL.

@P403n1x87
Copy link

I don't know if this could be related, but there seems to be issues with how dataclasses are handled too:

https://github.com/DataDog/riot/runs/6594827098?check_suite_focus=true

The logs show that the latest version of mypy has started complaining about attributes that are defined on the dataclass

https://github.com/DataDog/riot/blob/2f6ea2e7a128239c45d4771245f572095651436e/riot/riot.py#L177-L231

@gitpushdashf
Copy link

Thanks for reporting this! Getting this as well.

@JukkaL
Copy link
Collaborator

JukkaL commented May 26, 2022

Here is a small reproducer for the attrs crash:

import attr

@attr.s
class C:
    @attr.s
    class D:
        pass
    x = attr.ib(type=list[D])

As a workaround, moving the nested class to the module top level should fix the crash. I'm working on a fix.

@JukkaL
Copy link
Collaborator

JukkaL commented May 26, 2022

@P403n1x87 That's a separate issue, and it looks like it's related to #12798. Here's a skeleton of a workaround for the issue:

from dataclasses import dataclass, InitVar, field

@dataclass
class D:
    _x: InitVar[int]
    x: str = field(init=False)

    def __post_init__(self, _x: int) -> None:
        self.x = str(_x)

Feel free to create a separate issue if this isn't sufficient to resolve your issue.

JukkaL added a commit that referenced this issue May 26, 2022
@P403n1x87
Copy link

@JukkaL ah this makes a lot of sense, thanks! I guess this is an actual improvement from mypy that has just highlighted a misuse of InitVar from our side!

JukkaL added a commit that referenced this issue May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants