DeanWay / fastapi-versioning

api versioning for fastapi web applications
MIT License
644 stars 63 forks source link

:sparkles: Reflect attributes in version decorator #12

Closed HacKanCuBa closed 4 years ago

HacKanCuBa commented 4 years ago

Rewriting the decorator using functools.wraps() allows for tab completion and correctly reflecting of attributes and signature of wrapped function.

Closes #11.

takeda commented 4 years ago

There are two issues with this:

  1. you forgot return wrapper
  2. your PR actually changes behavior of the decorator. After your change the assignment of version happens on every invocation, when previously it only happened once when the function was created.

I believe the original code is actually correct and the autocomplete works. Perhaps the types should be updated to ones suggested here: https://github.com/tiangolo/fastapi/issues/200#issuecomment-525126712 which should work in PyCharm at least.

HacKanCuBa commented 4 years ago

Damn, that's correct! Yeah, probably typing as suggested would work. I'm closing this PR :)

takeda commented 4 years ago

I still think a PR is needed to update types to similar to what was in that comment (which is the recommend way https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#decorators). Right now all it says is that argument and return is a function, which in case of a decorator that's not saying much.

HacKanCuBa commented 4 years ago

I still think a PR is needed to update types to similar to what was in that comment (which is the recommend way https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#decorators). Right now all it says is that argument and return is a function, which in case of a decorator that's not saying much.

Agree, will fix one like that on a different PR