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

cast gives cryptic error: Invalid type "self" #6862

Closed
trickeydan opened this issue May 18, 2019 · 2 comments
Closed

cast gives cryptic error: Invalid type "self" #6862

trickeydan opened this issue May 18, 2019 · 2 comments

Comments

@trickeydan
Copy link

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

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

from typing import *

Integer = NewType("Integer", int)

class Foo:

    _bar: Integer

    def __init__(self, val: int) -> None:
        self._val = val
        self._bar = cast(self._val, self._bar)
  • What is the actual behavior/output?
    type.py:11: error: Invalid type "self"
  • What is the behavior/output you expect?
    An error message that explains that you cannot cast to an instance of a type.
  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
    mypy 0.701
    python 3.7.3
  • What are the mypy flags you are using? (For example --strict-optional)
    mypy.ini is as follows.
[mypy]
mypy_path = stubs

warn_unused_ignores = True
warn_return_any = True

strict_optional = True
no_implicit_optional = True

disallow_any_unimported = True
#disallow_any_expr = True
#disallow_any_decorated = True
disallow_any_explicit = True
disallow_subclassing_any = True
disallow_any_generics = True

disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True

check_untyped_defs = True
@gvanrossum
Copy link
Member

I wonder if using ‘self.something’ in other places that need a type give the same error.

@ilevkivskyi
Copy link
Member

This is a duplicate of a more general issue #4030. I prefer to track this in "centralized" way, so closing this one.

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

3 participants