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 __init__.py files in all the directories #2503

Merged
merged 1 commit into from
Sep 28, 2020

Conversation

dhruvmanila
Copy link
Member

Fixes: #2502

Please check if there's any directory where it's not needed.

Describe your change:

  • Fix a bug or typo in an existing algorithm?

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.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@TravisBuddy
Copy link

Travis tests have failed

Hey @dhruvmanila,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: f7a588e0-017e-11eb-9be6-0d9634a5fbe7

@dhruvmanila
Copy link
Member Author

That was a disaster! Let me see what's going on in there.

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Sep 28, 2020

@cclauss Ok, I found the reason for all the errors.
The errors are happening because of how namespace packages work. As we're adding all the __init__.py files, we're basically creating sub-packages in our parent directory (Python/). What this means is that if we want to use import in a file inside a sub-directory, then we need to import using the dot notation or relative to the parent directory.

For example:
In ciphers/affine_cipher.py, instead of import cryptomath_module as cryptomath we will have to do import ciphers.cryptomath_module as cryptomath

This doesn't seem like a viable solution so I will take a further look into this.

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Sep 28, 2020

I don't think there's any other choice if we're adding the __init__.py files.
It also seems that in some of the files we're using relative imports and in others we're using absolute. It would be better, in the long run, to stick with one. For more information on relative imports: https://docs.python.org/3/reference/import.html#package-relative-imports

If we're importing a module from the current directory we should use either relative or absolute imports and not just import module or from module import function:

  • from parent.module import function
  • from . import module
  • from ..module import function
  • import parent.module

Remember that a module is just another Python file.

@dhruvmanila
Copy link
Member Author

I fixed all the imports on my local copy and it fixes everything up.
Shall I make a PR to fix the imports? @cclauss

@cclauss cclauss merged commit 48357ce into TheAlgorithms:master Sep 28, 2020
@cclauss
Copy link
Member

cclauss commented Sep 28, 2020

Yes. please. Just the changes required to get Travis CI to be ✅ again.

@dhruvmanila dhruvmanila deleted the patch-mypy branch September 28, 2020 17:46
@AayushDadhich
Copy link

Typo

in data structures directory folder is named as trie instead of tree

@cclauss
Copy link
Member

cclauss commented Oct 1, 2020

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
@TheAlgorithms TheAlgorithms deleted a comment from annsleyshakeah66 Sep 7, 2021
@TheAlgorithms TheAlgorithms deleted a comment from kmkurumi Sep 7, 2021
@TheAlgorithms TheAlgorithms locked as resolved and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is this repo using mypy correctly?
4 participants