Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Implemented sum() builtin functionality for other types. #749

Merged
merged 4 commits into from
May 17, 2018

Conversation

nicklambourne
Copy link
Contributor

@nicklambourne nicklambourne commented May 16, 2018

Changes

Implemented python sum() builtin functionality for other datatypes including Strings, Sets, FrozenSets, Dict, Range, Bytes and Bytearrays. Calling sum on these datatypes generally returns something type-specific (e.g. bytes returns the sum of each byte's ASCII value) .

N.B. The tests for Set and FrozenSet occasionally fail nondeterministically (though only when provided invalid input - specifically a mix of ints, floats and strings) due to fact that their values are are stored in Python dicts and dicts don't (yet) maintain order. If anyone can see a way around this, I'd love to know. In the interim I've disabled the tests for Set and FrozenSet, but kept the functionality (which works, it may just return a different TypeError message).

Problem

The unique sum() functionality across the less commonly used data types had not been implemented.

Fixes

Contributes to fixing #47

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

👍

We have a couple of mechanisms for dealing with non-deterministic key-ordering, based on output substitution; if you search for substitutions in the test directory, you should be able to find some examples for working around the problem.

@freakboy3742 freakboy3742 merged commit d40c47b into beeware:master May 17, 2018
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.

2 participants