client_python icon indicating copy to clipboard operation
client_python copied to clipboard

[Question] Is "REGISTRY" meant to be a decorator for "Collectors"?

Open migueleliasweb opened this issue 5 years ago • 11 comments

Browsing through the code I've found a function called write_to_textfile in the exposition module. This function signature looks like this:

def write_to_textfile(path, registry):
    """Write metrics to the given path.
    pass

If you read the implementation of the function, turns out the expectation is not really a registry but instead anything that implements (something like an interface) the .collect() method.

Is that by design?

If so, would it be welcomed the addition of type hints throughout the code? I would be happy to add them and create a PR.

migueleliasweb avatar May 19 '20 00:05 migueleliasweb

It takes a registry, as the name clearly indicates.

brian-brazil avatar May 19 '20 08:05 brian-brazil

Thanks @brian-brazil, you couldn't have been more clear. Does that mean adding the type hints is a welcomed addition?

migueleliasweb avatar May 21 '20 02:05 migueleliasweb

What would that involve?

brian-brazil avatar May 21 '20 08:05 brian-brazil

@migueleliasweb that would break compatibility with all python versions < 3.5

beregon87 avatar Jun 04 '20 08:06 beregon87

That's not on the cards then.

brian-brazil avatar Jun 04 '20 09:06 brian-brazil

Hey @brian-brazil , adding the type hints would be just adding the specific type notations to the python files. That's quite handy as it would improve the autocomplete and hints from IDEs.

Some of the examples: https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html

migueleliasweb avatar Jun 09 '20 02:06 migueleliasweb

@beregon87 That might be true. Which versions are you guys supporting atm?

migueleliasweb avatar Jun 09 '20 02:06 migueleliasweb

I'm not a maintainer, but looking at setup.py:

        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.4",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",

beregon87 avatar Jun 09 '20 07:06 beregon87

That still looks to me like it'd break supported versions.

brian-brazil avatar Jun 09 '20 08:06 brian-brazil

See #491 which tracks this issue - so I think this is duplicate. Note that as that task says, one can provide type hints without breaking backwards compatibility, by either using annotations in comments, or preferrably, by using type stubs( .pyi).

paravoid avatar Apr 10 '21 23:04 paravoid

@paravoid I made a small PR illustrating that we can add types without breaking any compatibility. It passes all unit tests and adds enough type information so my code passes with running mypy with --strict.

I hope that could help to allow adding types. Here are some benefits, for people wondering if it is worth it:

  • finds additional bugs that unit tests might not pick up
  • enables autocompletion
  • IDEs can refactor code without introducing bugs (this helps a lot with a large project)
  • allows to compile module by mypyc to get a better performance

takeda avatar Oct 09 '21 07:10 takeda