question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add typing support

See original GitHub issue

Suggestion: add from __future__ import annotations to all your files (using isort or reorder_python_imports), make sure you are using mypy 0.800, make sure you have your minimum python version for mypy set to 3.7, and then use things like this in your types!

mixed_list: list[str | int] = [1, "hi", 2]

😃

_Originally posted by @henryiii in https://github.com/scikit-hep/pyhf/issues/1272#issuecomment-766285638_

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kratsgcommented, Jul 16, 2021

I’m running this on feat/typing now and will rebase and update that branch.

$ typing_copilot init
typing_copilot v0.6.0

Running mypy once with laxest settings to establish a baseline. Please wait...

Collecting mypy errors from strictest check configuration. Please wait...

Strict run completed and uncovered 1742 mypy errors. Building the strictest mypy config such that all configured mypy checks still pass...

> Mypy was unable to find type hints for some 3rd party modules, configuring mypy to ignore them.
    More info: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
    Affected modules: ['iminuit', 'numpy', 'papermill', 'scipy', 'scrapbook', 'setuptools', 'tensorflow', 'uproot']

> Constructed 116 mypy error suppression rules across 37 modules.

Config generated (232 lines). Verifying the last few mypy settings and validating that the new configuration does not produce mypy errors. Please wait...

Validation complete. Your mypy.ini file has been updated. Happy type-safe coding!
2reactions
matthewfeickertcommented, Jul 16, 2021

At SciPy 2021 @obi1kenobi and @ColCarroll gave a great talk in the maintainers track on typing_copilot. This seems like the way forward for pyhf!

We can incrementally ratchet down the strictness.

For reference, c.f. https://github.com/arviz-devs/arviz/pull/1528

I think though a great endorsement for it is Colin’s comment in the Q&A

I can’t stress enough how little I care about type hinting compared to how much I care about MCMC!

Sounds like me. 😃

cc @alexander-held

Read more comments on GitHub >

github_iconTop Results From Across the Web

typing — Support for type hints — Python 3.11.1 documentation
Source code: Lib/typing.py This module provides runtime support for type hints. The most fundamental support consists of the types Any, Union, Callable, ...
Read more >
Using Typing.com — Support and Knowledge Base
Check out our knowledge base to find answers to all your questions about setting up and using Typing.com. If you still need help,...
Read more >
Python Type Checking (Guide) - Real Python
In this guide, you'll look at Python type checking. Traditionally, types have been handled by the Python interpreter in a flexible but implicit...
Read more >
Python typing module - Use type checkers effectively
Introduced since Python 3.5, Python's typing module attempts to provide a way of hinting types to help static type checkers and linters ...
Read more >
Add support for external annotations in the typing module #600
We propose adding an Annotated type to the typing module to decorate existing types with context-specific metadata. Specifically, a type T ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found