Uh oh!
There was an error while loading. Please reload this page.
Annotate few functions and methods - #705
Conversation
1a00c66 to
b9226ffComparetakeda
commented
Nov 10, 2021
@csmarchbanks is there a chance to get this merged? Should I update this patch to resolve current conflicts? |
csmarchbanks
commented
Nov 10, 2021
takeda
commented
Nov 11, 2021
Yeah, that's fine. |
takeda
commented
Nov 29, 2021
@csmarchbanks I rebased my code and adapted it to use annotations as 3.6+ is now required. I currently added types that my code is utilizing. This can be used to show how to add types to other parts of the project. BTW: since types are not used when the code is run and adding typing involves time, the types could be added incrementally over time. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
csmarchbanks
left a comment
There was a problem hiding this comment.
One small comment that I missed the first time around, otherwise 👍. Thanks!
| import operator | ||
| import re | ||
| import sys | ||
| from typing import Any, Callable, TypeVar |
There was a problem hiding this comment.
This file is actually a copy of http://pypi.python.org/pypi/decorator, you can see the file header for more details. That does mean we should not edit it so as to make future upgrades easier.
There was a problem hiding this comment.
I removed it, but out of curiosity. Why is this needed and why contextmanager is used?
For example:
classExceptionCounter:
def__init__(self, counter: "Counter", exception: Type[BaseException]) ->None:
self._counter=counterself._exception=exceptiondef__enter__(self) ->None:
passdef__exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) ->Literal[False]:
ifisinstance(value, self._exception):
self._counter.inc()
returnFalsedef__call__(self, f: "F") ->"F":
defwrapped(func, *args, **kwargs):
withself:
returnfunc(*args, **kwargs)
returndecorate(f, wrapped)could be (if I understand things correctly):
@contextmanagerdefexception_counter(counter: "Counter", exception: Type[BaseException]) ->None:
try:
yieldexceptexception:
counter.inc()There was a problem hiding this comment.
You can find the history of the vendored in file in the PR that added it, as well as the linked issue: #91.
I think you probably could restructure the various context managers like you suggest now that we do not support older python versions. I believe that before 3.2 just using @contextmanger would not allow you to use it as a decorator as well so the class was nicer.
Signed-off-by: Derek Kulinski <d@kulinski.us>
as of v0.13.0 prometheus/client_python#705 we lock 0.14.0.
This is related to #491, it doesn't resolve it, but it could be a step into that direction.
This theoretically should not break python 2.7