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

stubgen does not seem to retain member variable type hint #5616

Closed
alexyiu875 opened this issue Sep 13, 2018 · 2 comments
Closed

stubgen does not seem to retain member variable type hint #5616

alexyiu875 opened this issue Sep 13, 2018 · 2 comments

Comments

@alexyiu875
Copy link

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?
    A bug (potentially) in Stubgen

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
    I am using stubgen to generate ".pyi" file.
    Original Python Source Code for this "Car" class is:

class Car:
    def __init__(self, manufacturer: str, make: str, mpg: float) -> None:
        self.manufacturer: str = manufacturer
        self.make: str = make
        self.mpg: float = mpg
  • What is the actual behavior/output?
class Car:
    manufacturer: Any = ...
    make: Any = ...
    mpg: Any = ...
    def __init__(self, manufacturer: str, make: str, mpg: float) -> None: ...
  • What is the behavior/output you expect?
    I expect the type hint of those member variables would be retained instead of using "Any".
    e.g.
class Car:
    manufacturer: str = ...
    make: str = ...
    mpg: float = ...
    def __init__(self, manufacturer: str, make: str, mpg: float) -> None: ...
  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
    mypy 0.620
    python 3.7.0
    (I have not tried out mypy from Git master)

  • What are the mypy flags you are using? (For example --strict-optional)
    N/A

  • If mypy crashed with a traceback, please paste
    the full traceback below.
    N/A

If there is a workaround to code this "Car" class in a different variant, which retains TypeHint during Stubgen, please let me know also.

Thanks.

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 17, 2018

This has not been implemented -- stubgen is currently only useful for unannotated modules, unfortunately. Closing as duplicate of #3475.

@JukkaL JukkaL closed this as completed Sep 17, 2018
@ilevkivskyi
Copy link
Member

@JukkaL
Actually this (preserving explicit annotations) was implemented in #3169, but it looks like the implementation has an inconsistency (bug?): it works correctly when an attribute is declared in the class body, but doesn't work if it was declared in __init__.

Should we reopen this for tracking preserving explicit annotations, and keep #3475 for inferred, or you want to have the latter for both?

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

3 participants