Skip to content

Error "Cannot determine type of ..." of instance attribute with isinstance() check #6846

Closed
@Athazo

Description

@Athazo

This is my very first time opening an Issue on GitHub, so don't be too harsh if I'm doing it wrong since I'm not really used to the conventions here ;)

  • Are you reporting a bug, or opening a feature request?
    Bug

  • Please insert below the code you are checking with mypy

import numbers

class Foo():
    def __init__(self, x: int) -> None:
      self.x = x

    @property
    def x(self) -> int:
        return self._x

    @x.setter
    def x(self, value: int) -> None:
        if value >= 0 and isinstance(value, numbers.Integral):
            self._x = value

Edit: Simpler example, removed the property, still getting the same error:

import numbers

class Foo():
  def __init__(self, x: int) -> None:
    if x >= 0 and isinstance(x, numbers.Integral):
      self.x = x
  • What is the actual behavior/output?
    Output: mypy_test.py:12: error: Cannot determine type of '_x'
    Everything works fine, if isinstance(value, numbers.Integral) is removed.

  • What is the behavior/output you expect?
    No error

  • What are the versions of mypy and Python you are using?
    mypy 0.701
    Python 3.7.2

  • What are the mypy flags you are using? (For example --strict-optional)
    No flags at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions