Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

repr patching broken by pep 563 #270

Closed
tacaswell opened this issue Dec 29, 2020 · 3 comments
Closed

repr patching broken by pep 563 #270

tacaswell opened this issue Dec 29, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@tacaswell
Copy link

Due to https://www.python.org/dev/peps/pep-0563/ delaying the evaluation of annotations until

~/.virtualenvs/bleeding/lib/python3.10/site-packages/ghapi/all.py in <module>
----> 1 from .core import *
      2 from .actions import *
      3 from .auth import *

~/.virtualenvs/bleeding/lib/python3.10/site-packages/ghapi/core.py in <module>
      3 __all__ = ['GH_HOST', 'GhApi', 'date2gh', 'gh2date', 'print_summary', 'EMPTY_TREE_SHA']
      5 # Cell
----> 6 from fastcore.utils import *
      7 from fastcore.foundation import *
      8 from fastcore.meta import *

~/.virtualenvs/bleeding/lib/python3.10/site-packages/fastcore/utils.py in <module>
      2 from .test import *
      3 from .basics import *
----> 4 from .xtras import *
      5 from .parallel import *
      6 from .net import *

~/.virtualenvs/bleeding/lib/python3.10/site-packages/fastcore/xtras.py in <module>
     50 @patch
---> 51 def __repr__(self:AttrDict): return repr_dict(self)

~/.virtualenvs/bleeding/lib/python3.10/site-packages/fastcore/basics.py in patch(f, as_prop, cls_method)
    773 if f is None: return partial(patch, as_prop=as_prop, cls_method=cls_method)
    774 cls = next(iter(f.__annotations__.values()))
--> 775 return patch_to(cls, as_prop=as_prop, cls_method=cls_method)(f)

~/.virtualenvs/bleeding/lib/python3.10/site-packages/fastcore/basics.py in patch_to.<locals>._inner(f)
    759 # `functools.update_wrapper` when passing patched function to `Pipeline`, so we do it manually
    760 for o in functools.WRAPPER_ASSIGNMENTS: setattr(nf, o, getattr(f,o))
--> 761 nf.__qualname__ = f"{c_.__name__}.{nm}"
    762 if cls_method:
    763     setattr(c_, nm, MethodType(nf, c_))

AttributeError: 'str' object has no attribute '__name__'

In [70]: %debug
> /home/tcaswell/.virtualenvs/bleeding/lib/python3.10/site-packages/fastcore/basics.py(761)_inner()
    759             # `functools.update_wrapper` when passing patched function to `Pipeline`, so we do it manually
    760             for o in functools.WRAPPER_ASSIGNMENTS: setattr(nf, o, getattr(f,o))
--> 761             nf.__qualname__ = f"{c_.__name__}.{nm}"
    762             if cls_method:
    763                 setattr(c_, nm, MethodType(nf, c_))

ipdb> p c_
'AttrDict'
ipdb> 

It looks like switching from obj.__annotations__ to typing.get_type_hints(obj) should be enough?

@jph00
Copy link
Contributor

jph00 commented Jan 2, 2021

typing.get_type_hints doesn't do quite the same thing, and I'd rather avoid importing typing if possible. Any other suggestions?

@tacaswell
Copy link
Author

I've more-or-less abandoned any work I was doing that uses fastai so I am unlikely to put any work into this issue.

@jph00
Copy link
Contributor

jph00 commented Jan 22, 2021

Thanks for the update.

@jph00 jph00 added the bug Something isn't working label Jan 22, 2021
@jph00 jph00 closed this as completed Jul 7, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants