Skip to content

Hopefully fix issues encountered with mypy 1.7.1

Running mypy 1.7.1 with fastenum produced issues. Mypy suggested this might be a bug with mypy itself, with the following error message:

fastenum/fastenum.pyi:8: error: INTERNAL ERROR -- Please try using mypy master on GitHub

However, running mypy with --show-traceback indicated that there was a problem in fastenum/mypy_plugin.py:

mypy --show-traceback --config-file ./mypy.ini --warn-unused-configs --check-untyped-defs --ignore-missing-imports ./my_project/
/home/austinjp/Desktop/my_project/venv-3.11/lib/python3.11/site-packages/fastenum/fastenum.pyi:8: 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: 1.7.1
Traceback (most recent call last):
  File "mypy/semanal.py", line 6525, in accept
  File "mypy/nodes.py", line 785, in accept
  File "mypy/semanal.py", line 832, in visit_func_def
  File "mypy/semanal.py", line 864, in analyze_func_def
  File "mypy/typeanal.py", line 1031, in visit_callable_type
  File "mypy/typeanal.py", line 1684, in anal_type
  File "mypy/types.py", line 949, in accept
  File "mypy/typeanal.py", line 259, in visit_unbound_type
  File "mypy/typeanal.py", line 306, in visit_unbound_type_nonoptional
  File "/home/austinjp/Desktop/my_project/venv-3.11/lib/python3.11/site-packages/fastenum/mypy_plugin.py", line 475, in transform_enum_type
    self_tvar_expr = nodes.TypeVarExpr(
                     ^^^^^^^^^^^^^^^^^^
TypeError: __init__() missing required argument 'default' (pos 5)
/home/austinjp/Desktop/my_project/venv-3.11/lib/python3.11/site-packages/fastenum/fastenum.pyi:8: : note: use --pdb to drop into pdb

After applying the patch in this merge request, mypy completes without issues:

mypy --show-traceback --config-file ./mypy.ini ./my_project/
Success: no issues found in 1 source file

I notice that the CI pipeline here on Gitlab uses mypy version 0.960 and the tests in that pipeline now all fail with the bug mentioned in this merge request.

The contents of my_project/__init__.py in my tests were:

from fastenum import Enum as FEnum

class Something(FEnum):
    x = 1

print(Something.x)

Merge request reports

Loading