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

Add mypy to typecheck the codebase #1334

Closed
nicarl opened this issue Nov 30, 2020 · 12 comments
Closed

Add mypy to typecheck the codebase #1334

nicarl opened this issue Nov 30, 2020 · 12 comments

Comments

@nicarl
Copy link
Contributor

nicarl commented Nov 30, 2020

  • Faker version: master
  • OS: all

How about adding mypy (http://mypy-lang.org/) to typecheck the codebase?
One could start to add type annotations and once the codebase is covered activate mypy type checking in the CI.

@UrielMaD
Copy link
Contributor

UrielMaD commented Dec 4, 2020

Hello @nicarl, can I help on typechek the codebase?

@nicarl
Copy link
Contributor Author

nicarl commented Dec 4, 2020

Hey that would be great! At the moment I am using the following mypy.ini and mypy 0.790:

[mypy]
python_version = 3.8
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_unreachable = True
allow_redefinition = True
pretty = True
follow_imports=silent 

I think best is to go file by file. The root folder (containing config.py, cli.py ...) is a good place to start I think.

Should we check in the mypy config and already add the dependency?

@UrielMaD
Copy link
Contributor

UrielMaD commented Dec 4, 2020

@nicarl sure! I'm kind of new contributing and I just started to using mypy, I saw that you just merged some files, so, could I start right into the root folder?

@nicarl
Copy link
Contributor Author

nicarl commented Dec 5, 2020

Yes you can start in the root folder. You can just ping me if you get stuck.

@UrielMaD
Copy link
Contributor

UrielMaD commented Dec 8, 2020

@nicarl Hello again Nicarl, I just did a little implementation of type checking in the cli.py file, but I realize that this topic is deeper than I thought, I'm very interested on dive into this and I was wondering that I could need a little guidence on this

@mdantonio
Copy link
Contributor

Hello,
just as information: mypy ignores type hints from packages that do not include a py.typed marker

https://www.python.org/dev/peps/pep-0561/#packaging-type-information

Package maintainers who wish to support type checking of their code MUST add a marker file named py.typed to their package supporting typing.

If some type hints have been added (even if very partial), would be useful to include the py.typed file to the release to let users to start using type hints and encourage contributions

@fcurella
Copy link
Collaborator

Thank you @mdantonio , I've added the py.typed file in 52e5018

@mdantonio
Copy link
Contributor

Great, I will test it as soon as a new version will be released

@MatthijsPiek
Copy link

Now the py.typed file is in there mypy complains about error: Call to untyped function "Faker" in typed context for a simple line like:

fake = Faker()

Adding type annotations to the line doesn't help. Removing the py.typed file manually from the package does fix the issue.

I think py.typed should only be added after more type annotations have been added.

@nicarl
Copy link
Contributor Author

nicarl commented Aug 5, 2021

I started to add type annotations some time ago and still have a branch with more type annotations lying around. I will try to rebase it and contribute what I have at the moment.
Any help with adding type annotations even for small parts of the code is highly appreciated

@nicarl
Copy link
Contributor Author

nicarl commented Aug 5, 2021

My current branch can be found here: https://github.com/nicarl/faker/tree/add_type_annotations_for_providers

@nicarl
Copy link
Contributor Author

nicarl commented Oct 19, 2021

closed by #1536

@nicarl nicarl closed this as completed Oct 19, 2021
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

5 participants