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

TypeError: format_type() missing 1 required positional argument: 'options' #15599

Closed
hofrob opened this issue Jul 5, 2023 · 2 comments
Closed
Labels

Comments

@hofrob
Copy link

hofrob commented Jul 5, 2023

Crash Report

Running mypy on a file with a very basic sqlalchemy ORM model raises this error.

Traceback

version: 1.5.0+dev.c13f1d416e907f58bc77d086b84819f500f1bde9
Traceback (most recent call last):
  File "/path/to/project/venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/main.py", line 94, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/main.py", line 173, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/build.py", line 195, in build
    result = _build(
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/build.py", line 268, in _build
    graph = dispatch(sources, manager, stdout)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/build.py", line 2927, in dispatch
    process_graph(graph, manager)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/build.py", line 3325, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/build.py", line 3420, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal_main.py", line 93, in semantic_analysis_for_scc
    process_top_levels(graph, scc, patches)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal_main.py", line 220, in process_top_levels
    deferred, incomplete, progress = semantic_analyze_target(
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal_main.py", line 349, in semantic_analyze_target
    analyzer.refresh_partial(
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal.py", line 600, in refresh_partial
    self.refresh_top_level(node)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal.py", line 611, in refresh_top_level
    self.accept(d)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal.py", line 6475, in accept
    node.accept(self)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/nodes.py", line 1141, in accept
    return visitor.visit_class_def(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal.py", line 1600, in visit_class_def
    self.analyze_class(defn)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal.py", line 1685, in analyze_class
    self.analyze_class_body_common(defn)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal.py", line 1714, in analyze_class_body_common
    self.apply_class_plugin_hooks(defn)
  File "/path/to/project/venv/lib/python3.11/site-packages/mypy/semanal.py", line 1801, in apply_class_plugin_hooks
    hook(ClassDefContext(defn, base_expr, self))
  File "/path/to/project/venv/lib/python3.11/site-packages/sqlalchemy/ext/mypy/plugin.py", line 261, in _base_cls_hook
    decl_class.scan_declarative_assignments_and_apply_types(ctx.cls, ctx.api)
  File "/path/to/project/venv/lib/python3.11/site-packages/sqlalchemy/ext/mypy/decl_class.py", line 96, in scan_declarative_assignments_and_apply_types
    _scan_declarative_assignment_stmt(
  File "/path/to/project/venv/lib/python3.11/site-packages/sqlalchemy/ext/mypy/decl_class.py", line 459, in _scan_declarative_assignment_stmt
    python_type_for_type = infer.infer_type_from_right_hand_nameexpr(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/project/venv/lib/python3.11/site-packages/sqlalchemy/ext/mypy/infer.py", line 52, in infer_type_from_right_hand_nameexpr
    python_type_for_type = _infer_type_from_decl_column(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/project/venv/lib/python3.11/site-packages/sqlalchemy/ext/mypy/infer.py", line 410, in _infer_type_from_decl_column
    return _infer_type_from_left_and_inferred_right(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/project/venv/lib/python3.11/site-packages/sqlalchemy/ext/mypy/infer.py", line 457, in _infer_type_from_left_and_inferred_right
    format_type(orig_left_hand_type),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: format_type() missing 1 required positional argument: 'options'

To Reproduce

import enum

import sqlalchemy
from sqlalchemy import orm

Base = orm.declarative_base()


class BlaEnum(enum.Enum):
    SOMETHING = enum.auto()


class Model(Base):
    ...


class Bar(Model):
    size: BlaEnum = sqlalchemy.Column(sqlalchemy.Text)

requirements.txt

mypy==1.4.1
mypy-extensions==1.0.0
sqlalchemy[mypy]==1.4.48
sqlalchemy2-stubs==0.0.2a34
types-sqlalchemy==1.4.53.38
types-sqlalchemy-utils==1.0.1
typing-extensions==4.6.3

This is a condensed minimal reproducible example. In short, Model is my abstract base model for all ORM classes. Bar is an ORM model that has an enum property. Declaring the column as enum would be correct, but it's not necessary to trigger the bug.

Your Environment

  • Mypy version used: 1.5.0+dev.c13f1d416e907f58bc77d086b84819f500f1bde9
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
plugins = ["sqlalchemy.ext.mypy.plugin"]
  • Python version used: 3.11.3
  • Operating system and version: Ubuntu 22.04 LTS
@hofrob hofrob added the crash label Jul 5, 2023
@JelleZijlstra
Copy link
Member

This is a bug in the SQLAlchemy mypy plugin. Please report it to SQLAlchemy, not here.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
@AlexWaygood
Copy link
Member

If the bug still exists in the latest version of the sqlalchemy mypy plugin, it indicates that they need to update the plugin following #6617 (comment)

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

3 participants