Pycharm warns about Unexpected type in a SqlAlchemy model

Viewed 4410

In a SqlAlchemy model I am getting a warning from pycharm saying that a column has an unexpected type.

The simplified code that produces the warning is as follows:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String

Base = declarative_base()

class Peptide(Base):
    __tablename__ = 'peptides'

    sequence = Column(String, primary_key=True)
    scan = Column(Integer)

    def __init__(self, scan, sequence):
        self.scan = scan
        self.sequence = sequence

    def __repr__(self):
        return '<Peptide "%s" Scan %i>' % (self.sequence, self.scan)

The warning is given for self.scan in the __repr__ method. If I change the format string to:

  return '<Peptide "%s" Scan %s>' % (self.sequence, self.scan)

the warning goes away. But in fact self.scan has been defined as an integer in the model, not a string. Surprisingly the following string does not produce any warning:

  return '<Scan %i>' % self.scan

Is this an overreaction of the pycharm checker or it is something related to SqlAlchemy types?

1 Answers
Related