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

AttributeError: attribute 'TypeInfo' of '_fullname' undefined #13099

Closed
copperfield42 opened this issue Jul 9, 2022 · 2 comments
Closed

AttributeError: attribute 'TypeInfo' of '_fullname' undefined #13099

copperfield42 opened this issue Jul 9, 2022 · 2 comments
Labels

Comments

@copperfield42
Copy link

Crash Report

I was putting type hint to a decorator like so (P is a ParamSpec and T is a TypeVar)

from my_typing import Callable, Iterator, P, T, PathType

def chdir_decorator(folder:PathType) -> Callable[[Callable[P, T]], Callable[P, T]]:
    def decorator(func:Callable[P,T]) -> Callable[P,T]:
        @wraps(func)
        def wrapper(*args:P.args,**kwarg:P.kwargs) -> T:
            with chdir(folder):
                return func(*args,**kwarg)
        return wrapper
    return decorator


and I got this error

Traceback (most recent call last):
  File "C:\Python3.10.5\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python3.10.5\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python3.10.5\Scripts\mypy.exe\__main__.py", line 7, in <module>
  File "C:\Python3.10.5\lib\site-packages\mypy\__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy\main.py", line 96, in main
  File "mypy\main.py", line 173, in run_build
  File "mypy\build.py", line 154, in build
  File "mypy\build.py", line 230, in _build
  File "mypy\build.py", line 2729, in dispatch
  File "mypy\build.py", line 3087, in process_graph
  File "mypy\build.py", line 3205, in process_stale_scc
  File "mypy\build.py", line 2313, in write_cache
  File "mypy\build.py", line 1470, in write_cache
  File "mypy\nodes.py", line 352, in serialize
  File "mypy\nodes.py", line 3435, in serialize
  File "mypy\nodes.py", line 3372, in serialize
  File "mypy\nodes.py", line 761, in serialize
  File "mypy\types.py", line 1797, in serialize
  File "mypy\types.py", line 1801, in serialize
  File "mypy\types.py", line 647, in serialize
  File "mypy\types.py", line 1190, in serialize
  File "mypy\nodes.py", line 2742, in fullname
AttributeError: attribute 'TypeInfo' of '_fullname' undefined
(Insert traceback and other messages from mypy here -- use `--show-traceback`.)

To Reproduce

I included the full files decorated.zip (my_typing.py and my_module.py) because if I try to reduce to it more simple version or put everything in same file the problem disappear so maybe is some weird interaction there with my_typing...

my_typing use the following other modules numerary 0.4.2 and typing extensions 4.3.0.

I have been using my_typing without any issue thus far.

Of notice is that if I remove the return type hint from chdir_decorator it passes the the mypy check but with it crash for no apparent reason.

Your Environment

  • Mypy version used: mypy 0.961 (compiled: yes)
  • Mypy command-line flags: mypy my_module.py
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.10.5
  • Operating system and version: windows 10
@copperfield42
Copy link
Author

I manage to reduce to a minimum necessary

#my_typing_simple.py
from typing import TypeVar, ParamSpec, Callable

T = TypeVar('T')
P = ParamSpec('P')

and in another module fail.py:

"failing module"
from my_typing_simple import Callable, P, T

def my_decorator(folder:str) -> Callable[[Callable[P, T]], Callable[P, T]]:
    def decorator(func:Callable[P,T]) -> Callable[P,T]:
        def wrapper(*args:P.args,**kwarg:P.kwargs) -> T:
            print("wrapper")
            return func(*args,**kwarg)
        return wrapper
    return decorator

this one is very weird because seemingly insignificant changes result in the error or not, if I delete the mypy cache and open a new console and test it pass, but if I just add an empty line between the doc string and the imports and test again I get the error

"failling module"

from my_typing_simple import Callable, P, T

def my_decorator(folder:str) -> Callable[[Callable[P, T]], Callable[P, T]]:
    def decorator(func:Callable[P,T]) -> Callable[P,T]:
        def wrapper(*args:P.args,**kwarg:P.kwargs) -> T:
            print("wrapper")
            return func(*args,**kwarg)
        return wrapper
    return decorator

Error

C:\Users\copperfield\Desktop\mypy_tests\paramspec bug>mypy fail.py
Traceback (most recent call last):
  File "C:\Python3.10.5\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python3.10.5\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python3.10.5\Scripts\mypy.exe\__main__.py", line 7, in <module>
  File "C:\Python3.10.5\lib\site-packages\mypy\__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy\main.py", line 96, in main
  File "mypy\main.py", line 173, in run_build
  File "mypy\build.py", line 154, in build
  File "mypy\build.py", line 230, in _build
  File "mypy\build.py", line 2729, in dispatch
  File "mypy\build.py", line 3087, in process_graph
  File "mypy\build.py", line 3205, in process_stale_scc
  File "mypy\build.py", line 2313, in write_cache
  File "mypy\build.py", line 1470, in write_cache
  File "mypy\nodes.py", line 352, in serialize
  File "mypy\nodes.py", line 3435, in serialize
  File "mypy\nodes.py", line 3372, in serialize
  File "mypy\nodes.py", line 761, in serialize
  File "mypy\types.py", line 1797, in serialize
  File "mypy\types.py", line 1801, in serialize
  File "mypy\types.py", line 647, in serialize
  File "mypy\types.py", line 1190, in serialize
  File "mypy\nodes.py", line 2742, in fullname
AttributeError: attribute 'TypeInfo' of '_fullname' undefined

meanwhile doing it like this

from my_typing_simple import Callable, ParamSpec, T
P = ParamSpec("P")

def my_decorator(folder:str) -> Callable[[Callable[P, T]], Callable[P, T]]:
    def decorator(func:Callable[P,T]) -> Callable[P,T]:
        def wrapper(*args:P.args,**kwarg:P.kwargs) -> T:
            print("wrapper")
            return func(*args,**kwarg)
        return wrapper
    return decorator

everything is ok

@ethanhs
Copy link
Collaborator

ethanhs commented Jul 10, 2022

Thank you for finding a minimal reproducer! This is a duplicate of #12475 but I will repost your reproducer over there.

@ethanhs ethanhs closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants