Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Missing stub entry for fractions._RATIONAL_FORMAT leads to mypy error #11652

Closed
sr-murthy opened this issue Mar 23, 2024 · 2 comments
Closed

Comments

@sr-murthy
Copy link

sr-murthy commented Mar 23, 2024

The stub file for the fractions standard library is missing an entry for _RATIONAL_FORMAT, which is a compiled regular expression.

I'm using libraries which import _RATIONAL_FORMAT:

...
from fractions import _RATIONAL_FORMAT
...

but running mypy against them leads to this error:

error: Module "fractions" has no attribute "_RATIONAL_FORMAT"  [attr-defined]

Is it not possible to add an entry for _RATIONAL_FORMAT? It is private, but really useful when validating numeric strings.

I saw some relevant discussion on this type of error in the mypy repo, but the solution proposed there does not work for me - it was to rewrite that particular import as an aliased import (using as), and setting the config. option implicit_reexport to true in [tool.mypy] in my project TOML. But that does not work.

My [tool.mypy] section in the project TOML looks like this:

[tool.mypy]
python_version = 3.12
mypy_path = "src"
namespace_packages = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
disallow_untyped_decorators = true
exclude = "version.py"
explicit_package_bases = true
follow_imports = "silent"
ignore_missing_imports = true
implicit_reexport = true

I'm using mypy version 1.9.0 and Python 3.11.2.

@srittau
Copy link
Collaborator

srittau commented Mar 23, 2024

We accept private fields on request. Please just open a PR if you want to add this to the module. Per our policy, I'm going to close this issue in the meantime.

@srittau srittau closed this as completed Mar 23, 2024
@sr-murthy
Copy link
Author

Np, will open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants