Skip to content

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

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

Closed
Athazo opened this issue May 16, 2019 · 1 comment

Comments

@Athazo
Copy link

Athazo commented May 16, 2019

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.

@Athazo Athazo changed the title Error "Cannot determine type of ..." of property Error "Cannot determine type of ..." of instance attribute with isinstance() check May 17, 2019
@ilevkivskyi
Copy link
Member

Hm, this is pretty bad. The problem is that mypy believes that int and numbers.Integral are non-overlapping, so the branch is unreachable. So essentially this is a duplicate of #3603 (already high priority).

See also #2636 for the discussion about numeric tower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants