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

bug: Decorated property not supported #6384

Closed
thomedes opened this issue Feb 13, 2019 · 7 comments
Closed

bug: Decorated property not supported #6384

thomedes opened this issue Feb 13, 2019 · 7 comments

Comments

@thomedes
Copy link

When running mypy on a file with the following content:

class Foo:
    @property
    def bar(self):
        return 'baz'

    def bar(self):
        return 'baz'

It will crash with following traceback:

non-method-property.py:6: error: Decorated property not supported
non-method-property.py:2: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.680+dev.2ef066fa651ac048d220c751a4f7554b949a2c13
Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 11, in <module>
    load_entry_point('mypy==0.680+dev.2ef066fa651ac048d220c751a4f7554b949a2c13', 'console_scripts', 'mypy')()
  File "/usr/local/lib/python3.6/dist-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/usr/local/lib/python3.6/dist-packages/mypy/main.py", line 91, in main
    res = build.build(sources, options, None, flush_errors, fscache)
  File "/usr/local/lib/python3.6/dist-packages/mypy/build.py", line 162, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/usr/local/lib/python3.6/dist-packages/mypy/build.py", line 217, in _build
    graph = dispatch(sources, manager)
  File "/usr/local/lib/python3.6/dist-packages/mypy/build.py", line 2388, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.6/dist-packages/mypy/build.py", line 2693, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/usr/local/lib/python3.6/dist-packages/mypy/build.py", line 2800, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/usr/local/lib/python3.6/dist-packages/mypy/build.py", line 1947, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 282, in check_first_pass
    self.accept(d)
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.6/dist-packages/mypy/nodes.py", line 846, in accept
    return visitor.visit_class_def(self)
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 1535, in visit_class_def
    self.accept(defn.defs)
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.6/dist-packages/mypy/nodes.py", line 911, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 1701, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.6/dist-packages/mypy/nodes.py", line 454, in accept
    return visitor.visit_overloaded_func_def(self)
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 426, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn)
  File "/usr/local/lib/python3.6/dist-packages/mypy/checker.py", line 441, in _visit_overloaded_func_def
    assert isinstance(fdef, Decorator)
AssertionError: 
non-method-property.py:2: : note: use --pdb to drop into pdb

I expected mypy to simply signal an error about reusing a method/property name.

Happening on both Ubuntu 18.04.1 LTS's apt install version and on latest version installed from GitHub. Python 3.6.7

@thomedes thomedes changed the title non-method-property bug: Decorated property not supported Feb 13, 2019
@tirkarthi
Copy link
Member

Related : #5561 and #1362

@ilevkivskyi
Copy link
Member

Yes, we should just report an error instead of crashing.

@TH3CHARLie
Copy link
Collaborator

This crash no more occurs in master. Output:

test.py:2: error: Single overload definition, multiple required
test.py:6: error: Unexpected definition for property "bar"

@JelleZijlstra
Copy link
Member

Seems like this issue can be closed then? Those errors look correct.

@TH3CHARLie
Copy link
Collaborator

TH3CHARLie commented Jan 19, 2020

Seems like this issue can be closed then? Those errors look correct.

I think it's OK to do so.

@frispete
Copy link

Yes, we should just report an error instead of crashing.

Hmm, so it is an error to use decorators with mypy?

The offending code for my case:

@functools.total_ordering
class ClassName:
    def __init__(self):
        """whatever"""

    @property
    @functools.lru_cache()
    def method(self):
         """expensive operation, that should show as property"""

@JelleZijlstra
Copy link
Member

@frispete mypy supports decorators in general, but there may be specific patterns that aren't supported. This issue is about a specific problem that led to a crash (not just a mypy error), which is fixed; if you have a different problem involving decorators, feel free to open a new issue.

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

No branches or pull requests

6 participants