Skip to content

Refactor currency_converter.py #5917

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

Merged
merged 8 commits into from
Jan 28, 2022
Merged

Conversation

MichaelCurrin
Copy link
Contributor

@MichaelCurrin MichaelCurrin commented Jan 11, 2022

Describe your change:

The use of locals in the function is unnecessary. It makes the code harder to follow because you have to check what goes in it, the locals line doesn't save any lines, and the rename of from_ to from has no benefit.

Also the types can be inferred from constants so no need to say 1.0 is a float.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints. See note at the top.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Jan 11, 2022
@ghost ghost added the tests are failing Do not merge until tests pass label Jan 16, 2022
@MichaelCurrin
Copy link
Contributor Author

Tests are failing because of a problem the way the CI is set up. I have the same issue locally on other projects.


On a fresh run, there is no cache.

So when Mypy trieds to install types, it doesn't know what to install for

https://github.com/TheAlgorithms/Python/runs/4831403253?check_suite_focus=true

Run mypy --ignore-missing-imports --install-types --non-interactive .
error: --install-types failed (no mypy cache directory)

A flow what does work but is inconvenient is:

# generate cache but expect failure, because packages are not installed
mypy --install-types --non-interactive .
# run a 2nd time based on cache from above
mypy --ignore-missing-imports --install-types --non-interactive .

What I prefer to is install the types directly in requirements-dev.txt or like this, then run Mypy.

pip install types-requests
mypy --ignore-missing-imports --non-interactive .

This is more manual but less magical (you know exactly what types you install and even the version if you pin it) and lets you run Mypy without the cache or the install flag.

@cclauss
Copy link
Member

cclauss commented Jan 16, 2022

mkdir --parents --verbose .mypy_cache

@MichaelCurrin
Copy link
Contributor Author

Thanks that worked locally.

I added a PR for just that

#5927

@MichaelCurrin
Copy link
Contributor Author

MichaelCurrin commented Jan 17, 2022

I am getting an error locally on the type of params being a dict

when it should be _Params

Screen Shot 2022-01-17 at 12 55 53 pm

But I can't get this to work as my import is not right. Maybe mean to be from request stubs? I haven't gone this deep into types and don't have capacity at the moment to figure it out

from requests.sessions import _Params

params = {
    "from": from_,
    "to": to,
    "amount": amount,
    "api_key": api_key
} # type: _Params

@ghost ghost removed the tests are failing Do not merge until tests pass label Jan 28, 2022
@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Jan 28, 2022
@cclauss cclauss merged commit c15a4d5 into TheAlgorithms:master Jan 28, 2022
@MichaelCurrin MichaelCurrin deleted the patch-1 branch January 31, 2022 10:29
@MichaelCurrin
Copy link
Contributor Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants