Skip to content

stubgen reports wrong Python version when used with debug f-string #10905

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

Closed
Peterl777 opened this issue Aug 1, 2021 · 2 comments · Fixed by #10907
Closed

stubgen reports wrong Python version when used with debug f-string #10905

Peterl777 opened this issue Aug 1, 2021 · 2 comments · Fixed by #10907
Labels
bug mypy got something wrong topic-stubgen

Comments

@Peterl777
Copy link

Bug Report

When running stubgen on a module that contains a debug f-string, stubgen reports a "Critical error" and reports the wrong python version.

To Reproduce

# mod.py
def fn() -> int:
    i = 5
    print(f'{i=}')
    return 0

C:\> stubgen mod.py
Critical error during semantic analysis: mod.py:3: error: f-string: self documenting expressions are only supported in Python 3.8 and greater

Expected Behavior

C:\> stubgen mod.py
Processed 1 modules
Generated out\mod.pyi

Actual Behavior

C:\> stubgen mod.py
Critical error during semantic analysis: mod.py:3: error: f-string: self documenting expressions are only supported in Python 3.8 and greater

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.9.6 (no other Pythons installed)
  • Operating system and version: Win 10.0.19043
@Peterl777 Peterl777 added the bug mypy got something wrong label Aug 1, 2021
@hauntsaninja
Copy link
Collaborator

Looks like stubgen effectively hardcodes 3.6. Easy enough to fix...

hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Aug 1, 2021
Not too familiar with stubgen, so maybe there's a good reason for
hardcoding, e.g. to ensure stubs capture sys.version checks in the
source? Most stubs in typeshed use sys.version checks for a) checking
Python 2, b) if they're stdlib backports. So hopefully this is still
reasonable.

Fixes python#10905
hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Aug 1, 2021
Not too familiar with stubgen, so maybe there's a good reason for
hardcoding, e.g. to ensure stubs capture sys.version checks in the
source? Most stubs in typeshed use sys.version checks for a) checking
Python 2, b) if they're stdlib backports. So hopefully this is a
reasonable change.

Fixes python#10905
@braindevices
Copy link

I also see this error

JelleZijlstra pushed a commit that referenced this issue Nov 21, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Not too familiar with stubgen, so maybe there's a good reason for
hardcoding, e.g. to ensure stubs capture sys.version checks in the
source? Most stubs in typeshed use sys.version checks for a) checking
Python 2, b) if they're stdlib backports. So hopefully this is a
reasonable change.

Fixes #10905
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
Not too familiar with stubgen, so maybe there's a good reason for
hardcoding, e.g. to ensure stubs capture sys.version checks in the
source? Most stubs in typeshed use sys.version checks for a) checking
Python 2, b) if they're stdlib backports. So hopefully this is a
reasonable change.

Fixes python#10905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubgen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants