Axelrod-Python / Axelrod

A research tool for the Iterated Prisoner's Dilemma
http://axelrod.readthedocs.org/
Other
722 stars 263 forks source link

Type Hints and Annotations #808

Open marcharper opened 7 years ago

marcharper commented 7 years ago

Now that we're Python 3.5+ exclusive, it's time for type hints!

Note to contributors: please run mypy on any newly annotated files. After installing with pip install mypy, please run:

mypy --ignore-missing-imports --follow-imports skip axelrod/<file.py>

for whichever files you annotate. You should receive no errors. We'll get this added to the automated checks soon. Thanks!

Finally, note that we're officially supporting Python 3.5 and 3.6, so please don't use any of the newer typing features in Python 3.6 yet.

souravsingh commented 7 years ago

I am interested in working on the issue.

marcharper commented 7 years ago

@souravsingh Great! It's a huge undertaking so feel free to tackle it in chunks, maybe file by file, and open multiple PRs if you'd like. And don't feel any pressure to do it all.

A few notes:

We're in uncharted territory here so if you are not sure how to annotate something, either leave it alone or open an issue and we'll discuss it.

marcharper commented 7 years ago

@meatballs @drvinceknight Have you seen PEP 526? It's Python 3.6 only and relevant to this issue. Unfortunately Python 3.7 won't be released for 18 months...

drvinceknight commented 7 years ago

Just read it :)

marcharper commented 7 years ago

@drvinceknight we should look into running a type checker (with travis?) once we have a some annotations in.

drvinceknight commented 7 years ago

Yeah: great idea! Do you know of a type checker for Python? A quick google has lead me to give up as the wifi is a bit slow in my hotel right now...

souravsingh commented 7 years ago

@drvinceknight @marcharper We can make use of mypy for type checks. Guido likes the tool himself.

marcharper commented 7 years ago

mypy is probably a good choice, assuming we can make it work with travis -- it's been around for a while (and is the only type checker I've used before).

souravsingh commented 7 years ago

There is pytest plugin for mypy here- https://github.com/dbader/pytest-mypy We can utilise it

marcharper commented 7 years ago

Here's a patch that another project used to incorporate mypy.

souravsingh commented 7 years ago

There is another package for type checking called Traits- https://github.com/enthought/traits

drvinceknight commented 7 years ago

Here's a patch that another project used to incorporate mypy.

Looks simple enough to me.

There is another package for type checking called Traits- https://github.com/enthought/traits

@souravsingh do you think there's anything that Traits adds over mypy?

souravsingh commented 7 years ago

@drvinceknight All I can think of is it supports Type Validation, Notification to other programs if the type of a varibale is changed. I haven't really used traits a lot.

marcharper commented 7 years ago

Thanks @juliahou8 and @souravsingh for getting the ball rolling on this issue!

janga1997 commented 7 years ago

@marcharper I would like to work on this issue. Maybe a stupid question, but do you want to add type hints for the whole project, strategies and tests, etc?

marcharper commented 7 years ago

Whenever possible other than tests IMO.

MariosZoulias commented 7 years ago

Hey.

I have heard that this issue isvery easy to begin with and am really beginner so i would like to start with it. Someone suggested me to take this issue and add type hints on these files : finite_state_machines.py, hmm.py, human.py

I will start from (really) Zero as i dont even know what is PRs and Type Hints , so i hope to have finished all these by Friday ...

So may i take this issue for this files ???

Thank you very much Marios Zoulias

souravsingh commented 7 years ago

@MariosZoulias I would suggest you to work on any one of the file for the PR. For contributing see here- http://axelrod.readthedocs.io/en/latest/tutorials/contributing/strategy/instructions.html For Type hinting, Read this- https://docs.python.org/3/library/typing.html

Let us know if you need any more help.

MariosZoulias commented 7 years ago

Ok then i would like to work on this issue and start with hmm.py I didnt answer fast because i was searching about what is type hinting and more about it... Can you give me some examples of file "before and after" type hinting in order to have a better view??? Thank you Marios Zoulias

janga1997 commented 7 years ago

@MariosZoulias you can check out any of the merged PRs referencing this issue a few comments above above, and click on Files Changed.

MariosZoulias commented 7 years ago

Thank you very much for your fast aswer. So anyway i have the issue about the hmm.py file ??? (am just beginner and i dont really know the procedure) (of course i read the contributing instructions)

janga1997 commented 7 years ago

@MariosZoulias Could we take this up in the gitter room? Also, i didn't quite understand your problem.

MariosZoulias commented 7 years ago

Yes of course am already there ;)

souravsingh commented 7 years ago

Here is the list of files in main module done so far-

drvinceknight commented 7 years ago

That's awesome :+1: @souravsingh

souravsingh commented 7 years ago

Let me know if I have missed something in the main module, I just skimmed through the code.

I will also be making a second list for the type hint progress in strategies module.

janga1997 commented 7 years ago

I would like to take up match.py and match_generator.py, if that's fine.

drvinceknight commented 7 years ago

That's great, thanks @janga1997!

souravsingh commented 7 years ago

For strategies we have this list(Almost everything is done and finished by @janga1997 )-

ghost commented 6 years ago

@souravsingh I'm looking to complete the whole thing. I'm taking up graph.py for now.

souravsingh commented 6 years ago

@eshansingh Awesome. Go for it

pujaniceman commented 6 years ago

are all the files completed here?

drvinceknight commented 6 years ago

They pretty much are, if there's a file that is said to be complete here but it doesn't look like it is let us know :)