google / pytype

A static type analyzer for Python code

Home Page:https://google.github.io/pytype

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on @property + @deprecated

JelleZijlstra opened this issue · comments

In python/typeshed#11009, I tried to add the deprecated decorator (PEP 702) to a property:

from typing_extensions import deprecated

class CodeType:
    @property
    @deprecated("message")
    def co_lnotab(self) -> bytes: ...

But pytype crashes with a ParseError (https://github.com/python/typeshed/actions/runs/6839481445/job/18597693717?pr=11009):

pytype.pyi.types.ParseError:   File: "/home/runner/work/typeshed/typeshed/stdlib/types.pyi", line 150
    def co_lnotab(self) -> bytes: ...
   ^
ParseError: Too many decorators for co_lnotab: property, deprecated

Ideally pytype should support @deprecated and emit warnings for deprecated properties, but failing that, it should just ignore the decorator.

It also crashes on __init__ methods where one variant is deprecated (pytype.pytd.codegen.function.OverloadedDecoratorError: Overloaded signatures for __init__ disagree on decorators: https://github.com/python/typeshed/actions/runs/6916103348/job/18815781379?pr=11009).

And on deprecated classmethods (https://github.com/python/typeshed/actions/runs/6916179270/job/18815978232?pr=11009):

pytype.pyi.types.ParseError:   File: "/home/runner/work/typeshed/typeshed/stdlib/datetime.pyi", line 269
    def utcfromtimestamp(cls, __t: float) -> Self: ...
   ^
ParseError: Too many decorators for utcfromtimestamp: classmethod, deprecated

Thanks for the quick fix!