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

Refactored complex methods #263

Merged
merged 1 commit into from
Nov 16, 2016
Merged

Conversation

vladimirnani
Copy link
Contributor

@vladimirnani vladimirnani commented Nov 11, 2016

Specified complexity level for prospector.

Refactored methods that raised complexity exceptions. (max-complexity 9)

Fixes #261

@benkonrath
Copy link
Member

Thanks! I should have time to review this tomorrow.

Copy link
Member

@benkonrath benkonrath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work here, thanks! Just those small changes and it's good to be merged.


mccabe:
options:
max-complexity: 9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a new line here.

if len(eik) == 13 and not check_eik_extra(eik):
raise ValidationError(error_message)
eik_validator = EIKValidator()
egn_validator = EGNValidator()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about deprecating the *_validator versions? I suppose there's no real harm in keeping them around but it would be nice to provide just the class version. Users can always make their own version of the callable if they want to use it that way. Consider this optional and only do it if you agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I was thinking to deprecate them. There is no point in callable, because usually logic is complex so you have to split into several methods. And even for simple cases think is better to stick to class validators conventionally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with merging this before these are depreciated because the deprecation work in #262 hasn't been merged yet. Just file a new issue so we don't forget to do the deprecation once #262 has been merged.

"""
Check Bulgarian unique citizenship number (EGN) for validity.

More details https://en.wikipedia.org/wiki/Unique_citizenship_number
Full information in Bulgarian about algorithm is available here
http://www.grao.bg/esgraon.html#section2
"""
def check_checksum(egn):

def check_checksum(self, egn):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mark new methods as private (prefixed with _)? This applies to all of the methods that you've created on the forms. I want to be clear that these are internal and not public. Please to this for data fields on the form as well.

@benkonrath benkonrath changed the title Refactored complex methods #261 Refactored complex methods Nov 12, 2016
@vladimirnani
Copy link
Contributor Author

Thanks for review, have created 265.

- Complexity 9
- Moved function validators to Validator classes
- Changed Indonesian Numbers
@benkonrath benkonrath merged commit c07e5a4 into django:master Nov 16, 2016
@benkonrath
Copy link
Member

Thanks @vladimirnani!

Copy link

@Ershilka Ershilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

777

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

Successfully merging this pull request may close these issues.

3 participants