dropbox / sqlalchemy-stubs

Mypy plugin and stubs for SQLAlchemy
Apache License 2.0
570 stars 101 forks source link

mypy 0.930 breaks the sqlmypy plugin with an INTERNAL ERROR #232

Closed plankthom closed 2 years ago

plankthom commented 2 years ago

Upgrading to mypy 0.930 triggered the following INTERNAL ERROR issue:

% mypy --config-file pkg/tsa-repo-db-client/setup.cfg -p tsa.repo.db --show-traceback
***/pkg/tsa-repo-db-client/tsa/repo/db/model.py:11: 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://github.com/python/mypy/issues
version: 0.930
Traceback (most recent call last):
  File "mypy/semanal.py", line 5132, in accept
  File "mypy/nodes.py", line 1140, in accept
  File "mypy/semanal.py", line 2110, in visit_assignment_stmt
  File "mypy/semanal.py", line 2392, in apply_dynamic_class_hook
  File "***/miniconda3/envs/tsa37/lib/python3.7/site-packages/sqlmypy.py", line 203, in decl_info_hook
    obj = ctx.api.builtin_type('builtins.object')
AttributeError: 'SemanticAnalyzer' object has no attribute 'builtin_type'
***/pkg/tsa-repo-db-client/tsa/repo/db/model.py:11: : note: use --pdb to drop into pdb

Considering the announcement in https://github.com/python/mypy/issues/6617 , I assume this should be solved here ...

Workaround: keep mypy pinned on version 0.921

plankthom commented 2 years ago

Removal of SemanticAnalyzer.builtin_type : https://github.com/python/mypy/commit/5bd2641ab53d4261b78a5f8f09c8d1e71ed3f14a#diff-6d2a87e2b0fdefc2766ed8e178d16253286bc574ee6798df140f081941bc5746

97littleleaf11 commented 2 years ago

Sorry that I forgot to update the announcement. Currently please use named_type instead.

ilevkivskyi commented 2 years ago

Could someone please submit a PR for this? (using a hasattr() for compatibility) Sorry, but I don't have much time to work on this myself.

JukkaL commented 2 years ago

I should be able to take care of this, but I don't access to the PyPI project.

@ilevkivskyi Could you make me a maintainer at https://pypi.org/project/sqlalchemy-stubs/?

JukkaL commented 2 years ago

Alternatively, I wonder if we could (or should) add back builtin_type as an alias to named_type, but mark it as deprecated.

ilevkivskyi commented 2 years ago

IIUC this should now work with mypy 0.931, so I am closing this issue.

ilevkivskyi commented 2 years ago

Actually, we can still switch to the newer "official" API method, so re-opening again. PRs are welcome :-)

shawnwall commented 2 years ago

@ilevkivskyi would you like to hasattr() on builtin_type in case it goes away again? using hasattr() on named_type doesn't work as named_type DID exist in mypy < .930 but apparently the functionality diffed a bit at that time.

JukkaL commented 2 years ago

I have no plans to remove builtin_type. Keeping it around is not a significant burden.

ilevkivskyi commented 2 years ago

@shawnwall Essentially, yes. We can have this just in case (but since Jukka says it will be there, it is not a priority).